fix liunx
All checks were successful
BlockStorage/repertory/pipeline/head This commit looks good

This commit is contained in:
Scott E. Graves 2024-09-26 20:17:03 -05:00
parent 3dc16db278
commit cbebcfae82
2 changed files with 15 additions and 7 deletions

View File

@ -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<std::uint64_t>(mktime(&tm1)) *
utils::time::NANOS_PER_SECOND);
return nanos +
(static_cast<std::uint64_t>(mktime(localtime_r(&utc_time, &tm1))) *
utils::time::NANOS_PER_SECOND);
#endif // defined(_WIN32)
}

View File

@ -23,6 +23,7 @@
#include "providers/s3/s3_provider.hpp"
#include "utils/file.hpp"
#include <utils/time.hpp>
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<time_t *>(&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)
}