Thread overview
D2 phobos std.date question
Jul 08, 2009
Sam Hu
Jul 13, 2009
Stewart Gordon
Jul 14, 2009
Sam Hu
Jul 14, 2009
Stewart Gordon
Jul 15, 2009
Sam Hu
Jul 15, 2009
John C
Jul 16, 2009
Sam Hu
July 08, 2009
Which method/ how can I produce proper result of local datetime? getUTCtime,UTCtoLocalTime,localTimeToUTC all can not produce the proper result.

Could any body help?Thanks.

Regards,
Sam
July 13, 2009
Sam Hu wrote:
> Which method/ how can I produce proper result of local datetime?
> getUTCtime,UTCtoLocalTime,localTimeToUTC all can not produce the proper result.
> 
> Could any body help?Thanks.

Not without seeing your code and knowing what exactly you're trying to do.

Stewart.
July 14, 2009
Stewart Gordon Wrote:

> Sam Hu wrote:
> > Which method/ how can I produce proper result of local datetime? getUTCtime,UTCtoLocalTime,localTimeToUTC all can not produce the proper result.
> > 
> > Could any body help?Thanks.
> 
> Not without seeing your code and knowing what exactly you're trying to do.
> 
> Stewart.
Thank you so much for your attention.Actually my questions are:
1.std.date has no implementation on getting local region system time,is this true?Say getUTCtime(),UTCtoLocalTime() are all 8 hours behind my region;I remembered in Tango  this is not a problem.gtkD provide a clock demo which I have build both under D1+tango and D2,2 exe show different time.The tango one is correct.

2.If I want to get proper system time under D2,I need do by myself,either +8hours hard-codes or call system API by myself,is this the only choice?

Thanks and best regards,
Sam
July 14, 2009
Sam Hu wrote:
> Stewart Gordon Wrote:
<snip>
>> Not without seeing your code and knowing what exactly you're trying
>> to do.
>> 
>> Stewart.
> Thank you so much for your attention.Actually my questions are: 1.std.date has no implementation on getting local region system
> time,is this true?Say getUTCtime(),UTCtoLocalTime() are all 8 hours
> behind my region;I remembered in Tango  this is not a problem.gtkD
> provide a clock demo which I have build both under D1+tango and D2,2
> exe show different time.The tango one is correct.
<snip>

Read the source of std.date and see for yourself.  If it's getting it wrong, it suggests either your system is misconfigured or you're using it wrongly.  But since you still haven't posted your code, I still can't comment further.

Stewart.
July 15, 2009
Stewart Gordon Wrote:

> 
> Read the source of std.date and see for yourself.  If it's getting it wrong, it suggests either your system is misconfigured or you're using it wrongly.  But since you still haven't posted your code, I still can't comment further.
> 
> Stewart.

Thank you so much again.
Actually I just tried the example based on the one inside the std.date source:
/*************************************
 * Converts UTC time into a text string of the form:
 * "Www Mmm dd hh:mm:ss GMT+-TZ yyyy".
 * For example, "Tue Apr 02 02:04:57 GMT-0800 1996".
 * If time is invalid, i.e. is d_time_nan,
 * the string "Invalid date" is returned.
 *
 * Example:
 * ------------------------------------
 */
  d_time lNow;
  string lNowString;//char[] lNowString;

  // Grab the date and time relative to UTC
  lNow = std.date.getUTCtime();
  // Convert this into the local date and time for display.
  lNowString = std.date.toString(lNow);
 /* ------------------------------------
 */
//And add testing below:
d_time localTime=std.date.UTCtoLocalTime(lNow);
string localTimeString=std.date.toString(localTime);

writefln(lNowString);
writefln(localTimeString);

===========
output:
===========
Wed Jul 15 01:47:42 GMT+0000 2009
Wed Jul 15 01:47:42 GMT+0000 2009



July 15, 2009
Sam Hu Wrote:

> Stewart Gordon Wrote:
> 
> > 
> > Read the source of std.date and see for yourself.  If it's getting it wrong, it suggests either your system is misconfigured or you're using it wrongly.  But since you still haven't posted your code, I still can't comment further.
> > 
> > Stewart.
> 
> Thank you so much again.
> Actually I just tried the example based on the one inside the std.date source:
> /*************************************
>  * Converts UTC time into a text string of the form:
>  * "Www Mmm dd hh:mm:ss GMT+-TZ yyyy".
>  * For example, "Tue Apr 02 02:04:57 GMT-0800 1996".
>  * If time is invalid, i.e. is d_time_nan,
>  * the string "Invalid date" is returned.
>  *
>  * Example:
>  * ------------------------------------
>  */
>   d_time lNow;
>   string lNowString;//char[] lNowString;
> 
>   // Grab the date and time relative to UTC
>   lNow = std.date.getUTCtime();
>   // Convert this into the local date and time for display.
>   lNowString = std.date.toString(lNow);
>  /* ------------------------------------
>  */
> //And add testing below:
> d_time localTime=std.date.UTCtoLocalTime(lNow);
> string localTimeString=std.date.toString(localTime);
> 
> writefln(lNowString);
> writefln(localTimeString);
> 
> ===========
> output:
> ===========
> Wed Jul 15 01:47:42 GMT+0000 2009
> Wed Jul 15 01:47:42 GMT+0000 2009
> 
> 
> 

There's a bug in Phobos where the value used to calculate timezone offsets (localTZA) never gets initialised, because std_date_static_this() is not called.

A temporary fix is to import std.datebase.

John.
July 16, 2009
John C Wrote:

> > 
> 
> There's a bug in Phobos where the value used to calculate timezone offsets (localTZA) never gets initialised, because std_date_static_this() is not called.
> 
> A temporary fix is to import std.datebase.
> 
> John.

Thank you so much John!!

You help me solved the problem,but what's more important you remind me that I should have found the clue by myself also.Acutally when I test the code,I have also print the value of localTZA,it is zero;I hard-corded localTZA=8 at startup,but after call getUTCtime,it changed back to zero.It is so clear a clue but I just let it go...