[squeak-dev] Unix Time

Bert Freudenberg bert at freudenbergs.de
Fri Jan 15 11:16:32 UTC 2010


On 15.01.2010, at 07:11, David T. Lewis wrote:
> 
> On Thu, Jan 14, 2010 at 09:26:34PM -0700, Mike Hales wrote:
>> Is there any protocol in the DateAndTime hierarchy that returns the unix
>> time? I want the equivalent of typing "date +%s" on the command line.
> 
> No, Squeak inherently uses local time with naive time zone representation.
> 
> If you are looking for seconds since the posix epoch, then see:
>  http://www.squeaksource.com/TimeZoneDatabase/
>  http://wiki.squeak.org/squeak/1076
> 
> Then set your time zone and use "PointInTime now asPosixSeconds"
> or "DateAndTime now asPointInTime asPosixSeconds".
> 
> Dave

I had to add that to Etoys for OLPC, the Sugar time stamps are in Unix time. Involved VM fixes to unify timezone handling across platforms. You can now access the time zone on all platforms. No manual setting of time zone required. 

Now I just need to find that ...

Ah yes. It uses LocalePlugin's primitiveTimezoneOffset:
http://tinlizzie.org/updates/etoys/updates/2092LocalePluginAddins-tpr.cs
It's mostly Tim's original code (hence -tpr) with some modifications I did to make it actually work. Tim's stuff is already in trunk, but Locale class>>startUp: does not set the timezone (and useLocale is off by default). I invented 'LT' to signify 'Local Time' because IIRC the time zone name prim is not working yet.

And this adds #asUnixTime:
http://tinlizzie.org/updates/etoys/updates/2106chronologyUnix-bf.cs

- Bert -





More information about the Squeak-dev mailing list