[libcxx-dev] Possible bug in std::get_time and std::chrono::system_clock::from_time_t

Jonas Nilsson via libcxx-dev libcxx-dev at lists.llvm.org
Thu Nov 21 05:50:02 PST 2019


Hi,

I have a problem that I was unable to find anything on in LLVM Bugzilla. Consider this code:

auto stringToTime(std::string const & TimeString) {
  std::tm t;
  std::istringstream InSS(TimeString);
  InSS >> std::get_time(&t, "%Y-%m-%d %T");
  auto Temp = std::mktime(&t);
  std::cout << "Temp: " << Temp << std::endl;
  return std::chrono::system_clock::from_time_t(Temp);
}
int main() {
  stringToTime("1996-02-25 12:13:13");
  stringToTime("1996-02-25 12:13:13”);
  return 0;
}

It produces the following output:
Temp: 825243193
Temp: 825246793

The last timestamp is correct whereas the first timestamp is off by one hour (3600s).

Removing the last line ("return std::chrono::system_clock::from_time_t(Temp);”) makes the two output lines identical (and correct).

I am using MacOSX Mojave 10.14.6 as a development OS. The compiler version string is: "Apple LLVM version 10.0.1 (clang-1001.0.46.4)”. The region (in System preferences) is set to Sweden.

Is this a known issue?

/Jonas


More information about the libcxx-dev mailing list