Unix Time

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Unix Time

Mike Hales
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.

Thanks,

Mike

Mike Hales
Engineering Manager
KnowledgeScape
www.kscape.com


Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

David T. Lewis
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


Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

Bert Freudenberg
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 -



Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

Bert Freudenberg
On 15.01.2010, at 05:26, 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.

In the latest trunk image, there now is #asUnixTime :)

On 15.01.2010, at 12:16, Bert Freudenberg wrote:
>
> http://tinlizzie.org/updates/etoys/updates/2092LocalePluginAddins-tpr.cs
> http://tinlizzie.org/updates/etoys/updates/2106chronologyUnix-bf.cs

I just committed these to trunk, with one modification to the startup - the timezone is set unconditionally (independent of useLocale).

The timezone is only set on startup. So restart the image or evaluate "Locale startUp: true".

before:

DateAndTime now
==> 2010-01-15T12:23:35.301+00:00

after:

DateAndTime now
==> 2010-01-15T12:24:02.452+01:00

(note the last four digits which are the local time offset)

DateAndTime now asUnixTime
==> 1263554652

- Bert -


Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

Mike Hales
That is beautiful! I wake up check my email, it's in the trunk, I hit the update button, go to my workspace and try it, it works.

Awesome, thanks.

Mike

Mike Hales
Engineering Manager
KnowledgeScape
www.kscape.com


On Fri, Jan 15, 2010 at 5:11 AM, Bert Freudenberg <[hidden email]> wrote:
On 15.01.2010, at 05:26, 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.

In the latest trunk image, there now is #asUnixTime :)

On 15.01.2010, at 12:16, Bert Freudenberg wrote:
>
> http://tinlizzie.org/updates/etoys/updates/2092LocalePluginAddins-tpr.cs
I just committed these to trunk, with one modification to the startup - the timezone is set unconditionally (independent of useLocale).

The timezone is only set on startup. So restart the image or evaluate "Locale startUp: true".

before:

DateAndTime now
==> 2010-01-15T12:23:35.301+00:00

after:

DateAndTime now
==> 2010-01-15T12:24:02.452+01:00

(note the last four digits which are the local time offset)

DateAndTime now asUnixTime
==> 1263554652

- Bert -





Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

Levente Uzonyi-2
In reply to this post by Bert Freudenberg
On Fri, 15 Jan 2010, Bert Freudenberg wrote:

> On 15.01.2010, at 05:26, 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.
>
> In the latest trunk image, there now is #asUnixTime :)
>
> On 15.01.2010, at 12:16, Bert Freudenberg wrote:
>>
>> http://tinlizzie.org/updates/etoys/updates/2092LocalePluginAddins-tpr.cs
>> http://tinlizzie.org/updates/etoys/updates/2106chronologyUnix-bf.cs
>
> I just committed these to trunk, with one modification to the startup - the timezone is set unconditionally (independent of useLocale).
>

Great, thanks. DateAndTimeTest >> #testReadFrom is failing now, because it
assumes that offset will be zero, which is okay according to the comment
in String >> #asDateAndTime which says: "Convert from UTC format".


Levente

> The timezone is only set on startup. So restart the image or evaluate "Locale startUp: true".
>
> before:
>
> DateAndTime now
> ==> 2010-01-15T12:23:35.301+00:00
>
> after:
>
> DateAndTime now
> ==> 2010-01-15T12:24:02.452+01:00
>
> (note the last four digits which are the local time offset)
>
> DateAndTime now asUnixTime
> ==> 1263554652
>
> - Bert -
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

David T. Lewis
In reply to this post by Bert Freudenberg
On Fri, Jan 15, 2010 at 01:11:22PM +0100, Bert Freudenberg wrote:
> On 15.01.2010, at 05:26, 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.
>
> In the latest trunk image, there now is #asUnixTime :)

Very nice! I didn't even know we had a #primitiveTimezoneOffset.

It's about time for me to update TimeZoneDatabase (Olsen tz table support)
to place nice with this.

Dave


Reply | Threaded
Open this post in threaded view
|

Re: Unix Time

Bert Freudenberg
On 16.01.2010, at 16:08, David T. Lewis wrote:
>
> On Fri, Jan 15, 2010 at 01:11:22PM +0100, Bert Freudenberg wrote:
>> On 15.01.2010, at 05:26, 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.
>>
>> In the latest trunk image, there now is #asUnixTime :)
>
> Very nice! I didn't even know we had a #primitiveTimezoneOffset.

Yes, LocalePlugin isn't widely used yet. Even in Etoys we just use the language and timezone settings.

- Bert -

> It's about time for me to update TimeZoneDatabase (Olsen tz table support)
> to place nice with this.
>
> Dave
>
>