Skip to content

Commit

Permalink
Call tzset() before localtime_r() as the docs say.
Browse files Browse the repository at this point in the history
Without it, one might run the risk of QDateTime::currentDateTime()
returning an invalid QDateTime the first time after changing timezone.

Change-Id: I3efb04d41e7fe4685f6cc5fb41b68424eb4b9eb8
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
sletta authored and The Qt Project committed May 16, 2014
1 parent 102cec7 commit cfcbb95
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/corelib/tools/qdatetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2405,6 +2405,9 @@ static bool qt_localtime(qint64 msecsSinceEpoch, QDate *localDate, QTime *localT
local.tm_year = sysTime.wYear - 1900;
}
#elif !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
// localtime() is required to work as if tzset() was called before it.
// localtime_r() does not have this requirement, so make an explicit call.
qt_tzset();
// Use the reentrant version of localtime() where available
// as is thread-safe and doesn't use a shared static data area
tm *res = 0;
Expand Down

0 comments on commit cfcbb95

Please sign in to comment.