Skip to content

Commit

Permalink
Using localtime instead of localtime_s. The problem is, that localtim…
Browse files Browse the repository at this point in the history
…e_s isn't properly defined across all platforms.
  • Loading branch information
Brotcrunsher committed Nov 24, 2023
1 parent 9b91c81 commit 05d55cd
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions BrotBoxEngine/BrotTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
::tm bbe::TimePoint::toTm() const
{
std::time_t nowT = std::chrono::system_clock::to_time_t(m_time);
::tm retVal;
::localtime_s(&retVal, &nowT);
::tm retVal = *localtime(&nowT);
return retVal;
}

Expand Down Expand Up @@ -83,14 +82,13 @@ bbe::TimePoint bbe::TimePoint::fromDate(int32_t year, Month month, int32_t day,
bbe::TimePoint bbe::TimePoint::nextMorning(int64_t morningHour) const
{
std::time_t t = std::chrono::system_clock::to_time_t(m_time);
::tm timeinfo;
::localtime_s(&timeinfo, &t);
::tm timeinfo = *localtime(&t);
if (timeinfo.tm_hour >= morningHour)
{
bbe::TimePoint nextDay(m_time);
nextDay = nextDay.plusDays(1);
t = std::chrono::system_clock::to_time_t(nextDay.m_time);
::localtime_s(&timeinfo, &t);
timeinfo = *localtime(&t);
}
timeinfo.tm_sec = 0;
timeinfo.tm_min = 0;
Expand Down Expand Up @@ -158,8 +156,7 @@ bool bbe::TimePoint::hasPassed() const
bool bbe::TimePoint::isNight(int64_t fromHour, int64_t toHour) const
{
std::time_t t = std::chrono::system_clock::to_time_t(m_time);
::tm timeinfo;
::localtime_s(&timeinfo, &t);
::tm timeinfo = *localtime(&t);

if (fromHour < toHour)
{
Expand All @@ -174,8 +171,7 @@ bool bbe::TimePoint::isNight(int64_t fromHour, int64_t toHour) const
bool bbe::TimePoint::isSunday() const
{
std::time_t t = std::chrono::system_clock::to_time_t(m_time);
::tm timeinfo;
::localtime_s(&timeinfo, &t);
::tm timeinfo = *localtime(&t);
return timeinfo.tm_wday == 0;
}

Expand Down

0 comments on commit 05d55cd

Please sign in to comment.