diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2019-07-19 21:24:56 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2021-12-16 22:35:44 +0100 |
commit | 493fe066f6b107a9f356d693c5d37d878d3a63eb (patch) | |
tree | 3039d6c3a031f716a6a8f369181a92828380df63 /src/common/Utilities/Util.cpp | |
parent | 53c41b28216dd75309ea918e9c8a5387a7a2cf5d (diff) |
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)
Diffstat (limited to 'src/common/Utilities/Util.cpp')
-rw-r--r-- | src/common/Utilities/Util.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
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; |