diff --git a/src/Bot.cs b/src/Bot.cs
index 84d9c397..d20b521a 100644
--- a/src/Bot.cs
+++ b/src/Bot.cs
@@ -27,10 +27,8 @@
using DSharpPlus.Interactivity;
// TODO: Subscriptions, Pokemon, Raid, Quest, Invasion, Gym, Weather alarm statistics by day. date/pokemonId/count
- // TODO: Specific timezone per Discord
// TODO: Account status alarms
// TODO: List all subscriptions with info command
- // TODO: Manage subscriptions via DM again
// TODO: Multiple discord bot tokens per server
// TODO: Only start database migrator if subscriptions are enabled
// TODO: Check nests again
diff --git a/src/Extensions/DateTimeExtensions.cs b/src/Extensions/DateTimeExtensions.cs
index 38f98990..463f1d1d 100644
--- a/src/Extensions/DateTimeExtensions.cs
+++ b/src/Extensions/DateTimeExtensions.cs
@@ -2,6 +2,9 @@
{
using System;
+ using GeoTimeZone;
+ using TimeZoneConverter;
+
public static class DateTimeExtensions
{
public static TimeSpan GetTimeRemaining(this DateTime endTime)
@@ -37,5 +40,18 @@ public static DateTime ConvertTime(this DateTime timeUtc, string timeZoneId = "P
}
return timeUtc;
}
+
+ public static DateTime ConvertTimeFromCoordinates(this DateTime date, double lat, double lon)
+ {
+ var tzIana = TimeZoneLookup.GetTimeZone(lat, lon).Result;
+#if Windows
+ // Convert to Windows acceptable TimeZone
+ tzIana = TZConvert.IanaToWindows(tzIana);
+#endif
+ var tzInfo = TimeZoneInfo.FindSystemTimeZoneById(tzIana);
+ var dt = DateTime.SpecifyKind(date, DateTimeKind.Utc);
+ var convertedTime = TimeZoneInfo.ConvertTimeFromUtc(dt, tzInfo);
+ return convertedTime;
+ }
}
}
\ No newline at end of file
diff --git a/src/Extensions/IntegerExtensions.cs b/src/Extensions/IntegerExtensions.cs
index b7359c88..cf730f26 100644
--- a/src/Extensions/IntegerExtensions.cs
+++ b/src/Extensions/IntegerExtensions.cs
@@ -14,7 +14,7 @@ public static char NumberToAlphabet(this int num)
public static DateTime FromUnix(this long unixSeconds)
{
var epochTime = new DateTime(1970,1,1,0,0,0,0,DateTimeKind.Utc);
- var localDateTime = epochTime.AddSeconds(unixSeconds).ToLocalTime();
+ var localDateTime = epochTime.AddSeconds(unixSeconds);//.ToLocalTime();
return localDateTime;
}
diff --git a/src/Net/Models/PokemonData.cs b/src/Net/Models/PokemonData.cs
index d276ff3d..c7e7bb85 100644
--- a/src/Net/Models/PokemonData.cs
+++ b/src/Net/Models/PokemonData.cs
@@ -376,13 +376,18 @@ public PokemonData()
///
public void SetDespawnTime()
{
- DespawnTime = DisappearTime.FromUnix();
+ DespawnTime = DisappearTime.FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
- SecondsLeft = DespawnTime.Subtract(DateTime.Now);
+ SecondsLeft = DespawnTime.Subtract(DateTime.Now.ConvertTimeFromCoordinates(Latitude, Longitude));
- FirstSeenTime = FirstSeen.FromUnix();
+ FirstSeenTime = FirstSeen
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
- LastModifiedTime = LastModified.FromUnix();
+ LastModifiedTime = LastModified
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
}
///
diff --git a/src/Net/Models/PokestopData.cs b/src/Net/Models/PokestopData.cs
index ea78a15d..73568f18 100644
--- a/src/Net/Models/PokestopData.cs
+++ b/src/Net/Models/PokestopData.cs
@@ -97,9 +97,13 @@ public PokestopData()
///
public void SetTimes()
{
- LureExpireTime = LureExpire.FromUnix();
+ LureExpireTime = LureExpire
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
- InvasionExpireTime = IncidentExpire.FromUnix();
+ InvasionExpireTime = IncidentExpire
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
}
public DiscordEmbedNotification GeneratePokestopMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
diff --git a/src/Net/Models/RaidData.cs b/src/Net/Models/RaidData.cs
index d0c534f1..471a2322 100644
--- a/src/Net/Models/RaidData.cs
+++ b/src/Net/Models/RaidData.cs
@@ -127,9 +127,13 @@ public RaidData()
///
public void SetTimes()
{
- StartTime = Start.FromUnix();
+ StartTime = Start
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
- EndTime = End.FromUnix();
+ EndTime = End
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
}
///
diff --git a/src/Net/Models/WeatherData.cs b/src/Net/Models/WeatherData.cs
index a50a7cd0..5aa115b6 100644
--- a/src/Net/Models/WeatherData.cs
+++ b/src/Net/Models/WeatherData.cs
@@ -102,11 +102,9 @@ public WeatherData()
public void SetTimes()
{
- UpdatedTime = Updated.FromUnix();
- //if (TimeZoneInfo.Local.IsDaylightSavingTime(Updated))
- //{
- // UpdatedTime = UpdatedTime.AddHours(1);
- //}
+ UpdatedTime = Updated
+ .FromUnix()
+ .ConvertTimeFromCoordinates(Latitude, Longitude);
}
public DiscordEmbedNotification GenerateWeatherMessage(ulong guildId, DiscordClient client, WhConfig whConfig, AlarmObject alarm, string city)
diff --git a/src/Net/Webhooks/WebhookController.cs b/src/Net/Webhooks/WebhookController.cs
index c78c3ade..a38ae9c3 100644
--- a/src/Net/Webhooks/WebhookController.cs
+++ b/src/Net/Webhooks/WebhookController.cs
@@ -225,7 +225,7 @@ public WebhookController(WhConfig config)
private void Http_PokemonReceived(object sender, DataReceivedEventArgs e)
{
var pkmn = e.Data;
- if (DateTime.Now > pkmn.DespawnTime)
+ if (DateTime.Now.ConvertTimeFromCoordinates(pkmn.Latitude, pkmn.Longitude) > pkmn.DespawnTime)
{
_logger.Debug($"Pokemon {pkmn.Id} already despawned at {pkmn.DespawnTime}");
return;
@@ -251,7 +251,7 @@ private void Http_PokemonReceived(object sender, DataReceivedEventArgs e)
{
var raid = e.Data;
- if (DateTime.Now > raid.EndTime)
+ if (DateTime.Now.ConvertTimeFromCoordinates(raid.Latitude, raid.Longitude) > raid.EndTime)
{
_logger.Debug($"Raid boss {raid.PokemonId} already despawned at {raid.EndTime}");
return;
diff --git a/src/Program.cs b/src/Program.cs
index 36004fb4..02d30c7d 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -5,6 +5,7 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
+
using WhMgr.Diagnostics;
class Program
diff --git a/src/Utilities/Utils.cs b/src/Utilities/Utils.cs
index 32cb376b..03ae81c2 100644
--- a/src/Utilities/Utils.cs
+++ b/src/Utilities/Utils.cs
@@ -37,7 +37,7 @@ public static string GetStaticMapsUrl(string templateFileName, string staticMapU
quest_reward_img_url = markerImageUrl,
weather_img_url = markerImageUrl,
tilemaps_url = staticMapUrl
- }); ;
+ });
StaticMapConfig staticMap = JsonConvert.DeserializeObject(staticMapData);
var url = string.Format(staticMapUrl, latitude, longitude, staticMapZoom);
diff --git a/src/WhMgr.csproj b/src/WhMgr.csproj
index d3dff53b..98fb4d31 100644
--- a/src/WhMgr.csproj
+++ b/src/WhMgr.csproj
@@ -33,11 +33,13 @@
+
-
-
+
+
+