• OpiF (unregistered)

    Jesus...

  • Sywor (unregistered)

    "// TODO: fix this before january 19th, 2038 at 03:14:08 UTC"

    Thinking ahead!

  • Foo AKA Fooo (unregistered) in reply to Sywor

    Why, actually? AFAIK, parseInt is not limited to signed 32 bits, and 10 decimal digits will not overrun for many more years.

    Also, what kind of name is PastorGL? Isn't that the Christian version of OpenGL?

  • (nodebb)

    /\s*(mon(day)?|tue(s?day)?|wed(nesday)?|thu((rs)?day)?|fri(day)?|sat(urday)?|sun(day)?)\s*/gi

    Obviously matching the abbreviations as well as the full days, but I'm bothered by Tuesday and Thursday. I'm thinking the intention is to match Tue, Tues, or Tuesday, likewise to include Thurs. Reasonable. But unless I'm somewhat confused, it looks like it's actually matching Tueday and Thuday.

  • T.T.O. (unregistered)
    (mon(day)?|tue(s?day)?|wed(nesday)?|thu((rs)?day)?|fri(day)?|sat(urday)?|sun(day)?)

    Tueday? Thuday?

  • Alex (unregistered)

    Does pastorGL really really like The OpenGL Superbible?

  • MaxArt (unregistered)

    I wouldn't desecrate so much that code. Smells like some poor bastard FE developer that had to deal with BE developers that couldn't care to agree to stick with a specific format.

  • Jere (unregistered)

    Funny. The regex that removes "at" and "on" from the date string has no word boundaries (\b). The preceding \s* does not help since it will effectively match empty strings. The regex would end up chopping out "at" and "on" from the middle of words.

    Then the weekday elimination regex would fail to get rid Mday and Surday =)

  • gnasher729 (unregistered)

    I thought the rule was: When you can't parse JSON, tell the server guys to bloody fix it.

  • Hrmmmm (unregistered)

    Whenever I find code that redefines a variable and uses two different coding styles for the two definitions, I immediately flag it as needing rewrite.

    var ts = Date.parse(str);
    .
    .
    .
    var ts;
    ts = Date.parse(str);
    
  • Pedant (unregistered)

    It doesn't even handle the obvious json.dumps(time.gmtime())

    Which gives you the perfectly reasonable [2017, 2, 20, 19, 26, 47, 0, 51, 0] encoding of struct_time.

  • Chris (unregistered) in reply to Foo AKA Fooo

    PastorGL is much more forgiving of bad coding than regular OpenGL.

  • Simon (unregistered)

    JSON, of course, doesn’t have a concept of date datatypes, which leaves the web-service developer needing to make a choice about how to pass the date back. As a Unix timestamp? As a string? What kind of string?

    As an ISO-8601 formatted string, of course. Because in a text-based data interchange format, doing anything other than following the standard is a clear sign that you're an incompetent fuckwit who shouldn't be allowed near a keyboard.

    Sadly, there are plenty of those around. :(

  • löchlein deluxe (unregistered)

    My old multilingual wristwatch would tell me "DIE" every Tuesday, but for the more agressive Frenchpeople, it could be switched to say "TUE" (which, if memory serves, is the imperative of "tuer", to kill).

    Fun fact: the standard unix at daemon can take many date specs on the command line, including oddities like "teatime" and "midnight". It can also tell what it parsed the date as and will tell you "Tue Feb 21 23:00:00 2017" or whatever. Guess which format it will actually not take on the command line.

  • Gerrie (unregistered)

    Nice use of a meme at the end

  • niemand (unregistered) in reply to löchlein deluxe

    DIE, as in DIENSTAG? what would french be?

  • Damon (unregistered)

    This code must die. A slow, painful death.

  • (nodebb) in reply to niemand

    "DIE, as in DIENSTAG? what would french be?"

    "Mardi", but of course "Tue" comes from English.

  • Quite (unregistered) in reply to Steve_The_Cynic

    Not quite as brutal as "die", but then "mar" is redundant as the code is badly marred as it is.

  • Harald (unregistered)

    Code sob.

  • Ulysses (unregistered)

    Jason doesn't appreciate your insulting choice of date format. [Restore] [Restart] [Quit]

  • Ray (unregistered)

    It's moments like these I like to use MomentJS, let them do all the heavy lifting for me :)

  • löchlein deluxe (unregistered) in reply to Quite

    Nice one! And so the cycle completes, it's the ciiiiiiiiircle of strii-hi-hi-hife.

  • Hannes (unregistered) in reply to löchlein deluxe

    Nonono, this is german and means "The Bart, the".

  • guest (unregistered)

    TRWTF is why not just pass a date format mask along with the date string? Its all in-house code, no?

Leave a comment on “A Date With a Parser”

Log In or post as a guest

Replying to comment #:

« Return to Article