Community server profile date format selection.







  • @morbiuswilters said:

    @Ben L. said:
    Three hours apart is a strange definition of "the same time"...

    What.

    In the.

    Fuck.

    Hahaha Go is the gift that keeps on giving! I think Go was secretly invented by Alex to guarantee this site would never run out of material.



  • @MiffTheFox said:

    Ok, this one is my fault. I swear last time I was working with DateTime.ParseExact it ignored any time zone specifiers (so that parsing 7:25:00 PM PDT 5/20/2013 on a computer in EST would result in 7:25:00 PM EST 5/20/2013 which is not the same time.). Still you have to go through the complicated part of cutting the timestamp apart and putting it back together if it's in a format that DateTime.ParseExact doesn't like, like PDT or -0700, so I stay by what I say about how working with time zones in .NET is difficult.

    string time = "5/20/2013 7:25:00 PM EST";
    string format = "M/dd/yyyy h🇲🇲ss tt K";
    DateTime t1 = DateTime.ParseExact(time.Replace("EST", "-0400"), format, CultureInfo.InvariantCulture);
    Console.WriteLine(t1.ToLongTimeString() + " on " + t1.ToLongDateString());
    
    DateTime uTime = t1.ToUniversalTime();
    Console.WriteLine(uTime.ToLongTimeString() + " on " + uTime.ToLongDateString());
    
    DateTime pTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(uTime, "Pacific Standard Time");
    Console.WriteLine(pTime.ToLongTimeString() + " on " + pTime.ToLongDateString());
                
    //Output:
    //7:25:00 PM on Monday, May 20, 2013
    //11:25:00 PM on Monday, May 20, 2013
    //4:25:00 PM on Monday, May 20, 2013

    What do you find difficult about the above?



  • @lettucemode said:

    What do you find difficult about the above?

    Because it also has to handle if the timezone has a : in it, it has to handle if there is not timezone, it has to handle if the timezone is a Z with no space, it has to handle 24-hour time, etc.

    Later I'll write a small program that pulls every single different timestamp format from my RSS list just to demonstrate how difficult handling all of them. Apparently some big RSS reader (Google Reader?) wasn't too picky about timestamps and now we're stuck with a million minor variations.

    Also EST is UTC-5, not UTC-4.



  • Look, Miff, it's easy: the standard time formats that .net accepts are STANDARD TIME FORMATS. ISO standards.

    If your time format is not one of those, you have to give it a custom format string.

    They didn't implement the system to do guess-and-check Excel-style. They implemented it to create good, solid, bug-free software. If you want it to just accept any old bullshit, go code in PHP.



  • @MiffTheFox said:

    Also EST is UTC-5, not UTC-4.

    Blarg. Just change that S to a D and we'll call it good.

    And I'm interested in seeing that list!



  • @blakeyrat said:

    Look, Miff, it's easy: the standard time formats that .net accepts are STANDARD TIME FORMATS. ISO standards.

    If your time format is not one of those, you have to give it a custom format string.

    They didn't implement the system to do guess-and-check Excel-style. They implemented it to create good, solid, bug-free software. If you want it to just accept any old bullshit, go code in PHP.

    Unless of course there is no custom format string, like for example in the ISO 8601 standard date of 2013-W20-5, which I'm glad has never been in the wild, but .NET won't accept that no matter what you do because there's no format string for "week of the year".



  • Various formats from RSS feeds. Pretty normal, but you have to strip out the day of week and change the named time zones to numeric ones:

    12 May 2013 01:00:00 EST
    Fri, 15 Apr 2011 14:45:58 GMT
    Fri, 19 Apr 2013 22:56:12 +0000
    Mon, 20 May 2013 04:00:00 -0000
    Mon, 11 Feb 2013 21:30:27 -0600
    Tue, 21 May 2013 11:04:00 PDT

    Various formats from Atom feeds, in the "standard" ISO 8601 format:

    2013-05-21T11:57:02-08:00
    2013-05-21T12:31:11.483-04:00
    2013-05-21T18:57:00Z

    I have to completely take apart the string here to take out fractional seconds (since AFICT there's no way to tell .NET "ignore this part if it's there"), as well as change Z to a numeric offset; oh yeah, and strip the : from the time zone. And god forbid that something ever invoke one of the more obscure ISO 8601 formats, even if it's just something like basic format.



  • @MiffTheFox said:

    12 May 2013 01:00:00 EST
    Fri, 15 Apr 2011 14:45:58 GMT
    Fri, 19 Apr 2013 22:56:12 +0000
    Mon, 20 May 2013 04:00:00 -0000
    Mon, 11 Feb 2013 21:30:27 -0600
    Tue, 21 May 2013 11:04:00 PDT

    Various formats from Atom feeds, in the "standard" ISO 8601 format:

    2013-05-21T11:57:02-08:00
    2013-05-21T12:31:11.483-04:00
    2013-05-21T18:57:00Z

    I just ran each of those through the following code sample:

    string time = "date string goes here";
    DateTime t = DateTime.Parse(time2);
    Console.WriteLine(t.ToLongTimeString() + " on " + t.ToLongDateString());

    1st and 6th strings (EST and PDT) threw errors, the rest converted correctly. I didn't modify any of them. The ISO Week Date example you gave earlier didn't work.


  • Considered Harmful

    @MiffTheFox said:

    Various formats from RSS feeds. Pretty normal, but you have to strip out the day of week and change the named time zones to numeric ones:

    12 May 2013 01:00:00 EST
    Fri, 15 Apr 2011 14:45:58 GMT
    Fri, 19 Apr 2013 22:56:12 +0000
    Mon, 20 May 2013 04:00:00 -0000
    Mon, 11 Feb 2013 21:30:27 -0600
    Tue, 21 May 2013 11:04:00 PDT

    Various formats from Atom feeds, in the "standard" ISO 8601 format:

    2013-05-21T11:57:02-08:00
    2013-05-21T12:31:11.483-04:00
    2013-05-21T18:57:00Z

    I have to completely take apart the string here to take out fractional seconds (since AFICT there's no way to tell .NET "ignore this part if it's there"), as well as change Z to a numeric offset; oh yeah, and strip the : from the time zone. And god forbid that something ever invoke one of the more obscure ISO 8601 formats, even if it's just something like basic format.

    <html><body style='color:#000000; background:#ffffff; '>
    private readonly string[] _dates =
    	new[] {
    		"12 May 2013 01:00:00 EST",
    		"Fri, 15 Apr 2011 14:45:58 GMT",
    		"Fri, 19 Apr 2013 22:56:12 +0000",
    		"Mon, 20 May 2013 04:00:00 -0000",
    		"Mon, 11 Feb 2013 21:30:27 -0600",
    		"Tue, 21 May 2013 11:04:00 PDT",
    		"2013-05-21T11:57:02-08:00",
    		"2013-05-21T12:31:11.483-04:00",
    		"2013-05-21T18:57:00Z"
    	};
    

    void Main() {
    foreach( var date in _dates ) {
    DateTimeOffset d;
    if( DateTimeOffset.TryParse( date, out d ) ) Console.WriteLine( "{0:u}", d );
    else Console.WriteLine( "Unable to parse {0}", date );
    }
    }

    /* Output:
    Unable to parse 12 May 2013 01:00:00 EST
    2011-04-15 14:45:58Z
    2013-04-19 22:56:12Z
    2013-05-20 04:00:00Z
    2013-02-12 03:30:27Z
    Unable to parse Tue, 21 May 2013 11:04:00 PDT
    2013-05-21 19:57:02Z
    2013-05-21 16:31:11Z
    2013-05-21 18:57:00Z
    */



  • @lettucemode said:

    1st and 6th strings (EST and PDT) threw errors, the rest converted correctly. I didn't modify any of them. The ISO Week Date example you gave earlier didn't work.

    @joe.edwards said:


    /* Output:
    Unable to parse 12 May 2013 01:00:00 EST
    2011-04-15 14:45:58Z
    2013-04-19 22:56:12Z
    2013-05-20 04:00:00Z
    2013-02-12 03:30:27Z
    Unable to parse Tue, 21 May 2013 11:04:00 PDT
    2013-05-21 19:57:02Z
    2013-05-21 16:31:11Z
    2013-05-21 18:57:00Z
    */

    Go Team Venture!



  • @morbiuswilters said:

    Go Team Venture!

    "I don't know, they just do that."



  • @lettucemode said:

    @MiffTheFox said:

    Also EST is UTC-5, not UTC-4.

    Blarg. Just change that S to a D and we'll call it good.

    And I'm interested in seeing that list!

    EST is UTC+10. Next question?



  • @Ben L. said:

    EST is UTC+10. Next question?

    That would be AEST



  • @Quinnum said:

    AEST

    Sounds like a mid-90s show from Sci-Fi Channel.

    AEST: Star Samurai Pilots 2731


Log in to reply