Skip to content

Commit 24f5964

Browse files
committed
Fixed annual week and day period logic.
1 parent 1a07fd2 commit 24f5964

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Dates should be in`YYYY-MM-DD` format and versions are in [semantic versioning](
99

1010
- Updated minor dependencies.
1111
- Updated to `write-excel-file` 3.0.
12+
- Fixed annual week and day period logic.
1213

1314
## v0.8.7 2026-02-08
1415

src/database/Period.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ test.each([
1313
[new Date(2024, 0, 18), { type: 'monthly-weekday', week: 3, day: 3 }, new Date(2024, 1, 21)],
1414
[new Date(2024, 0, 1), { type: 'weekly', weeks: 1, day: 7 }, new Date(2024, 0, 7)],
1515
[new Date(2024, 0, 8), { type: 'weekly', weeks: 1, day: 7 }, new Date(2024, 0, 14)]
16-
] as [Date, Period, Date][])(
16+
] satisfies [Date, Period, Date][])(
1717
'%s + %s should be %s',
1818
(now: Date, period: Period, expected: Date) => {
1919
expect(getNextPeriodDate(now.getTime(), period).getTime() === expected.getTime()).toBe(true);

src/database/Period.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { ProcessRow } from './Organization';
33

44
/** e.g., Every March 1st. Month 1-12, date 1-31 */
55
export type AnnualDate = { type: 'annually-date'; month: number; date: number };
6-
/** e.g., Every 13th week on Monday. Week 1-52, day 1-7 */
6+
/** e.g., Every 13th week on Monday. Week 1-52, day 1-7, starting Monday. */
77
export type AnnuallyWeek = { type: 'annually-week'; week: number; day: number };
88
/** e.g., Every 1st of the month. Day 1-31 */
99
export type MonthlyDate = { type: 'monthly-date'; day: number };
@@ -30,8 +30,12 @@ export function getNextPeriodDate(timestamp: number, period: Period): Date {
3030
do {
3131
const yearWeek = getWeek(nextDate, { weekStartsOn: 1 });
3232
const weekDay = getDay(nextDate);
33-
// Note that the day of weeks in the library starts at 0 on Sunday, but we number starting on Monday at 1, so no conversion is needed.
34-
if (yearWeek === period.week && weekDay === period.day - 1) break;
33+
// Note that the day of weeks in the library starts at 0 on Sunday, but we number starting on Monday at 1, so no conversion is needed, aside from Sunday.
34+
if (
35+
yearWeek === period.week &&
36+
((period.day === 7 && weekDay === 0) || weekDay === period.day)
37+
)
38+
break;
3539
else nextDate = addDays(nextDate, 1);
3640
} while (nextDate);
3741
return nextDate;

test-results/.last-run.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"status": "passed",
2+
"status": "interrupted",
33
"failedTests": []
44
}

0 commit comments

Comments
 (0)