Merge topic 'string-TIMESTAMP-unset-TZ'

f23760ffac string(TIMESTAMP): Fix unset TZ

Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Attila Krasznahorkay <attila.krasznahorkay@gmail.com>
Merge-request: !2464
This commit is contained in:
Brad King
2018-10-09 11:42:38 +00:00
committed by Kitware Robot
+11 -1
View File
@@ -96,7 +96,7 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
// From Linux timegm() manpage.
std::string tz_old;
cmSystemTools::GetEnv("TZ", tz_old);
bool const tz_was_set = cmSystemTools::GetEnv("TZ", tz_old);
tz_old = "TZ=" + tz_old;
// The standard says that "TZ=" or "TZ=[UNRECOGNIZED_TZ]" means UTC.
@@ -109,7 +109,17 @@ time_t cmTimestamp::CreateUtcTimeTFromTm(struct tm& tm) const
time_t result = mktime(&tm);
# ifdef CMAKE_BUILD_WITH_CMAKE
if (tz_was_set) {
cmSystemTools::PutEnv(tz_old);
} else {
cmSystemTools::UnsetEnv("TZ");
}
# else
// No UnsetEnv during bootstrap. This is good enough for CMake itself.
cmSystemTools::PutEnv(tz_old);
static_cast<void>(tz_was_set);
# endif
tzset();