[squeak-dev] The Inbox: Chronology-Core-eem.22.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Jan 10 02:53:53 UTC 2019


A new version of Chronology-Core was added to project The Inbox:
http://source.squeak.org/inbox/Chronology-Core-eem.22.mcz

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

Name: Chronology-Core-eem.22
Author: eem
Time: 9 January 2019, 6:53:52.265064 pm
UUID: 348c4ad7-0a27-4021-8788-9e3ec220df24
Ancestors: Chronology-Core-ul.21

Simple speedup by caching the result of getSeconds in an inst var.  Lots of other values are defined in terms of getSeconds so this simply eliminates duplicating the large integer arithmetic in getSeconds.

=============== Diff against Chronology-Core-ul.21 ===============

Item was changed:
  Magnitude subclass: #DateAndTime
+ 	instanceVariableNames: 'utcMicroseconds localOffsetSeconds seconds'
- 	instanceVariableNames: 'utcMicroseconds localOffsetSeconds'
  	classVariableNames: 'AutomaticTimezone ClockProvider InitializeFromPrimitive LocalTimeZone PosixEpochJulianDays'
  	poolDictionaries: 'ChronologyConstants'
  	category: 'Chronology-Core'!
  
+ !DateAndTime commentStamp: 'eem 1/9/2019 18:44' prior: 0!
- !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.  I cache the result of getSeconds in the seconds variable that is computed when required.
- 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 changed:
  ----- Method: DateAndTime>>getSeconds (in category 'accessing') -----
  getSeconds
- 
  	| posixDays posixSeconds localSeconds |
+ 	seconds ifNil:
+ 		[posixSeconds := utcMicroseconds // 1000000.
+ 		 localSeconds := posixSeconds + localOffsetSeconds.
+ 		 localSeconds < 0 ifTrue: [localSeconds := localSeconds \\ SecondsInDay]. "normalize"
+ 		 posixDays := localSeconds // SecondsInDay.
+ 		 seconds := localSeconds - (posixDays * SecondsInDay)].
+ 	^seconds!
- 	posixSeconds := utcMicroseconds // 1000000.
- 	localSeconds := posixSeconds + localOffsetSeconds.
- 	localSeconds < 0 ifTrue: [localSeconds := localSeconds \\ SecondsInDay]. "normalize"
- 	posixDays := localSeconds // SecondsInDay.
- 	^localSeconds - (posixDays * SecondsInDay).
- !

Item was changed:
  ----- Method: DateAndTime>>readDataFrom:size: (in category 'objects from disk') -----
  readDataFrom: aDataStream size: varsOnDisk
  	"Fill in the fields of self based on the contents of aDataStream. The serialized
  	data will have four instance variables, because all instances are serialized in a
  	cononical format as if having originating from an instance with the traditional
  	seconds/offset/jdn/nanos instance variables."
   
  	| seconds offset jdn nanos |
  	seconds := aDataStream next.
  	offset := aDataStream next.
  	jdn := aDataStream next.
  	nanos := aDataStream next.
  	localOffsetSeconds := offset ifNil: [ 0 ] ifNotNil: [ :off | off asSeconds ].
  	utcMicroseconds := self
  				microsecondsFromDay: jdn
  				seconds: seconds
  				nanos: nanos
+ 				offset: localOffsetSeconds..
+ 	seconds := nil!
- 				offset: localOffsetSeconds.!

Item was changed:
  ----- Method: DateAndTime>>setJdn:seconds:nano:localOffsetSeconds: (in category 'private') -----
  setJdn: jdn seconds: s nano: n localOffsetSeconds: offset
  
  	localOffsetSeconds := offset.
  	utcMicroseconds := self
  				microsecondsFromDay: jdn
  				seconds: s
  				nanos: n
+ 				offset: offset.
+ 	seconds := nil!
- 				offset: offset!

Item was changed:
  ----- Method: DateAndTime>>ticks:offset: (in category 'private') -----
  ticks: ticks offset: utcOffset
  	"ticks is {julianDayNumber. secondCount. nanoSeconds}"
  
  	| jdn s nanos |
  	self normalize: 3 ticks: ticks base: NanosInSecond.
  	self normalize: 2 ticks: ticks base: SecondsInDay.
  
  	jdn	:= ticks at: 1.
  	s := ticks at: 2.
  	nanos := ticks at: 3.
  	localOffsetSeconds := utcOffset ifNil: [0] ifNotNil: [utcOffset asSeconds].
  	utcMicroseconds := self microsecondsFromDay: jdn seconds: s nanos: nanos offset: localOffsetSeconds.
+ 	seconds := nil!
- !

Item was changed:
  ----- Method: DateAndTime>>utcMicroseconds: (in category 'initialize-release') -----
  utcMicroseconds: utcValue
  	"Allow value to be modified during initialization from a primitive in order to support
  	monotonically increasing clock behavior."
+ 	utcMicroseconds := utcValue.
+ 	seconds := nil!
- 	utcMicroseconds := utcValue!

Item was changed:
  ----- Method: DateAndTime>>utcMicroseconds:offset: (in category 'initialize-release') -----
  utcMicroseconds: microsecondsSincePosixEpoch offset: tzOffset
  
  	utcMicroseconds := microsecondsSincePosixEpoch.
  	localOffsetSeconds := tzOffset.
+ 	seconds := nil
  !



More information about the Squeak-dev mailing list