Почему mktime () конвертирует 31/03/2019 с 02:00 в 01:00 с tm.tm_isdst = 1 с часовым поясом CET?
Я думаю, что это недопустимая комбинация.
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void reset(struct tm* tm){
(*tm) = (const struct tm){0};
tm->tm_sec = 0;
tm->tm_min = 1;
tm->tm_hour = 2;
tm->tm_mon = 2;
tm->tm_mday = 31;
tm->tm_year = 2019 - 1900;
}
int main(int argc, char **argv)
{
struct tm tm;
int secs;
reset(&tm);
printf("Before mktime\n");
printf(" %04d-%02d-%02d %02d:%02d:%02d\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec);
tm.tm_isdst = 0;
secs = mktime(&tm);
printf("After mktime tm.tm_isdst = 0;\n");
printf(" %04d-%02d-%02d %02d:%02d:%02d TZ=%s , tm_isdst = %d, timestamp=%i\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_zone, tm.tm_isdst, secs);
reset(&tm);
tm.tm_isdst = 1;
secs = mktime(&tm);
printf("After mktime tm.tm_isdst = 1;\n");
printf(" %04d-%02d-%02d %02d:%02d:%02d TZ=%s , tm_isdst = %d, timestamp=%i\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_zone, tm.tm_isdst, secs);
reset(&tm);
tm.tm_isdst = -1;
secs = mktime(&tm);
printf("After mktime tm.tm_isdst = -1\n");
printf(" %04d-%02d-%02d %02d:%02d:%02d TZ=%s , tm_isdst = %d, timestamp=%i\n", tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_zone, tm.tm_isdst, secs);
return 0;
}
Выход:
% date
Sun Mar 31 06:50:42 CEST 2019
% test_mktime
Before mktime
2019-03-31 02:01:00
After mktime tm.tm_isdst = 0;
2019-03-31 03:01:00 TZ=CEST , tm_isdst = 1, timestamp=1553994060
After mktime tm.tm_isdst = 1;
2019-03-31 01:01:00 TZ=CET , tm_isdst = 0, timestamp=1553990460
After mktime tm.tm_isdst = -1
2019-03-31 03:01:00 TZ=CEST , tm_isdst = 1, timestamp=1553994060