diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2019-07-19 21:24:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-19 21:24:56 +0200 |
commit | aeddd417c460c43d885cb89ceaa6e051c44b1d27 (patch) | |
tree | 589e76b3c39940dec7e8db8240224220d4893090 /src/common/Utilities/Util.cpp | |
parent | fbd0fe26ee239f7cf80004d771b96df3f9ae1274 (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
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 53365373eb4..3b9917611aa 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; |