www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - timezone problem

reply Qian Xu <quian.xu stud.tu-ilmenau.de> writes:
Hi All,

I am fighting with date time conversion and have a problem right now:
I want to convert a local timestamp to UTC timestamp.
So I have to get the time zone information.
However in some countries (ie. German, US), the offset is not constant,
because of daylight saving issue.

Is there any "hidden" routine can tell the correct time zone information
(cross platform, esp. open suse)

Any hints are apprecated ^^)

--Qian
Jan 13 2009
next sibling parent reply Qian Xu <quian.xu stud.tu-ilmenau.de> writes:
BTW: Is there any Date.Format("YYYY-mm-dd") function?
Jan 13 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Qian Xu wrote:
 BTW: Is there any Date.Format("YYYY-mm-dd") function?
Not in Phobos. But there is such a thing in my utility library: http://pr.stewartsplace.org.uk/d/sutil/ Stewart.
Jan 13 2009
prev sibling next sibling parent reply Sergey Gromov <snake.scaly gmail.com> writes:
Tue, 13 Jan 2009 11:27:40 +0100, Qian Xu wrote:

 Hi All,
 
 I am fighting with date time conversion and have a problem right now:
 I want to convert a local timestamp to UTC timestamp.
 So I have to get the time zone information.
 However in some countries (ie. German, US), the offset is not constant,
 because of daylight saving issue.
 
 Is there any "hidden" routine can tell the correct time zone information
 (cross platform, esp. open suse)
 
 Any hints are apprecated ^^)
 
 --Qian
I thought that std.date.getUTCtime(), std.date.UTCtoLocalTime() and std.date.LocalTimetoUTC() were quite enough.
Jan 13 2009
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Sergey Gromov wrote:
<snip>
 I thought that std.date.getUTCtime(), std.date.UTCtoLocalTime() and
 std.date.LocalTimetoUTC() were quite enough.
std.date is somewhat badly designed - a time can be in any time zone but has no time zone information in it. And toString(d_time) expects a UTC time but formats in the user's time zone. My library stores all times in UTC, but allows them to be manipulated in any time zone. But it doesn't yet support daylight saving time adjustments. I haven't quite worked out how best to do this. (It initialises the working time zone to the user's current time zone under Windows, but that's it at the moment.) http://pr.stewartsplace.org.uk/d/sutil/ Stewart.
Jan 13 2009
parent Qian Xu <quian.xu stud.tu-ilmenau.de> writes:
Stewart Gordon wrote:
 My library stores all times in UTC, but allows them to be manipulated in
 any time zone.  But it doesn't yet support daylight saving time
 adjustments.  I haven't quite worked out how best to do this.  (It
 initialises the working time zone to the user's current time zone under
 Windows, but that's it at the moment.)
 
Thanks Stewart, this is a great library. However the daylight saving problem is a big issue. I think it would be easier to use an external library from other programming language (ie. PHP), instead of implementing the own one for D. (But I do not know how) --Qian
Jan 14 2009
prev sibling parent reply Kagamin <spam here.lot> writes:
Qian Xu Wrote:

 Hi All,
 
 I am fighting with date time conversion and have a problem right now:
 I want to convert a local timestamp to UTC timestamp.
 So I have to get the time zone information.
 However in some countries (ie. German, US), the offset is not constant,
 because of daylight saving issue.
Even windows doesn't have this kind of heuristics. The only solution is to keep all timestamps in UTC and leave local time representation only for user eyes and don't care about its precision. See also http://www.codeproject.com/KB/datetime/dstbugs.aspx
Jan 14 2009
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Kagamin wrote:
<snip>
 Even windows doesn't have this kind of heuristics. The only solution
 is to keep all timestamps in UTC and leave local time representation
 only for user eyes and don't care about its precision.
That's the best thing indeed for timestamps and the like. For some other kinds of applications, different methodologies'll be needed.
 See also
 http://www.codeproject.com/KB/datetime/dstbugs.aspx
The bugs pertaining to that page are probably as bad as the bug it tries to describe. But I wonder: Is there any sensible way that M$ could eventually paint itself out of this corner? Stewart.
Jan 14 2009