From 1bb3a79b54a3e0339b25836a488ceb155c95a33e Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 18 Jun 2022 17:39:24 -0400 Subject: [PATCH] Core/Calendar: Improve calendar timezone handling Port From (https://github.com/TrinityCore/TrinityCore/commit/5600316c9f69d2afda82ae0e632715b420dfd402) --- Source/Framework/Util/Time.cs | 5 +++++ Source/Game/Handlers/CalendarHandler.cs | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Source/Framework/Util/Time.cs b/Source/Framework/Util/Time.cs index b7b153f9b..a9fea5e5f 100644 --- a/Source/Framework/Util/Time.cs +++ b/Source/Framework/Util/Time.cs @@ -141,6 +141,11 @@ public static class Time return hourLocal; } + public static long LocalTimeToUTCTime(long time) + { + return DateTimeToUnixTime(UnixTimeToDateTime(time).ToUniversalTime()); + } + public static string secsToTimeString(ulong timeInSecs, TimeFormat timeFormat = TimeFormat.FullText, bool hoursOnly = false) { ulong secs = timeInSecs % Minute; diff --git a/Source/Game/Handlers/CalendarHandler.cs b/Source/Game/Handlers/CalendarHandler.cs index bd3bf35af..c8292febf 100644 --- a/Source/Game/Handlers/CalendarHandler.cs +++ b/Source/Game/Handlers/CalendarHandler.cs @@ -121,6 +121,8 @@ namespace Game { ObjectGuid guid = GetPlayer().GetGUID(); + calendarAddEvent.EventInfo.Time = Time.LocalTimeToUTCTime(calendarAddEvent.EventInfo.Time); + // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarAddEvent.EventInfo.Time < (GameTime.GetGameTime() - 86400L)) @@ -204,6 +206,8 @@ namespace Game ObjectGuid guid = GetPlayer().GetGUID(); long oldEventTime; + calendarUpdateEvent.EventInfo.Time = Time.LocalTimeToUTCTime(calendarUpdateEvent.EventInfo.Time); + // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarUpdateEvent.EventInfo.Time < (GameTime.GetGameTime() - 86400L)) @@ -240,6 +244,8 @@ namespace Game { ObjectGuid guid = GetPlayer().GetGUID(); + calendarCopyEvent.Date = Time.LocalTimeToUTCTime(calendarCopyEvent.Date); + // prevent events in the past // To Do: properly handle timezones and remove the "- time_t(86400L)" hack if (calendarCopyEvent.Date < (GameTime.GetGameTime() - 86400L))