TimeStamp Class

Daniel Salama dsalama at user.net
Thu Apr 7 23:45:23 UTC 2005


I found this, in case anyone is interested in reading:
http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-April/ 
024439.html

John, I think you even posted that message.

Anyway, I've been reading and trying to figure out what you're  
suggesting, but have not been lucky. I've been trying to compute the  
milliseconds since epoch. I will settle for Squeak's epoch which is  
01/01/1901 (instead of the more common 01/01/1970). However, the  
millisecondClockValue, as you mentioned, starts at some arbitrary  
point, which I can't figure out which one it was.

I did a simple experiment:

timeNow := Time now. "6:58:33 pm"
millisecondsSincePrime := Time millisecondClockValue.
Transcript show: (timeNow asSeconds - (millisecondsSincePrime // 1000)  
* 1000 + millisecondsSincePrime).

This prints the value:  68313764. If I make a very rough and inaccurate  
conversion:

Transcript show: (68313764 / 3600000) asFloat.

This prints the value: 18.97604555555556, which is equivalent to  
18:58:33.7640000000218 which is pretty accurate for what I need.  
Granted, there could be a slight difference in the time the VM takes to  
execute the first two statements.

Then, if I do the following:

timeNow := Time totalSeconds.
millisecondsSincePrime := Time millisecondClockValue.
Transcript show: (timeNow - (millisecondsSincePrime // 1000) * 1000 +  
millisecondsSincePrime).

This prints the value: 3290355022972. If I apply a similarly rough and  
inaccurate conversion:

Transcript show: (3290355022972 / 31536000) asFloat.
"31536000 is the approximate number of milliseconds in a year"

This prints the value: 104.3364733311771, which is equivalent to 104  
years, 122 days, 19:30:22.972. Obviously this simple "reverse"  
computation didn't take into account leap years and leap seconds and  
all that, but in essence, I think it does compute the number of  
milliseconds since SqueakEpoch.

Does anyone see any flaws in this? Any suggestions?

Thanks,
Daniel

On Apr 7, 2005, at 5:21 PM, John M McIntosh wrote:

> This only returns the millisecond clock value which has started from  
> some arbitrary point, and will roll over at some point either when it  
> exceeds 536870911 or
> at some decision made by the support VM based on hosting OS or  
> hardware limitations.   See Time (class)>>millisecondsSince:  &  
> millisecondsToRun: for logic to handle clock rollover. I recall in the  
> past someone asked for access to the millisecond value as part of the  
> second call (or another primitive). But I don't believe anything was  
> done.
>
> On Apr 7, 2005, at 1:45 PM, Joan Barrull wrote:
>
>> Hope this helps:
>>
>>  3 timesRepeat: [ Transcript cr; show:DateAndTime  
>> millisecondClockValue ]
>>
>>
>> Regards,
>>
>>  joan
>>
>> On Apr 7, 2005 9:10 PM, Daniel Salama <dsalama at user.net> wrote:
>>> I'm trying to get the difference of two TimeStamps objects and the  
>>> best
>>> accuracy I get is "asSeconds". When I try asMilliSeconds or
>>> asNanoSeconds, the result is simply padded with 0s. Is there a better
>>> way to get higher degree of accuracy? Maybe I'm just using the wrong
>>> classes. For example:
>>>
>>> epoch := TimeStamp date: (Date readFromString: '01-01-1970') time:
>>> (Time new).
>>> Transcript clear.
>>> 1 to: 20 do: [:i|
>>>        Transcript cr; show: (((TimeStamp date: (Date today) time:  
>>> (Time now))
>>> - epoch) asMilliSeconds)
>>> ].
>>>
>>> The idea behind is to get the number of milli seconds since the  
>>> Epoch.
>>> Is there a better way to do this?
>>>
>>> Thanks,
>>> Daniel
>>>
>>>
>>
>>
> --
> ======================================================================= 
> ====
> John M. McIntosh <johnmci at smalltalkconsulting.com> 1-800-477-2659
> Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
> ======================================================================= 
> ====


Daniel Salama
dsalama at user.net
Voice: (954) 655-8051
Fax  : (954) 252-3988

------------------------

This e-mail contains information which may be confidential and
privileged. Unless you are the addressee (or authorized to
receive for the addressee), you may not use, copy or disclose
to anyone the message or any information contained in the
message.  If you have received the message in error, please
advise the sender by reply e-mail to dsalama at user.net or
tel. +1-954-655-8051 and delete the material from any computer.




More information about the Squeak-dev mailing list