[squeak-dev] Fuel update for UTCDateAndTime

David T. Lewis lewis at mail.msen.com
Mon Nov 26 13:20:49 UTC 2018


The Fuel serializer is loadable in Squeak 5.2 from the SqueakMap loader,
and is supported for Pharo, Squeak, and Cuis (great kudos to the
maintainers for doing this).

In order to change DateAndTime to a simpler UTC-based implementation in
Squeak, with two instance variables rather than four, an update will be
needed for Fuel to understand the new format.

The attached change set provides the necessary support, while maintaining
compatibility with the traditional DateAndTime and interoperability
between images that support either format. For example, an image can
serialize a traditional DateAndTime with Fuel, and another image with
UTC DateAndTime can materialize it in the new UTC format.

I am not yet sure how to submit this to the Fuel maintainers, so I'm
posting it here as a change set for now.

Dave

-------------- next part --------------
'From Squeak5.2 of 13 December 2018 [latest update: #18221] on 26 November 2018 at 8:17:56 am'!
"Change Set:		Fuel update for UTCDateAndTime
Date:			26 November 2018
Author:			David T. Lewis

Update Fuel serialization for a DateAndTime in the new UTC format for Squeak, where DateAndTime has only the two instance variables 'utcMicroseconds' and 'localOffsetSeconds'. Compatibility is maintained with the traditional DateAndTime with 'seconds' 'offset' 'jdn' and 'nanos' instance variables. A DateAndTime serialized from one format can be materialized in an image using the other format, which may be important if serialzied data is kept in external files or databases."!


!DateAndTime methodsFor: '*FuelPlatformExtensions' stamp: 'dtl 11/26/2018 08:17'!
serializeOn: t1 
	<flExtensionOf: #DateAndTime selector: #serializeOn:>
	self class instSize = 2
		ifFalse: [ "traditional jdn, seconds, nanos, offset instance variables based on local time"
			t1 encodeUint32: self julianDayNumberUTC;
			 	encodeUint32: self nanoSecond;
				 encodeInt24: self secondsSinceMidnight;
				 encodeInt24: self offset asSeconds;
				 encodeInt32: self offset nanoSeconds ]
		ifTrue: [ | ticks | "materialize to new format with UTC microseconds and local offset"
			ticks := self ticks.
			t1 encodeUint32: (ticks at: 1);
			 	encodeUint32: (ticks at: 3);
				 encodeInt24: (ticks at: 2);
				 encodeInt24: self offset asSeconds;
				 encodeInt32: self offset nanoSeconds ]
! !


!DateAndTime class methodsFor: '*Fuel-Core' stamp: 'dtl 11/26/2018 00:49'!
materializeFrom: aDecoder

	| jdn nanos seconds offset |
	jdn := aDecoder nextEncodedUint32.
	nanos :=  aDecoder nextEncodedUint32.
	seconds := aDecoder nextEncodedInt24.
	offset := Duration 
		seconds: aDecoder nextEncodedInt24 
		nanoSeconds: aDecoder nextEncodedInt32.
	self instSize = 2
		ifFalse: [ "traditional jdn, seconds, nanos, offset instance variables based on local time" ]
		ifTrue: [ "materialize to new format with UTC microseconds and local offset"
				seconds := seconds + offset asSeconds].
	^ self basicNew
			setJdn: jdn
			seconds: seconds
			nano: nanos
			offset: offset;
			yourself
! !

DateAndTime removeSelector: #fuelSet:nanoSecond:seconds:offset:!


More information about the Squeak-dev mailing list