MrWheeliebin
March 8th, 2012, 01:18 PM
Consider the following code, why do the first two printfs differ from the last two? (NB: Requires that you are in the London time zone). Note the times are around the end of DST this year.
Is something global being changed in the system just by calling mktime?
MrWheeliebin
PS: I get the following output
1351386900 isdst flag now 0 (301)
1351390500 isdst flag now 0 (301)
1351379700 isdst flag now 1 (301)
1351383300 isdst flag now 1 (301)
1351390500 isdst flag now 0 (301)
.......
#include <stdio.h>
#include <time.h>
#include <string.h>
void do_time(int hour)
{
time_t utc;
struct tm tp;
memset(&tp,0,sizeof(tp));
/* construct a time on Sunday 29 October 2012 (the day the clocks go back at 2am) */
tp.tm_hour = hour;
tp.tm_min = 15;
tp.tm_sec = 0;
tp.tm_year = 2012 - 1900;
tp.tm_mon = 9;
tp.tm_wday = 0;
tp.tm_mday = 28;
tp.tm_isdst = -1;
utc = mktime( &tp );
printf("%d isdst flag now %d (%d)\n",utc, tp.tm_isdst, tp.tm_yday);
}
int main(int argc, char** argv)
{
/* why do these two time/dates ... */
do_time(1);
do_time(2);
do_time(0);
/* ... produce different time_t dates from these two time/dates? */
do_time(1);
do_time(2);
return 0;
}
Is something global being changed in the system just by calling mktime?
MrWheeliebin
PS: I get the following output
1351386900 isdst flag now 0 (301)
1351390500 isdst flag now 0 (301)
1351379700 isdst flag now 1 (301)
1351383300 isdst flag now 1 (301)
1351390500 isdst flag now 0 (301)
.......
#include <stdio.h>
#include <time.h>
#include <string.h>
void do_time(int hour)
{
time_t utc;
struct tm tp;
memset(&tp,0,sizeof(tp));
/* construct a time on Sunday 29 October 2012 (the day the clocks go back at 2am) */
tp.tm_hour = hour;
tp.tm_min = 15;
tp.tm_sec = 0;
tp.tm_year = 2012 - 1900;
tp.tm_mon = 9;
tp.tm_wday = 0;
tp.tm_mday = 28;
tp.tm_isdst = -1;
utc = mktime( &tp );
printf("%d isdst flag now %d (%d)\n",utc, tp.tm_isdst, tp.tm_yday);
}
int main(int argc, char** argv)
{
/* why do these two time/dates ... */
do_time(1);
do_time(2);
do_time(0);
/* ... produce different time_t dates from these two time/dates? */
do_time(1);
do_time(2);
return 0;
}