x First time here? Check out the FAQ

Come work for Umbraco - The Umbraco HQ are hiring Project managers, .NET developers and DevOps people!

  • Avatar3938posts8575karma
    CoreadminMVP

    Wrong twitter time

    Jeroen Breuer started this topic October 21, 2010 @ 12:13, Go directly to the topic solution

    Hello,

    This topic isn't really Umbraco related, but I'm using the Twitter for Umbraco package (which is great!) and the time from all tweets is wrong. It's 2 hours behind. The created_at date says 09:00, but it was created on 11:00. Is it because of a different time zone?

    Also is there an easy way to show "3 hours ago" as the time instead of the create date?

    Jeroen


  • Warren Buckley posted this reply October 21, 2010 @ 04:03

    Hi Jeroen,
    I would check the XML feed directly from twitter to see what times is being returned.
    Unfortunately my package cant do anything to help with that.

    I am not sure if there is a timezone setting in your twitter account on twitter.com this could affect these time/date values if not then you will need to add some logic into your XSLT to either add or substract from the XML date/time to suit your needs.

    Thanks,
    Warren :)


  • Jeroen Breuer posted this reply October 21, 2010 @ 04:08

    Hi Warren,

    I've check the XML feed directly from twitter and there the time is also wrong. For now I just add 2 hours to the time and everything is fine, but that's not the best solution off course.

    Jeroen


  • Warren Buckley posted this reply October 21, 2010 @ 04:31

    Jeroen,
    I know its not the best solution. However I have no control over the XML feed ;)

    Warren


  • Morten Bock posted this reply October 21, 2010 @ 05:02

    As far as I can tell, the date in the feed looks like this:

    "Wed Aug 25 19:40:45 +0000 2010"

    Is that correct? If so, then the "+0000" indicates that the time is in UTC, meaning that it has a 0 offset. So it makes perfect sense, that the date might be a couple of hours off the time you expect because of timezones/daylight savings.

    A solution could be that the CWS.Twitter:FormatTwitterDate(created_at) method parses the date as being UTC, and the converts it into local time (meaning the servers time setting). That would work for 90% of people. Alternatively, supply an overload allowing to pass in a timezone that the time should be converted to.

    Hope that makes sense :-)

     


  • Warren Buckley posted this reply October 21, 2010 @ 05:25

    Morten & Jeroen,
    The package is open source and is open to contributors if you want to help fix or improve twitter for umbraco.

    I just sturggle to find time to keep up to date with all my packages.
    Warren :)


  • Avatar1767posts1773karma
    adminComment with ID: 50890
    Morten Bock posted this reply October 21, 2010 @ 06:15

    I can fix the date method if you want? Just need codeplex access :)


  • Avatar1767posts1773karma
    adminComment with ID: 50901
    Morten Bock posted this reply October 21, 2010 @ 07:40

    Just changed the method a bit to convert to local time. Was looking at making an overload for changing timezones, but that got pretty messy very quick, when starting to think about daylight savings and all... So for now:

    public static string FormatTwitterDate(string twitterDate)
    {
        DateTime parsedDate;
        if (DateTime.TryParseExact(twitterDate, "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out parsedDate))
        {
            return parsedDate.ToLocalTime().ToString("s");
        }
        return "1900-01-01T00:00:00";
    }

    Should fit most needs.

    As an instant fix, you can just add this method as inline C# in the xslt until there is an updated package...


  • Warren Buckley posted this reply October 21, 2010 @ 08:34

    Hi Morten do you want to become a contributor and work on obviously adding this and maybe any other ideas or improvements you may have?

    Cheers,
    Warren :)


  • Avatar1767posts1773karma
    adminComment with ID: 50948
    Morten Bock posted this reply October 21, 2010 @ 10:51

    Sure thing. You can add me on codeplex: "mortenbock".

    Will check in the changes, and then we can coordinate how the packaging works :)


  • Warren Buckley posted this reply October 22, 2010 @ 10:04

    Added you on Codeplex, if you add yourself or send request to be a contributor on our.umbraco.org project page then I can add you there as well.

    Cheers,
    Warren :)


Pages:

Please login or Sign up To post replies