diff --git a/repertory/librepertory/src/providers/s3/s3_provider.cpp b/repertory/librepertory/src/providers/s3/s3_provider.cpp index 0d8faaed..aedad862 100644 --- a/repertory/librepertory/src/providers/s3/s3_provider.cpp +++ b/repertory/librepertory/src/providers/s3/s3_provider.cpp @@ -78,12 +78,11 @@ auto s3_provider::convert_api_date(std::string_view date) -> std::uint64_t { return nanos + utils::time::windows_time_t_to_unix_time(mktime(&tm1)); #else // !defined(_WIN32) strptime(date_time.c_str(), "%Y-%m-%dT%T", &tm1); + auto utc_time = timegm(&tm1); - auto *utc_tm = localtime(&utc_time); - if (utc_tm != nullptr) { - } - return nanos + (static_cast(mktime(&tm1)) * - utils::time::NANOS_PER_SECOND); + return nanos + + (static_cast(mktime(localtime_r(&utc_time, &tm1))) * + utils::time::NANOS_PER_SECOND); #endif // defined(_WIN32) } diff --git a/repertory/repertory_test/src/utils_test.cpp b/repertory/repertory_test/src/utils_test.cpp index dc452094..73e83f6a 100644 --- a/repertory/repertory_test/src/utils_test.cpp +++ b/repertory/repertory_test/src/utils_test.cpp @@ -23,6 +23,7 @@ #include "providers/s3/s3_provider.hpp" #include "utils/file.hpp" +#include namespace repertory { TEST(utils, convert_api_date) { @@ -42,10 +43,18 @@ TEST(utils, convert_api_date) { EXPECT_EQ(30, st.wSecond); EXPECT_EQ(111, st.wMilliseconds); #else // !defined(_WIN32) - auto unix_time = s3_provider::convert_api_date("2009-10-12T17:50:30.111Z"); - auto *tm_data = gmtime(&unix_time); + auto unix_time = s3_provider::convert_api_date("2009-10-12T17:50:30.111Z") / + utils::time::NANOS_PER_SECOND; + auto *tm_data = gmtime(reinterpret_cast(&unix_time)); EXPECT_TRUE(tm_data != nullptr); if (tm_data != nullptr) { + EXPECT_EQ(2009, tm_data->tm_year + 1900); + EXPECT_EQ(10, tm_data->tm_mon + 1); + EXPECT_EQ(12, tm_data->tm_mday); + + EXPECT_EQ(17, tm_data->tm_hour); + EXPECT_EQ(50, tm_data->tm_min); + EXPECT_EQ(30, tm_data->tm_sec); } #endif // defined(_WIN32) }