Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

WallClock

Moderators: larsivi kris

Posted: 05/25/07 00:52:38

On linux with dmd, tango r2247

WallClock?.now - Clock.now => 2h
WallClock?.zone => 1h

Is this daylight saving?

How can i convert a given UTC time value, into a local time?
The zone value seams missing one hour.

Ideally the daylight saving shall be dependent on the given time value.

Author Message

Posted: 05/25/07 20:18:14

keinfarbton wrote:

On linux with dmd, tango r2247

WallClock?.now - Clock.now => 2h
WallClock?.zone => 1h

Is this daylight saving?

How can i convert a given UTC time value, into a local time?
The zone value seams missing one hour.

Ideally the daylight saving shall be dependent on the given time value.

Yeah, that's DST at work. It's a pain to handle because of how linux exposes the Time/Date functions ... you have to use WallClock?.toDate(utc) to get DST taken into account.

Posted: 05/27/07 12:38:57

The Date is restricted to seconds. I think it would be cool, to have a

 Time WallClock.toTime( Time utc );

What do you think?

Posted: 05/28/07 20:42:26

Can you show me the (portable, dependable) Posix code to implement this ?

Posted: 05/30/07 15:17:30

Hm, if WallClock?.toDate(utc) meets your criteria and creates a Date, it should be possible to return a Time as well?

// in WallClock
Time toTime( Time utc ){
  long remainingTicksToMs = utc % Time.TicksPerMillisecond;
  return cast(Time)( Clock.fromDate( WallClock.toDate( utc )) + remainingTicksToMs );
}

Posted: 05/30/07 18:19:04

Oh, OK ... thought you perhaps had something else in mind. Could probably do something like that; thx :)

Posted: 06/02/07 08:05:47

WallClock? has a couple of new functions called toLocal() and toUtc() ... hope they do the trick :)

Posted: 06/02/07 12:20:18

Thank you, toLocal works on my Linux/dmd