Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
UTCDateAndTime
Last updated at 1:08 am UTC on 16 September 2019
UTCDateAndTime is a UTC based implementation of class DateAndTime with one instance variable representing the magnitude of the point in time, and another representing local time zone offset.

Contributed by Dave Lewis. License is MIT.

UTCDateAndTime is maintained at http://www.squeaksource.com/UTCDateAndTime. Please refer to that repository for loading UTCDateAndTime.

As of January 2019 this project has been merged in Squeak trunk and is now included in package Chronology-Core.


Traditional implementation

The traditional implementation of the date and time class called DateAndTime uses instance variables
and calculates its magnitude based on those variables in conjunction with the local TimeZone.

New implementation

UTCDateAndTime replaces this with an implementation using instance variables
This represents time magnitude as elapsed microseconds since the Posix epoch,
with localOffsetSeconds representing local offset from UTC.

The magnitude is used for comparison and duration calculations, and the local offset is used for displaying this magnitude in the context of a local time zone.

The implementation ignores leap seconds, which are adjustments made to maintain earth rotational clock time in synchronization with elapsed seconds.

 DateAndTime class>>now 

will use #primitiveUtcWithOffset to obtain current time in UTC microseconds with current local offset in seconds. The primitive provides an atomic query for UTC time and local offset as measured by the OS platform.

If primitiveUtcWithOffset is not available, the traditional implementation is used, which relies on a primitive for microseconds in the local time zone and derives UTC based on the TimeZone setting.

These changes are not easily reversed. When initially loading from SS3, the first four MCZ files must be loaded individually and in sequence. During the loading process, instances of DateAndTime in the image must be converted to new formats. Currently this is a one way process, so save your image prior to loading UTCDateAndTime. Installing the changes takes time because the become operations are slow, and this may give the impression that the image has locked up. Be patient, and in due time all will be well.

Migration

With regard to serialization, it is handled as follows:

Name: Chronology-Core-dtl.26
Author: dtl
Time: 8 December 2016, 8:23:28.539757 pm
UUID: 9572cf6e-6c65-4205-9435-f82b6c169a98
Ancestors: Chronology-Core-dtl.25

Fix readDataFrom:size: and implement storeDataOn:

Strategy - Always store instances of DateAndTime as if they were the old
format with seconds, offset, jdn, nanos. This ensures that serialized
instances such as those in the snapshot.bin of a Monticello archive can
be read by any image.

Implementation is in DateAndTime>>readDataFrom:size: and DateAndTime>>storeDataOn:
and I expect that both Fuel and Ma-Serializer will need similar handling.

Historical versions

Historical versions from the original development:

Load UTCDateAndTime from a SAR archive (original procedure as of May 2015) UTCDateAndTime-dtl-20150526.sar

The updated SAR for Squeak trunk as of March 2016 is UTCDateAndTime-dtl-20160306.sar

UTCDateAndTime was originally posted as UtcDateAndTime-dtl.sar on the squeak-dev list http://lists.squeakfoundation.org/pipermail/squeak-dev/2014-May/178325.html under the subject line "A UTC based implementation of DateAndTime". A simple performance test utility was also included LXTestDateAndTimePerformance.st.