The problem of converting date and time if the moment is exactly at the end of winter (non-DST)

In my application, I need to calculate the shifts using the template described in the file. Recently, one of my clients had an application freeze for the following reason:

If you fill in "struct tm" with the exact moment at the end of winter (non-DST), _mktime seems to return the wrong result.

The code is as follows:

struct tm tm_start;
tm_start.tm_mday  = startday;
tm_start.tm_mon   = startmonth-1;
tm_start.tm_year  = startyear-1900;
tm_start.tm_hour  = starthour;
tm_start.tm_min   = startmin;
tm_start.tm_sec   = startsec;
tm_start.tm_isdst = -1;             // Don't know if DST is active at this moment

_int64 contTime = _mktime64(&tm_start);

Suppose that from April 5 at 2:00 there is a transition from winter to summer time. In practice, this means that we have the following points in time:

5 April, 1:58
5 April, 1:59
5 April, 3:00

Since I don’t know in the application when the DST starts or ends (do I really want to know this?) I pass the date "April 5, 2:00" to _mktime64 using the code shown above.

, _mktime64 time_t, 5 , 3:00 ( , 5 , 2:00).

, . _mktime64 tm_start 5 , 1:00 time_t. , . (: 2:00 3:00 _mktime64, 1:00 2:00)

, Visual Studio 2005, , , Visual Studio 2010 (Release Candidate) .

XP, Windows7 ( Vista).

? ?

+3
3

, , , . , , - "1 1:59 ", , , "3:00" DST , . " 3:00 ", , , , , "1:00". , , - undefined , .

, - UTC , . , , !

+2

, UTC. DST doozy, , .

, UTC , . CRT, _gmtime64() GetFileTime().

+3

5 , 2:30 time_t 29 2011 time_t. , . 5 2:00 . 1: 59.59 3:00:00

+1

Source: https://habr.com/ru/post/1735403/


All Articles