[Interest] Relashionship between time_t and QDateTime

Constantin Makshin cmakshin at gmail.com
Tue Aug 27 20:17:07 CEST 2013


In MSVC's runtime library — yes, gmtime() is broken.

From MSDN (http://msdn.microsoft.com/en-us/library/vstudio/0z9czt0w.aspx):
> Return Value
> A pointer to a structure of type tm. The fields of the returned structure hold the evaluated value of the timer argument in UTC rather than in local time. Each of the structure fields is of type int, as follows:
> ...
> tm_isdst
> Always 0 for gmtime.

That's for gmtime(), but the same applies to gmtime_s()
(http://msdn.microsoft.com/en-us/library/vstudio/3stkd9be.aspx) as all
these *_s() functions are simply a result of Microsoft's NIH syndrome
and share the [general] behavior with their standard counterparts.

On 08/27/2013 09:57 PM, Thiago Macieira wrote:
> On terça-feira, 27 de agosto de 2013 21:40:29, Constantin Makshin wrote:
>> When converting time from UTC to local time, Windows uses the *current*
>> state of daylight saving, not one that was active at the time the
>> original timestamp is "pointing" to.
> 
> Hmm... we have two versions of the code: FileTimeToSystemTime and gmtime. Are 
> you saying that gmtime is broken and does not apply the correct historical 
> daylight saving settings?
> 
> #if defined(Q_OS_WINCE)
>     tm res;
>     FILETIME localTime = time_tToFt(secsSince1Jan1970UTC);
>     SYSTEMTIME sysTime;
>     FileTimeToSystemTime(&localTime, &sysTime);
>     FILETIME resultTime;
>     LocalFileTimeToFileTime(&localTime , &resultTime);
>     FileTimeToSystemTime(&resultTime , &sysTime);
>     res.tm_sec = sysTime.wSecond;
>     res.tm_min = sysTime.wMinute;
>     res.tm_hour = sysTime.wHour;
>     res.tm_mday = sysTime.wDay;
>     res.tm_mon = sysTime.wMonth - 1;
>     res.tm_year = sysTime.wYear - 1900;
>     res.tm_isdst = (int)isdst;
>     brokenDown = &res;
> #elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
>     // use the reentrant version of gmtime() where available
>     tm res;
>     brokenDown = gmtime_r(&secsSince1Jan1970UTC, &res);
> #elif defined(_MSC_VER) && _MSC_VER >= 1400
>     tm res;
>     if (!_gmtime64_s(&res, &secsSince1Jan1970UTC))
>         brokenDown = &res;
> #else
>     brokenDown = gmtime(&secsSince1Jan1970UTC);
> #endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130827/7bd4d0aa/attachment.sig>


More information about the Interest mailing list