From 493fe066f6b107a9f356d693c5d37d878d3a63eb Mon Sep 17 00:00:00 2001 From: Giacomo Pozzoni Date: Fri, 19 Jul 2019 21:24:56 +0200 Subject: Core/Misc: Handle timezones for hour-specific events specifieds in worldserver.conf (#23540) * Core/Misc: Handle timezones for hour-specific events specifieds in worldserver.conf * Handle Respawn.RestartQuietTime too * Handle XP.Boost.Daymask too * Core/Misc: Code cleanup * Core/Misc: Code cleanup * Update Util.cpp * Update boosted_xp.cpp (cherry picked from commit aeddd417c460c43d885cb89ceaa6e051c44b1d27) --- src/common/Utilities/Util.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/common/Utilities/Util.cpp') diff --git a/src/common/Utilities/Util.cpp b/src/common/Utilities/Util.cpp index 5123636f6a0..4b8c206c9ff 100644 --- a/src/common/Utilities/Util.cpp +++ b/src/common/Utilities/Util.cpp @@ -77,6 +77,13 @@ struct tm* localtime_r(time_t const* time, struct tm *result) } #endif +tm TimeBreakdown(time_t time) +{ + tm timeLocal; + localtime_r(&time, &timeLocal); + return timeLocal; +} + time_t LocalTimeToUTCTime(time_t time) { #if (defined(WIN32) || defined(_WIN32) || defined(__WIN32__)) @@ -86,6 +93,21 @@ time_t LocalTimeToUTCTime(time_t time) #endif } +time_t GetLocalHourTimestamp(time_t time, uint8 hour, bool onlyAfterTime) +{ + tm timeLocal = TimeBreakdown(time); + timeLocal.tm_hour = 0; + timeLocal.tm_min = 0; + timeLocal.tm_sec = 0; + time_t midnightLocal = mktime(&timeLocal); + time_t hourLocal = midnightLocal + hour * HOUR; + + if (onlyAfterTime && hourLocal < time) + hourLocal += DAY; + + return hourLocal; +} + std::string secsToTimeString(uint64 timeInSecs, bool shortText, bool hoursOnly) { uint64 secs = timeInSecs % MINUTE; -- cgit v1.2.3