Skip to content

Commit f44c524

Browse files
committed
Fix ISO week calculation in backup rotation policy
Replace manual ISO week calculation with System.Globalization.ISOWeek API. The manual calculation had bugs around year boundaries where thursday.DayOfYear and jan4.DayOfYear could be from different years, causing incorrect week numbers. This fixes the BackupRotationPolicyTests.ApplyRotationAsync_KeepsWeeklyBackups test which was failing when backups crossed year boundaries (Dec 2025 -> Jan 2026).
1 parent 1dda597 commit f44c524

1 file changed

Lines changed: 3 additions & 12 deletions

File tree

LocalizationManager.Core/Backup/BackupRotationPolicy.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -164,18 +164,9 @@ public async Task ApplyRotationAsync(BackupManifest manifest, string backupDir)
164164
/// </summary>
165165
private string GetIsoWeekKey(DateTime date)
166166
{
167-
// ISO 8601 week number
168-
var dayOfWeek = (int)date.DayOfWeek;
169-
var dayOfYear = date.DayOfYear;
170-
171-
// Adjust for ISO 8601: Monday = 1, Sunday = 7
172-
var isoWeekDay = dayOfWeek == 0 ? 7 : dayOfWeek;
173-
174-
// Find the ISO week number
175-
var thursday = date.AddDays(4 - isoWeekDay);
176-
var isoYear = thursday.Year;
177-
var jan4 = new DateTime(isoYear, 1, 4);
178-
var isoWeek = (thursday.DayOfYear - jan4.DayOfYear) / 7 + 1;
167+
// Use built-in ISO 8601 week calculation
168+
var isoYear = System.Globalization.ISOWeek.GetYear(date);
169+
var isoWeek = System.Globalization.ISOWeek.GetWeekOfYear(date);
179170

180171
return $"{isoYear}-W{isoWeek:D2}";
181172
}

0 commit comments

Comments
 (0)