fix(planning): plan TIME_WINDOW rules on the picked calendar dates
CI / policy (pull_request) Failing after 11s
CI / validate (pull_request) Successful in 27s
CI / build (pull_request) Successful in 43s
CI / benchmark (pull_request) Successful in 1m12s
CI / security (pull_request) Successful in 1m6s
CI / test (pull_request) Successful in 1m52s
CI / images (pull_request) Skipped
CI / required (pull_request) Failing after 1s

Rule windows reached the planner as local-midnight Date objects, and the
planner read their Europe/Paris date, so east of Paris every window
started and ended one day early. Format them from local components as
YYYY-MM-DD before planning, as balances already are.

Closes #311

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
nessarandClaude Opus 5.5 committed 2026-10-19 15:01:06 +02:00
1 parent 9e5c93e733
commit 0b8424503c
2 files changed
+39 -3

No files matched your search

@@ -1,7 +1,7 @@
import { provideZonelessChangeDetection } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { vi } from '../../testing/vitest-compat';
import { CalendarService } from './calendar-service';
import { CalendarService, SelectableDayType } from './calendar-service';
import { CalendarSettingsService } from './calendar-settings-service';
import type {
PlanOutcome,
@@ -11,6 +11,7 @@ import type {
PlanningReason,
} from './leave-planner.service';
import { PlanningCalculationService } from './planning-calculation.service';
import { RuleService, RuleType } from './rule-service';
import { UserInputService } from './user-input-service';
function deferred<T>() {
@@ -119,6 +120,33 @@ describe('PlanningCalculationService', () => {
expect(submission.labels).toBeDefined();
});
it('hands TIME_WINDOW rules the picked calendar dates east of Paris', () => {
const previousTimeZone = process.env['TZ'];
process.env['TZ'] = 'Pacific/Auckland';
try {
TestBed.inject(RuleService).addRule({
id: 'christmas',
name: 'Christmas',
type: RuleType.TIME_WINDOW,
enabled: true,
force: 'obligation',
startDate: new Date(2026, 11, 20),
endDate: new Date(2026, 11, 31),
placeDays: 3,
placeType: SelectableDayType.CP,
});
queue(fakeCalculation('first'));
service.start();
const submitted = create.mock.calls[0][0].rules.find(
(rule: { id: string }) => rule.id === 'christmas',
);
expect(submitted).toMatchObject({ startDate: '2026-12-20', endDate: '2026-12-31' });
} finally {
// bun test defaults to UTC without setting TZ; deleting it would fall back to the host zone.
process.env['TZ'] = previousTimeZone ?? 'UTC';
}
});
it('reports the stage and submission of the latest calculation only, until Cancel', () => {
queue(fakeCalculation('old'), fakeCalculation('latest'));
service.start();
@@ -11,7 +11,7 @@ import type {
PlanningRequest,
PlanningSnapshot,
} from './leave-planner.service';
import { RuleService } from './rule-service';
import { RuleService, RuleType } from './rule-service';
import { TranslationService } from './translation-service';
import { UserInputService } from './user-input-service';
@@ -85,7 +85,15 @@ export class PlanningCalculationService {
: undefined,
expiryDate: dayjs(balance.expiryDate).format('YYYY-MM-DD'),
})),
rules: this.rules.rules,
rules: this.rules.rules.map((rule) =>
rule.type === RuleType.TIME_WINDOW
? {
...rule,
startDate: dayjs(rule.startDate).format('YYYY-MM-DD'),
endDate: dayjs(rule.endDate).format('YYYY-MM-DD'),
}
: rule,
),
};
});