local time (was: something about Celeste)

Lex Spoon lex at cc.gatech.edu
Wed Dec 1 23:04:35 UTC 1999


Okay, here is a proposal for minimal support of local time.  All it does
is specify a new primitive which returns the local time and the offset
in seconds from UTC time.  It also shows a few new Time queries which
use this new primitive.  It does *not* add any notion of time zones;
dealing with time zones sounds pretty complicated and code-heavy, and so
is deferred to a later project.

The epoch is left at Jan 1, 1901.  Does it really matter what we use? 
No matter what you use, it would seem that you have to use negative
numbers if you go far enough back in time.  And if nothing else, your
app can use some other epoch internally by adding a big constant to
whatever Squeak returns.

This patch should be backwards compatible; if your VM doesn't have the
new primitive, then the fallback code uses #primSecondsClock with a 0
offset--ie, it assumes your existing primSecondsClock implementation
returns a time in UTC.  I guess it could be changed so that the default
is California time, or something :)


So does this sound reasonable to people?  It seems like just the ticket
to get Celeste's Date field going, and it seems like enough to get an
HTTP cache with expiry going if anyone wants to try for that.

Lex




'From Squeak2.7alpha of 25 October 1999 [latest update: #1568] on 1
December 1999 at 10:46:22 pm'!
"Change Set:		Time
Date:			1 December 1999
Author:			Lex Spoon

adds a primitive to distinguish local time from global time"!


!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:39'!
dateAndTimeNow
	"Answer a two-element Array of (Date today, Time now) in local time"
	^self localDateAndTimeNow! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:45'!
dateAndTimeNowWithOffset
	"Answer a three-element Array of (Date today, Time now, offset from
UTC)"
	| secondsCount offset |
	{secondsCount. offset} _ self localSecondsClockWithOffset.
	^(self dateAndTimeFromSeconds: secondsCount) copyWith: offset! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:37'!
localDateAndTimeNow
	"Answer a two-element Array of (Date today, Time now) in local time"

	| secondCount |
	secondCount _ self localSecondsClock.
	^self dateAndTimeFromSeconds: secondCount! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:29'!
localSecondsClock
	"return the seconds since Jan 1, 1901, in local time"
	^self localSecondsClockWithOffset at: 1! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:33'!
localSecondsClockWithOffset
	"calculate the local time, and its ofset from UCT"
	|ans|
	ans _ Array new: 2.
	self primLocalSecondsClockWithOffset: ans.
	^ans! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:39'!
utcDateAndTimeNow
	"Answer a two-element Array of (Date today, Time now) in UTC time"
	| secondCount |
	secondCount _ self utcSecondsClock.
	^self dateAndTimeFromSeconds: secondCount! !

!Time class methodsFor: 'general inquiries' stamp: 'ls 12/1/1999 22:34'!
utcSecondsClock
	"return the seconds since Jan 1, 1901, in UTC time"
	| clockWithOffset |
	clockWithOffset _ self localSecondsClockWithOffset at: 1.
	^clockWithOffset first - clockWithOffset second! !

!Time class methodsFor: 'private' stamp: 'ls 12/1/1999 22:31'!
primLocalSecondsClockWithOffset: array
	"calculate the local time, and its ofset from UCT"
	<primitive: 'localSecondsClockWithOffset' module: 'time'>

	"if failed, assume UTC time  (modify this if you want it to assume some
other time zone by default"
	array at: 1 put: self primSecondsClock.
	array at: 2 put: 0.! !





More information about the Squeak-dev mailing list