[squeak-dev] The Trunk: Chronology-Core-dtl.67.mcz

commits at source.squeak.org commits at source.squeak.org
Sat Jul 3 21:30:54 UTC 2021


David T. Lewis uploaded a new version of Chronology-Core to project The Trunk:
http://source.squeak.org/trunk/Chronology-Core-dtl.67.mcz

==================== Summary ====================

Name: Chronology-Core-dtl.67
Author: dtl
Time: 3 July 2021, 5:30:52.505882 pm
UUID: d25ed490-226f-4216-b39d-29880e215059
Ancestors: Chronology-Core-dtl.66

Cruft removal. DateAndTime no longer needs to be in the startUp list. The canInitializeFromPrimitive workaround is no longer needed. Do not use the no-argument call to primitiveUtcWithOffset, which works fine but is easier to understand in the image if we always use a single primitive interface.

=============== Diff against Chronology-Core-dtl.66 ===============

Item was changed:
  Magnitude subclass: #DateAndTime
  	instanceVariableNames: 'utcMicroseconds localOffsetSeconds'
+ 	classVariableNames: 'AutomaticTimezone ClockProvider LocalTimeZone PosixEpochJulianDays'
- 	classVariableNames: 'AutomaticTimezone ClockProvider InitializeFromPrimitive LocalTimeZone PosixEpochJulianDays'
  	poolDictionaries: 'ChronologyConstants'
  	category: 'Chronology-Core'!
  
  !DateAndTime commentStamp: 'dtl 3/12/2016 10:32' prior: 0!
  I represent a point in UTC time as defined by ISO 8601. I have zero duration.
  
  My implementation uses variables utcMicroseconds and localOffsetSeconds. 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.
  !

Item was removed:
- ----- Method: DateAndTime class>>canInitializeFromPrimitive (in category 'system startup') -----
- canInitializeFromPrimitive
- 	"Some implementations of primitiveUtcWithOffset do not support passing the
- 	DateAndTime instance as a parameter to the primitive."
- 
- 	^self  basicNew initializeFromPrimitive utcMicroseconds notNil!

Item was changed:
  ----- Method: DateAndTime class>>initialize (in category 'initialize-release') -----
  initialize
  
  	ClockProvider := Time.
  	PosixEpochJulianDays := 2440588.
- 	InitializeFromPrimitive := self canInitializeFromPrimitive.
  	Smalltalk addToStartUpList: self.
  	self startUp: true
  !

Item was changed:
  ----- Method: DateAndTime class>>now (in category 'ansi protocol') -----
  now
  	"Answer time now as reported by #primitiveUtcWithOffset. If the primitive is not
  	available, answer the Posix epoch GMT."
  
  	self automaticTimezone
+ 		ifTrue: [ ^ self basicNew initializeFromPrimitive ]
- 		ifTrue: [ InitializeFromPrimitive
- 			ifTrue: [ ^ self basicNew initializeFromPrimitive ]
- 			ifFalse: [ | timeArray |
- 				timeArray := Time posixMicrosecondClockWithOffset.
- 				^ self utcMicroseconds: timeArray first offset: timeArray second ] ]
  		ifFalse: [ | timeArray |
  			timeArray := Time posixMicrosecondClockWithOffset.
  			^ self utcMicroseconds: timeArray first offset: self localOffsetSeconds ]
  !

Item was removed:
- ----- Method: DateAndTime class>>startUp: (in category 'system startup') -----
- startUp: startingAfresh
- 	"Set local timezone"
- 	startingAfresh
- 		ifTrue: [InitializeFromPrimitive := self canInitializeFromPrimitive.
- 			Time initialize. "set LastClockTick to 0".
- 			self now]!

Item was changed:
  ----- Method: Time class>>posixMicrosecondClockWithOffset (in category 'clock') -----
  posixMicrosecondClockWithOffset
  	"Answer an array with local microseconds since the Posix epoch and the
  	current seconds offset from GMT in the local time zone."
  
  	| array posixUtcValue |
+ 	array := self primPosixMicrosecondClockWithOffset: (Array new: 2).
- 	array := self primPosixMicrosecondClockWithOffset.
  	posixUtcValue := array at: 1.
  	(self updateTimeZoneCacheAt: posixUtcValue) ifTrue: [ "Time zone may have changed: fetch again."
  		self primPosixMicrosecondClockWithOffset: array.
  		posixUtcValue := array at: 1 ].
  	ClockPolicy caseOf: {
  		[#acceptPlatformTime] -> [^ array] .
  		[#monotonicAllowDuplicates] -> [
  			posixUtcValue > LastClockTick
  				ifTrue: [LastClockTick := posixUtcValue]
  				ifFalse: [array at: 1 put: LastClockTick]] .
  		[#monotonicForceMicrosecondIncrement] -> [
  			posixUtcValue > LastClockTick
  				ifTrue: [LastClockTick := posixUtcValue]
  				ifFalse: [LastClockTick := LastClockTick + 1. "add one microsecond"
  					array at: 1 put: LastClockTick]] .
  		[#monotonicForceNanosecondIncrement] -> [
  			posixUtcValue > LastClockTick
  				ifTrue: [LastClockTick := posixUtcValue]
  				ifFalse: [LastClockTick := LastClockTick + (1 / 1000). "add one nanosecond"
  					array at: 1 put: LastClockTick]]
  	} otherwise: [].
  	^array!

Item was removed:
- ----- Method: Time class>>primPosixMicrosecondClockWithOffset (in category 'private') -----
- primPosixMicrosecondClockWithOffset
- 	"Answer an array with UTC microseconds since the Posix epoch and the
- 	current seconds offset from GMT in the local time zone. If the primitive is
- 	not available, then answer the time and offset of Posix epoch GMT. This enables
- 	the image to continue running in the absence of #primitiveUtcWithOffset, thus
- 	avoiding the need to fallback code based on the earlier local microsecond clock
- 	mechanism."
- 
- 	<primitive: 'primitiveUtcWithOffset'>
- 	^{0. 0}!

Item was changed:
+ ----- Method: Time class>>primPosixMicrosecondClockWithOffset: (in category 'clock') -----
- ----- Method: Time class>>primPosixMicrosecondClockWithOffset: (in category 'private') -----
  primPosixMicrosecondClockWithOffset: arrayOrObjectWithTwoSlots
  	"Answer an array with UTC microseconds since the Posix epoch and the
  	current seconds offset from GMT in the local time zone. If the primitive is
  	not available, then answer the time and offset of Posix epoch GMT. This enables
  	the image to continue running in the absence of #primitiveUtcWithOffset, thus
  	avoiding the need to fallback code based on the earlier local microsecond clock
  	mechanism.
  
  	The parameter may be a two element array, or an object whose first two instance
  	variables are expected to be UTC microseconds and seconds offset from GMT."
  
  	<primitive: 'primitiveUtcWithOffset'>
  
  	(arrayOrObjectWithTwoSlots instVarAt: 1)
  		ifNil: [arrayOrObjectWithTwoSlots instVarAt: 1 put: 0].
  	(arrayOrObjectWithTwoSlots instVarAt: 2)
  		ifNil: [arrayOrObjectWithTwoSlots instVarAt: 2 put: 0]!

Item was changed:
+ (PackageInfo named: 'Chronology-Core') postscript: 'Smalltalk removeFromStartUpList: DateAndTime'!
- (PackageInfo named: 'Chronology-Core') postscript: '"Make sure UpdateVMTimeZoneCacheAt of Time is initialized."
- Time classPool at: #UpdateVMTimeZoneCacheAt put: 0.
- "Separated Time''s startup duties from DateAndTime."
- Smalltalk addToStartUpList: Time before: DateAndTime'!



More information about the Squeak-dev mailing list