Skip to content

Commit

Permalink
Some minor fixes after the time string refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuscu committed Aug 19, 2024
1 parent 47ae130 commit df5b56b
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions packages/logging/source/common/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ namespace string {
int32_t to_unix_time(int year, int month, int day, int hour, int min, int sec) {
struct tm timeinfo = {};

timeinfo.tm_year = year - 1900;
timeinfo.tm_mon = month - 1; //months since January - [0,11]
timeinfo.tm_year = year;
timeinfo.tm_mon = month; //months since January - [0,11]
timeinfo.tm_mday = day; //day of the month - [1,31]
timeinfo.tm_hour = hour; //hours since midnight - [0,23]
timeinfo.tm_min = min; //minutes after the hour - [0,59]
timeinfo.tm_sec = sec; //seconds after the minute - [0,59]

// use gmtime for gmt/utc time, use it when local time zone is unknown, for example in storage
// use mktime for local time zone presentation
return static_cast<int32_t>(convert_to_time(&timeinfo));
bool adjustYearAndMonth = timeinfo.tm_year > 1000 ? true : false;
return static_cast<int32_t>(convert_to_time(&timeinfo, adjustYearAndMonth));
}

int32_t to_unix_time(std::string_view date) {
Expand Down Expand Up @@ -177,13 +178,10 @@ namespace string {
ASSERT(ret <= 3);
}


timeinfo.tm_year -= 1900;
timeinfo.tm_mon -= 1;

// use _mkgmtime for gmt/utc time, use it when local time zone is unknown, for example in storage
// use mktime for local time zone presentation
return static_cast<int32_t>(convert_to_time(&timeinfo));
bool adjustYearAndMonth = timeinfo.tm_year > 1000 ? true : false;
return static_cast<int32_t>(convert_to_time(&timeinfo, adjustYearAndMonth));
}

int32_t to_unix_time2(std::string_view date) {
Expand All @@ -203,12 +201,10 @@ namespace string {

ASSERT(ret <= 7);

timeinfo.tm_year -= 1900;
timeinfo.tm_mon -= 1;

// use _mkgmtime for gmt/utc time, use it when local time zone is unknown, for example in storage
// use mktime for local time zone presentation
return static_cast<int32_t>(convert_to_time(&timeinfo));
bool adjustYearAndMonth = timeinfo.tm_year > 1000 ? true : false;
return static_cast<int32_t>(convert_to_time(&timeinfo, adjustYearAndMonth));
}

int32_t to_unix_time_from_local(const int32_t* dateAndTime) {
Expand Down

0 comments on commit df5b56b

Please sign in to comment.