ISO/JSON date format timezone questions

Lars T Hansen lth at acm.org
Thu Jul 19 21:47:26 PDT 2007


On 7/16/07, Lars T Hansen <lth at acm.org> wrote:
> On 7/16/07, Lars T Hansen <lth at acm.org> wrote:
> > On 7/13/07, doekman at gmail.com <doekman at gmail.com> wrote:
> > > Hi,
> > > I was wondering about two things involving timezones.
> > >
> > > The proposal "Date and time improvements" is defining the
> > > Date.toISO():String method.
> > >
> > > It's unclear to me in what timezone the date should
> > > be serialized in: local timezone or UTC. Although it's semantically
> > > correct to allow both and let the implementors decide, but I think
> > > that would be "not a good thing".
> > >
> > > I prefer is to be serialized in UTC (with the Z suffix).
> >
> > I agree.  I'll update the proposal.
>
> Actually the proposal states (last sentence on the page) that the
> timezone field is always present and never Z.  It's possible that is
> an external requirement; I'll have to look into it further.

Resolved: toISOString() always produces a UTC timestamp with the "Z"
suffix.  Eventually JSON users should be able to count on this.

ISO timestamps can be recognized and picked apart by a simple ES4
regular expression, reproduced here for your collective amusement:

        static const isoTimestamp : RegExp! =
            /^
            # Date, optional
            (?: (?P<year> - [0-9]+ | [0-9]{4} [0-9]* )
             (?: - (?P<month> [0-9]{2} )
              (?: - (?P<day> [0-9]{2} ) )? )? )?
            T
            # Time, optional
            (?: (?P<hour> [0-9]{2} )
             (?: : (?P<minutes> [0-9]{2} )
              (?: : (?P<seconds> [0-9]{2} )
               (?: \. (?P<fraction> [0-9]+ ) )? )? )? )?
            # Timezone, optional
            (?: (?P<zulu> Z )
             | (?P<offs>
                (?P<tzdir> \+ | - )
                (?P<tzhr> [0-9]{2} )
                (?: : (?P<tzmin> [0-9]{2} ) )? ) )?
            $/x;

--lars

>
> --lars
>
> > > The
> > > downside of this is, all json users will have to support time-zones.
> >
> > As opposed to the current situation, when they have no idea what the
> > time stamp means? ;-)
> >
> > > The advantage is, you can truncate two arbitrary json-date strings,
> > > and compare them, even if the dates are serialized in different
> > > timezones.
> > >
> > > The other question is concerning the "JSON encoding and decoding"
> > > proposal. Is the Date serialization using the (fixed) formatting
> > > of www.json.org/json.js, or is it using the toISO method,
> > > mentioned above?
> >
> > JSON has no syntax for time or date data, according to the grammar on
> > json.org.  The code you reference does format dates as strings,
> > however, and it contains a comment which states that eventually dates
> > will be formatted according to Date.prototype.toISOString().  This
> > seems natural to me, as the ISO date format is unambiguous and
> > compact.
> >
> > So far the committee has been happy not to write any code for
> > toJSONString, instead (informally) incorporating the code on json.org
> > by reference.  That may or may not change in the future.
> >
> > --lars
> >
>



More information about the Es4-discuss mailing list