[BUG] Chronology DateAndTime class>>now returns incorrect time

Lex Spoon lex at cc.gatech.edu
Mon Feb 23 01:03:33 UTC 2004


Timothy Rowledge <tim at sumeru.stanford.edu> wrote:
> If it is really considered important to have micro/nano second 
> resolution in times we will want a new primitive that (for example) 
> returns effectively the same as that unix call that gives the seconds 
> and milliseconds etc. I'd doubt there are many OS calls that give 
> reliable nanosecond results though While we're thinking about it, it 
> might be useful to consider an optional prim that can make use of 
> functions like gmtime() since that leaves the tricky arithmetic to 
> someone else.

And while one is at it, one may as well support UTC time as well as
local time, so that Squeak's in different timezones can communicate
about time without confusing each other.

Attached is a plugin I wrote long ago, plus a patch to make use of it. 
I've also attached a patch to Richard Harmon's ANSI Compatibility
package to make use of it.  While Chronology seems to be more popular
than Harmon's older work, this patch should at least provide a useful
example to anyone who wants to try and use the plugin.

The main downside of the plugin is that it only has resolution to
seconds.  But hopefully it is a useful starting point even so.

There is only one function in this plugin, and it returns both local
time and UTC time as split apart by localtime() and gmtime().  The
Squeak-level interface to this generates four items: local date, local
time, UTC date, and UTC time.

This is enough for several purposes.  If you want local time, then you
have it.  If you want local time plus an offset, e.g. for an email
header, then you can subtract the two time values to get it.  And if you
want to go all out and support time zones explicitly, then you can
ignore the supplied local time and compute local times yourself from the
UTC date and time.

Now, if you want to add microseconds to the mix, I would think you could
use gettimeofday() instead of time().  Simply pretend the tv_sec field
came from time(), and then add the tv_usec in after you get your results
from localtime() and gmtime().  But this has only just now occured to
me, thus it's not in the plugin.

-Lex
-------------- next part --------------
A non-text attachment was scrubbed...
Name: /home/lex/squeak/TimePlugin.4.cs
Type: application/octet-stream
Size: 4057 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040222/5fd950be/TimePlugin.4.obj
-------------- next part --------------
A non-text attachment was scrubbed...
Name: /home/lex/squeak/useTimePlugin.7.cs
Type: application/octet-stream
Size: 4015 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040222/5fd950be/useTimePlugin.7.obj


More information about the Squeak-dev mailing list