From 3be6f2b3886585153b77869a4a1accc0c2a07b35 Mon Sep 17 00:00:00 2001 From: myangelkamikaze Date: Wed, 8 May 2019 11:45:30 +0900 Subject: [PATCH] temp DST fix --- .../Resource/Record/ResourceRecord.cs | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/ElectronicObserver/Resource/Record/ResourceRecord.cs b/ElectronicObserver/Resource/Record/ResourceRecord.cs index 4f4595f6e..c42f0b6fd 100644 --- a/ElectronicObserver/Resource/Record/ResourceRecord.cs +++ b/ElectronicObserver/Resource/Record/ResourceRecord.cs @@ -239,8 +239,11 @@ public ResourceElement GetRecord(DateTime target) /// public ResourceElement GetRecordPrevious() { + DateTime now = DateTime.Now; + bool isDst = TimeZoneInfo.Local.IsDaylightSavingTime(now); + + now = DateTime.UtcNow + new TimeSpan(9, 0, 0); - DateTime now = DateTime.UtcNow + new TimeSpan(9, 0, 0); DateTime target; if (now.TimeOfDay.Hours < 2) { @@ -255,7 +258,10 @@ public ResourceElement GetRecordPrevious() target = new DateTime(now.Year, now.Month, now.Day, 14, 0, 0); } - return GetRecord(target.Add(DateTimeHelper.GetTimeDifference())); + if(isDst) + target += new TimeSpan(1, 0, 0); + + return GetRecord(target.Add(DateTimeHelper.GetTimeDifference())); } /// @@ -263,9 +269,12 @@ public ResourceElement GetRecordPrevious() /// public ResourceElement GetRecordDay() { + DateTime now = DateTime.Now; + bool isDst = TimeZoneInfo.Local.IsDaylightSavingTime(now); - DateTime now = DateTime.UtcNow + new TimeSpan(9, 0, 0); - DateTime target; + now = DateTime.UtcNow + new TimeSpan(9, 0, 0); + + DateTime target; if (now.TimeOfDay.Hours < 2) { target = new DateTime(now.Year, now.Month, now.Day, 2, 0, 0).Subtract(TimeSpan.FromDays(1)); @@ -275,9 +284,13 @@ public ResourceElement GetRecordDay() target = new DateTime(now.Year, now.Month, now.Day, 2, 0, 0); } - return GetRecord(target.Add(DateTimeHelper.GetTimeDifference())); + if (isDst) + target += new TimeSpan(1, 0, 0); + + return GetRecord(target.Add(DateTimeHelper.GetTimeDifference())); } + /// /// 今月の戦果更新以降の最も古い記録を返します。 ///