From 6b4bb3259163bdcdf015b97e6b2de230441c6e40 Mon Sep 17 00:00:00 2001 From: GianniKoch Date: Sat, 13 Apr 2024 19:07:16 +0200 Subject: [PATCH] =?UTF-8?q?Use=20TZ=20timezone=20instead=20of=20whatever?= =?UTF-8?q?=20I=20did=20=F0=9F=98=85=20Ty=20Eris=20=F0=9F=98=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-compose.yml | 1 + .../POI.DiscordDotNet/Jobs/BirthdayGirlsJob.cs | 18 ++---------------- source/POI.DiscordDotNet/Program.cs | 14 +------------- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b2f8a331..cb7a198d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,6 +12,7 @@ services: - Discord:Prefix=$DiscordPrefix - Discord:Token=$DiscordToken - Paths:DataFolderPath=/var/lib/poi/data + - TZ=$TZ postgres: image: postgres:16-alpine ports: diff --git a/source/POI.DiscordDotNet/Jobs/BirthdayGirlsJob.cs b/source/POI.DiscordDotNet/Jobs/BirthdayGirlsJob.cs index e485a823..08dee849 100644 --- a/source/POI.DiscordDotNet/Jobs/BirthdayGirlsJob.cs +++ b/source/POI.DiscordDotNet/Jobs/BirthdayGirlsJob.cs @@ -1,5 +1,4 @@ -using System.Runtime.InteropServices; -using DSharpPlus.Entities; +using DSharpPlus.Entities; using JetBrains.Annotations; using Microsoft.Extensions.Logging; using NodaTime; @@ -35,20 +34,7 @@ public async Task Execute(IJobExecutionContext context) return; } - var timeZoneId = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Romance Standard Time" : "Europe/Brussels"; - TimeZoneInfo? belgiumTimeZone; - try - { - belgiumTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); - } - catch (TimeZoneNotFoundException) - { - _logger.LogError("Timezone {TimeZoneId} not found on this system", timeZoneId); - throw; - } - - var localDate = LocalDate.FromDateTime(TimeZoneInfo.ConvertTimeFromUtc(context.ScheduledFireTimeUtc?.LocalDateTime ?? DateTime.Today, belgiumTimeZone)); - //var localDate = LocalDate.FromDateTime(context.ScheduledFireTimeUtc?.LocalDateTime ?? DateTime.Today); + var localDate = LocalDate.FromDateTime(context.ScheduledFireTimeUtc?.LocalDateTime ?? DateTime.Today); _logger.LogInformation("Looking up birthday party people using date: {Date}", localDate.ToString()); var currentBirthdayPartyPeople = await _globalUserSettingsRepository.GetAllBirthdayGirls(localDate.Day, localDate.Month); diff --git a/source/POI.DiscordDotNet/Program.cs b/source/POI.DiscordDotNet/Program.cs index 33fddd06..d5662a77 100644 --- a/source/POI.DiscordDotNet/Program.cs +++ b/source/POI.DiscordDotNet/Program.cs @@ -115,24 +115,12 @@ tp.MaxConcurrency = 5; }); - var timeZoneId = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "Romance Standard Time" : "Europe/Brussels"; - TimeZoneInfo? belgiumTimeZone; - try - { - belgiumTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId); - } - catch (TimeZoneNotFoundException) - { - Log.Error("Timezone {TimeZoneId} not found on this system", timeZoneId); - throw; - } - q.ScheduleJob(trigger => trigger .WithIdentity("RankUpFeed Trigger") .WithSchedule(CronScheduleBuilder.CronSchedule("0 0/5 * * * ?"))); q.ScheduleJob(trigger => trigger .WithIdentity("Birthday Girl trigger") - .WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 0).InTimeZone(belgiumTimeZone))); + .WithCronSchedule(CronScheduleBuilder.DailyAtHourAndMinute(0, 0))); }) .AddQuartzHostedService(options => {