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

Daylight Saving Time in Formatted Time

Moderators: larsivi kris

Posted: 04/13/09 20:50:10

I have the following code

auto layout=new Locale();

which outputs a string such as "Mon, 13 Apr 2009 21:00:01 GMT".

I presume Tango somehow finds out from the OS that I'm in the UK and thus knows my time zone is normally GMT. Is there a way to take into consideration daylight saving time and thus return "BST" as opposed to "GMT"?

Author Message

Posted: 04/14/09 01:07:11

Looking at the code, it appears that DST should be taken into account for WallClock?. Is this Win32, linux, other?

Posted: 04/14/09 18:58:02

This is with linux and the output from the date command on the terminal is "Tue Apr 14 19:55:23 BST 2009". The formatted output when using WallClock? is correct with the exception of the time zone now being BST as opposed to GMT.

Posted: 04/15/09 05:33:33

I'm no linux expert, but I think I see the problem. Values from WallClock are derived via the global variable timezone (initialized, I think, via a call to tzset). It would seem that value already includes DST, and thus results in BST values instead of GMT (the zone is correct, but the DST should be ignored).

I think this is a limitation of the WallClock module, in that it cannot (or does not have the ability to) distinguish between DST and non-DST periods. One of the things on the list is to implement our own DST calculations, but it hasn't happened yet.

As for the DateFormat: I'm afraid the 'R' specifier is locked (via a standard) to GMT. In this case, the clock value is inappropriate rather than the decoration. Sorry about that. You can always create an equivalent formatting pattern, with "BST" on the end instead of "GMT", and use that in place of the 'R' shorthand notation.

If you know of a way to get the current DST bias from linux, or the timezone without the DST bias, that would help tremendously. The same issue probably exists on other O/S also, although Win32 separates out the components (Win32 has other issues in this arena, instead).

Posted: 04/16/09 19:07:59

After a bit of reading I have found the tzset man page. Here is an extract:

#include <time.h>

       void tzset (void);

       extern char *tzname[2];
       extern long timezone;
       extern int daylight;

       The tzset() function initializes the tzname variable from the TZ  envi-
       ronment  variable.   This function is automatically called by the other
       time conversion functions that depend on the timezone.  In a  System-V-
       like  environment it will also set the variables timezone (seconds West
       of GMT) and daylight (0 if this timezone does  not  have  any  daylight
       saving  time  rules,  non-zero  if there is a time during the year when
       daylight saving time applies).

I wrote the following C test program to test it.

#include <stdio.h>
#include <time.h>

int main(){
        printf("%s %s %d %d\n",tzname[0],tzname[1],timezone,daylight);
        return 0;
//outputs "GMT BST 0 1"

The output is correct for me. The timezone variable would allow the local time without DST bias to be obtained.

I thought having the different timezone codes available would also be quite useful but as you point out this could only be used if WallClock? is modified to take DST into consideration.

From looking at the DateTime? module I gather that the 'R' specifier relates to RFC1123, am I right? I ask because I looked at a document I think was the RFC1123 spec but could find no reference to the time format.