[squeak-dev] A UTC based implementation of DateAndTime

David T. Lewis lewis at mail.msen.com
Mon May 26 15:16:05 UTC 2014


On Mon, May 26, 2014 at 10:48:16AM -0400, Louis LaBrunda wrote:
> 
> On Sun, 25 May 2014 13:48:44 -0400, "David T. Lewis" <lewis at mail.msen.com>
> wrote:
> 
> >I have been working on a variation of class DateAndTime that replaces its
> >instance variables (seconds offset jdn nanos) with two instance variables,
> >utcMicroseconds to represent microseconds elapsed since the Posix epoch, and
> >localOffsetSeconds to represent the local time zone offset. When instantiating
> >the time now, A single call primitiveUtcWithOffset is used to obtain these
> >two values atomically as reported by the underlying platform.
> >
> >There are several advantages to this representation of DateAndTime, the most
> >important of which is that its magnitude is unambiguous regardless of daylight
> >savings transitions in local time zones.
> >
> Hi Dave,
> 
> May I respectfully ask why localOffsetSeconds (to represent the local time
> zone offset) is needed?  It seems to me a UTC time is enough.  Is there
> really a need for the timezone offset the instance was created in?  Does
> every DateAndTime instance need to carry this offset around with it?  I
> would think the offset is only needed if one wants to display a date/time
> as a local value and then one could get the local offset from the VM or a
> program setting the user had previously supplied regardless of where the
> computer was setup to run.  I guess there might be some historic interest
> as to the timezone an instances (or many instances) was created in but one
> could just keep that as a separate value.

Hi Lou,

Good question. In fact, one of the reasons I like the UTC implementation is
that it helps clarify the two main responsibilities of DateAndTime. One is
to represent time as a magnitude (for duration calculation, etc). The other
is to display time in the frame of reference of a local time zone. It is not
at all clear to me that those two responsibilies belong in the same class.

Dave



More information about the Squeak-dev mailing list