COleDateTime adding an hour when constructed with time_t

416 views Asked by At

I have a struct tm object that is converted to UNIX time_t using mktime, that when passed into the constructor of COleDateTime seems to be adding an hour to account for daylight savings (UK time), even though the documentation for COleDateTime suggests that it ignores DST.

If I create my time with SYSTEMTIME and pass that object to COleDateTime the problem disappears. Does anyone have any idea why this might be happening? This is from legacy code so changing everything to SYSTEMTIME may not be a solution.

Here is my example code:

timeinfo.tm_year = 2018 - 1900;
timeinfo.tm_mon = 6 - 1;
timeinfo.tm_mday = 1;
timeinfo.tm_isdst = 0;
timeinfo.tm_hour = 10;
timeinfo.tm_min = 30;
timeinfo.tm_sec = 40;

auto unix = mktime( &timeinfo );
printf("UNIX time %lld\n", unix);
COleDateTime date(unix);
printf("COleDateTime: %f\n", date.m_dt);
CString res = date.Format();
printf("Formatted: %ls\n", res.GetString());
1

There are 1 answers

0
Jack K On BEST ANSWER

Answered my own question:

COleDateTime time_t constructor uses CTime internally which, regardless of what the documentation for COleDateTime says, does take into account the environment variables for locale and timezone.