time or the lack of it...

John M McIntosh johnmci at smalltalkconsulting.com
Wed Nov 21 06:50:04 UTC 2001


>On Tue, Nov 20, 2001 at 06:41:01PM -0800, John M McIntosh wrote:
>>
>>  For the curious what is pending is
>>
>>  a) The ability to get back a UUID. This uses C code to generate the
>>  UUID for mac and windows. However I'm looking at some doing some
>>  Smalltalk code. Mind the lack of simple things like getting the
>>  current UTC time is a hassle. Anyone have timezone for Squeak code.
>
>A bit heavyweight for what you have in mind, but TimeZone is at
>http://minnow.cc.gatech.edu/squeak/1076
>
>Dave

Yes a bit much, but very interesting. I'm tempted to punt so to speak 
and go ask my friendly time server what the time is.

	| serverAddr s |
	Socket initializeNetworkIfFail: [^self error: 'Failed to init 
network'].
	serverAddr _ NetNameResolver addressForName: 
'time-a.nist.gov' timeout: 10.
	serverAddr = nil ifTrue: [self error: 'Could not find the 
address for time-a.nist.gov'].
	s _ Socket new.
	s connectTo: serverAddr port: 13. 
	s waitForConnectionUntil: (self deadlineSecs: 15).
	Transcript show: 'the time server reports: ' , s 
getResponseNoLF,' at time ',Time now printString;cr.
	s closeAndDestroy.


Try it,

the time server reports: 52234 01-11-21 05:33:07 00 0 0 599.9 
UTC(NIST) *  at time 9:33:06 pm

See http://www.boulder.nist.gov/timefreq/service/its.htm

then do some messy math and roughly estimate the time zone I'm in and 
go from there... This assume the silly system clock is oh 5 to 10 
minutes within the real time I'd guess, actually it doesn't matter 
the math + or - will allow me to back calculate the UTC time. MMm I 
could go with port 37 and get the seconds since 1900, that might be 
easier, then get the seconds in squeak since 1901

Mm but what about that millisecond clock, a distraction.. Let see on 
the mac the internal nanosecond clock will wrap after count 
milliseconds for 24.855 days (2147483647 milliseconds).I'm not sure 
I've have an image up that long in a test environment so I'm unsure 
what it means. However but since the millisecond clock is returned as 
smallinteger it only can span 536870911 milliseconds or 6.213 days. 
Which is the limit for a millisecond interval btw. MMM I wonder if 
anyone has tested that... yes a distraction.

Maybe there is an OS call to get the timezone you are in and I'll 
punt to the VM  maintainers eh?

Sigh of course machines aren't required to be connected to the internet...
-- 
--
===========================================================================
John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================




More information about the Squeak-dev mailing list