In the time.h header for the daylight global variable it says: "This variable has a nonzero value if Daylight Saving Time rules apply. A nonzero value does not necessarily mean that Daylight Saving Time is now in effect; it means only that Daylight Saving Time is sometimes in effect."
Now I've noticed that in both Solaris 11.2 and Linux the "daylight" variable is being set to 1, even though my time-zone does not use daylight savings at all (Australia/Brisbane).
Sample code confirms this, if I run tzset and output the global variables we get: daylight = 1 tz[0] = [AEST] tz[1] = [AEDT] timezone = [-36000]
But by my understanding, daylight should be set to 0 since my zone does not have daylight savings at any time during the year.
I also noticed that the struct tm when set to current time returns a tm_isdst = 0, which is correct.
So why is the daylight variable set to 1? Shouldn't it be set to 0? Or am I misinterpreting this?
Code is:
#include <stdio.h>
#include <time.h>
void main()
{
time_t t;
struct tm *tms = { 0 };
tzset();
time(&t);
tms = localtime(&t);
printf("date and time : %s",ctime(&t));
printf("daylight = %d tz[0] = [%s] tz[1] = [%s] timezone = [%ld]\n", daylight, tzname[0], tzname[1], timezone);
printf("tm_isdst = %d\n",tms->tm_isdst);
}
Output is:
date and time : Mon Nov 30 16:41:01 2015
daylight = 1 tz[0] = [AEST] tz[1] = [AEDT] timezone = [-36000]
tm_isdst = 0
Australia/Brisbane doesn't use daylight saving time at the moment, but it has in the past; look at the australasia
file you'll see the few years where it has observed DST.
My interpretation of daylight
is that it indicates whether that time zone has ever observed (or will ever obseve with the current rules) daylight savings. In other words, if this is 1 you need to be careful when performing date/time handling, whereas if it's 0 you can assume a constant UTC offset.
(It's not immediately clear to me whether a time zone which has never observed DST, but has shifted its standard UTC offset over time, would set daylight
to 1 or not. I guess it would be strictly wrong to set it, but it would be practical to do so for the reasons above...)
See more on this question at Stackoverflow