12 comments

[ 2.9 ms ] story [ 53.8 ms ] thread
I don't know if this is only true of JavaScript, but its parser at least accepts all months as having 31 days and then normalises them to the following month, on overflow:

    > new Date('2015-02-31')
    Mon Mar 02 2015 00:00:00 GMT+0000 (GMT)
    > new Date('2015-02-32')
    Invalid Date
I'm not sure if I entirely approve of this behaviour...
The by-integers constructor accepts overflow on any of the input values and adjusts accordingly:

    > new Date(2015,10,30)
      Mon Nov 30 2015 00:00:00 GMT+0000 (GMT Standard Time)
    > new Date(2015,10,31)
      Tue Dec 01 2015 00:00:00 GMT+0000 (GMT Standard Time)
    > new Date(2015,10,32)
      Wed Dec 02 2015 00:00:00 GMT+0000 (GMT Standard Time)
    > new Date(2015,10,320)
      Thu Sep 15 2016 00:00:00 GMT+0100 (GMT Daylight Time)
    > new Date(2015,10,01,23,59)
      Sun Nov 01 2015 23:59:00 GMT+0000 (GMT Standard Time)
    > new Date(2015,10,01,23,590)
      Mon Nov 02 2015 08:50:00 GMT+0000 (GMT Standard Time)
I can kind of justify that, insofar as it's unlikely that any input would be entered directly like that and it has the quite nice property of allowing date arithmetic on an arbitrary unit (e.g., "+ 1 calendar month, 4 hours and 25 milliseconds", etc.)
Yes, I've deliberately used it that way in the past:

    newDate = new Date(refDate.getFullYear(), refDate.getMonth(), refDate.getDate(), refDate.getHours()+1000, refDate.getMinutes())
letting it deal with the wrapping of larger date/time parts as needed.
Actually, the JS specification doesn't constrain the date parser except to require that ISO 8601 dates must be accepted, so it differs from JS engine to JS engine. I'm guessing you're testing in V8, since my SpiderMonkey test right now gave Invalid Date for both of those.

It got really annoying for me because the ISO 8601 portion of the parser refused to accept leap seconds but non-ISO-8601 forms (such as RFC 5322) did.

The IANA timezone database[0] contains some real gems in the comments. A lot of research has gone into making it as accurate as possible.

For instance, at the top of the UK entries in the "europe" file, you get this:

    # From Peter Ilieve (1994-07-06):
    #
    # On 17 Jan 1994 the Independent, a UK quality newspaper, had a piece about
    # historical vistas along the Thames in west London. There was a photo
    # and a sketch map showing some of the sightlines involved. One paragraph
    # of the text said:
    #
    # 'An old stone obelisk marking a forgotten terrestrial meridian stands
    # beside the river at Kew. In the 18th century, before time and longitude
    # was standardised by the Royal Observatory in Greenwich, scholars observed
    # this stone and the movement of stars from Kew Observatory nearby. They
    # made their calculations and set the time for the Horse Guards and Parliament,
    # but now the stone is obscured by scrubwood and can only be seen by walking
    # along the towpath within a few yards of it.'
    #
    # I have a one inch to one mile map of London and my estimate of the stone's
    # position is 51 degrees 28' 30" N, 0 degrees 18' 45" W. The longitude should
    # be within about +-2". The Ordnance Survey grid reference is TQ172761.
    #
    # [This yields GMTOFF = -0:01:15 for London LMT in the 18th century.]
Or in the "northamerica" file:

    # From Arthur David Olson (2011-02-09):
    # I just spoke by phone with a staff member at the Metlakatla Indian
    # Community office (using contact information available at
    # http://www.commerce.state.ak.us/dca/commdb/CIS.cfm?Comm_Boro_name=Metlakatla
    # It's shortly after 1:00 here on the east coast of the United States;
    # the staffer said it was shortly after 10:00 there. When I asked whether
    # that meant they were on Pacific time, they said no - they were on their
    # own time. I asked about daylight saving; they said it wasn't used. I
    # did not inquire about practices in the past.
And for furthere errata, I will mention the artist William Kentridge, whose video installation "The Refusal of Time"[1] was one of the cooler pieces I've seen in the last few years.

[0]: http://www.iana.org/time-zones

[1]: https://www.youtube.com/watch?v=uaPnBorIMmc (YouTube doesn't really do it justice, but if you like art and you ever get the chance to see it, I highly recommend taking the time)

  Over Quota

  This application is temporarily over its serving quota.
  Please try again later.
It wasn't prepared for HackerNews visiblity :P