case 4755 - automatic backup no longer skips a day after a restart or a manual backup
SetNextBackup counted "tomorrow" from the day the server started, using the newest backup file as the last backup, so a restart between midnight and the backup time (every Thursday reboot), a manual backup, or a backup finishing after midnight skipped a day. The next backup is now simply the next time the backup time comes round on the server's clock. A time that happens twice when the clocks go back runs at the first one only. Tested with a minute-by-minute simulation over both daylight saving changes (one backup every day; the old code skipped days) and on the local server. Changelog line; two Deferred entries (dead inputs, safe headers missing on handler 500s). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -65,20 +65,12 @@ namespace AyaNova.Util
|
||||
DateTime utcNow = DateTime.UtcNow;
|
||||
//case 4682: the backup time is a time on the server's clock; days are the server's local days
|
||||
DateTime localToday = TimeZoneInfo.ConvertTimeFromUtc(utcNow, TimeZoneInfo.Local).Date;
|
||||
//Has last backup run more than 24 hours ago?
|
||||
if (NextBackup < utcNow.AddHours(-24))
|
||||
{
|
||||
//set it to today then
|
||||
NextBackup = BackupTimeOnLocalDay(localToday);
|
||||
//Make sure next backup is in the future
|
||||
if (NextBackup < utcNow)
|
||||
NextBackup = BackupTimeOnLocalDay(localToday.AddDays(1));
|
||||
}
|
||||
else
|
||||
{
|
||||
//less than 24 hours, set it to tomorrow
|
||||
//case 4755: the next backup is the next time the backup time comes round on the server's clock: today's if it is
|
||||
//still ahead, otherwise tomorrow's. It no longer counts from the last backup, which skipped a night after a restart
|
||||
//between midnight and the backup time, or after a manual backup
|
||||
NextBackup = BackupTimeOnLocalDay(localToday);
|
||||
if (NextBackup <= utcNow)
|
||||
NextBackup = BackupTimeOnLocalDay(localToday.AddDays(1));
|
||||
}
|
||||
}
|
||||
|
||||
//case 4682: the backup time is stored as the UTC moment it meant on the day it was set, and was run at that UTC hour
|
||||
@@ -91,6 +83,9 @@ namespace AyaNova.Util
|
||||
//a time skipped when the clocks go forward (e.g. 2:30 AM that night) runs an hour later
|
||||
if (TimeZoneInfo.Local.IsInvalidTime(local))
|
||||
local = local.AddHours(1);
|
||||
//case 4755: a time that happens twice when the clocks go back (e.g. 1:30 AM that night) runs at the first one only
|
||||
if (TimeZoneInfo.Local.IsAmbiguousTime(local))
|
||||
return new DateTimeOffset(local, TimeZoneInfo.Local.GetAmbiguousTimeOffsets(local).Max()).UtcDateTime;
|
||||
return TimeZoneInfo.ConvertTimeToUtc(local, TimeZoneInfo.Local);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user