Today marker and default planning horizon disagree near midnight outside Europe/Paris #301

Closed
opened 2026-10-18 01:48:19 +02:00 by nessar · 2 comments
Owner

Problem

CalendarService.getDefaultPlanningHorizon() starts the horizon on the Paris date (planningDateInParis(now), src/app/services/calendar-service.ts:69-71), but project() marks the TODAY day from dateCache.getTodayComponents() (calendar-service.ts:88-92, 126-130), which uses the runtime's local date.

Whenever the local date differs from the Paris date, the horizon's first day is not marked as today, and a different day (or none) gets the today marker. This happens:

  • in CI containers (UTC), every night between 22:00 and 24:00 UTC during CEST (23:00-24:00 during CET);
  • for any user whose browser is not on Europe/Paris time, around their midnight.

Evidence

CI for PR #296 (run 98, job test) ran at 2026-10-17 22:16 UTC (Sunday 00:16 Paris) and failed with 1 of 750 tests:

(fail) CalendarService > project > projects weekends, holidays and today for the default planning horizon
Expected to contain: "today"
Received: "weekend"

The horizon started on Sunday 2026-10-18 (Paris) while the container's local today was still Saturday 2026-10-17. The failure is unrelated to that PR's change and reproduces on develop in that time window.

Expected

The today marker and the default horizon use the same planning-day definition (presumably the Paris date via planning-date.ts), and the test is deterministic regardless of the clock and time zone (inject now/fake the clock rather than relying on wall time).

Repro

Run TZ=UTC bun run test with the system clock between 22:00 and 24:00 UTC (CEST), or fake Date to e.g. 2026-10-17T22:16:00Z.

## Problem `CalendarService.getDefaultPlanningHorizon()` starts the horizon on the **Paris** date (`planningDateInParis(now)`, `src/app/services/calendar-service.ts:69-71`), but `project()` marks the TODAY day from `dateCache.getTodayComponents()` (`calendar-service.ts:88-92`, `126-130`), which uses the **runtime's local** date. Whenever the local date differs from the Paris date, the horizon's first day is not marked as today, and a different day (or none) gets the today marker. This happens: - in CI containers (UTC), every night between 22:00 and 24:00 UTC during CEST (23:00-24:00 during CET); - for any user whose browser is not on Europe/Paris time, around their midnight. ## Evidence CI for PR #296 (run 98, job `test`) ran at 2026-10-17 22:16 UTC (Sunday 00:16 Paris) and failed with 1 of 750 tests: ``` (fail) CalendarService > project > projects weekends, holidays and today for the default planning horizon Expected to contain: "today" Received: "weekend" ``` The horizon started on Sunday 2026-10-18 (Paris) while the container's local today was still Saturday 2026-10-17. The failure is unrelated to that PR's change and reproduces on `develop` in that time window. ## Expected The today marker and the default horizon use the same planning-day definition (presumably the Paris date via `planning-date.ts`), and the test is deterministic regardless of the clock and time zone (inject `now`/fake the clock rather than relying on wall time). ## Repro Run `TZ=UTC bun run test` with the system clock between 22:00 and 24:00 UTC (CEST), or fake `Date` to e.g. 2026-10-17T22:16:00Z.
nessar added the needs-triage label 2026-10-18 01:48:19 +02:00
Author
Owner

Findings from an attempt in PR #307 (closed without merging; the work is redone properly here). The fix itself was two lines; this is what is worth keeping.

Root cause confirmed, as described above: getDefaultPlanningHorizon() uses planningDateInParis, while project() marks TODAY from dateCache.getTodayComponents() (the runtime's local date).

Two more CI occurrences, same assertion (calendar-service.spec.ts:205, Expected to contain: "today"). The received value was blank rather than "weekend" as in #296, because the Paris day was a Monday:

  • push run of #304: run 112, job test 912, 2026-10-18 23:13 UTC (01:13 Paris, Monday)
  • push run of #305: run 114, job test 928, 2026-10-18 23:35 UTC

This test passed in their pull_request runs, which ran around 07:40 UTC, when both dates agree.

A repro that does not depend on the wall clock. The existing test only fails inside the window, and never on a Paris-time machine. A test that pins the clock to this issue's instant fails against develop under TZ=UTC (every CI runner) and TZ=Pacific/Honolulu, and passes with the fix (branch feature/ci-test-stability, commit 036b136):

vi.setSystemTime(new Date('2026-10-17T22:16:00Z'));
const horizon = service.getDefaultPlanningHorizon();
expect(horizon.start).toBe('2026-10-18');
const { selections } = project(horizon);
expect(selections.getClasses(day('2026-10-18'))).toContain(DayType.TODAY);
expect(selections.getClasses(day('2026-10-17'))).not.toContain(DayType.TODAY);

To make it fail on a Paris-time machine too, set process.env['TZ'] = 'UTC' inside the test (restored in finally), the pattern the existing "derives the planning horizon from the instant in Europe/Paris" test already uses with Pacific/Auckland. Verified with a throwaway spec under TZ=Europe/Paris: fails without the fix, passes with it.

The attempted fix (f458a83): in project(), derive today from planningDateInParis(new Date()) (split into year, month, day; compare with day.getMonth() + 1) instead of dateCache.getTodayComponents(). Full suite 759 pass, ESLint, Prettier and tsc clean at the time.

To decide for the proper fix

  1. The same local-date assumption exists elsewhere (found by grep and by reading the template; not run in a browser, not fixed):
    • calendar-month.html:37 has [class.past]="day < getNow()", and getNow() is DateCacheService.getNow(), the local midnight. For a user whose local date is ahead of Paris, the Paris-today horizon start should be styled past.
    • getHolidays()'s default start year and monthsInAYearFromNow() use getCurrentYear() / getCurrentMonth() (local). monthsInAYearFromNow() has no caller outside tests.
  2. With the attempted fix, DateCacheService.getTodayComponents() has no caller outside its own spec. Making DateCacheService Paris-aware once would cover every consumer, whereas patching project() alone leaves the items above.
  3. project() reads new Date() internally, while getDefaultPlanningHorizon(now = new Date()) already takes now. An injectable now on project() would avoid faking the clock, which is the "inject now" this issue asks for.
Findings from an attempt in PR #307 (closed without merging; the work is redone properly here). The fix itself was two lines; this is what is worth keeping. **Root cause confirmed**, as described above: `getDefaultPlanningHorizon()` uses `planningDateInParis`, while `project()` marks TODAY from `dateCache.getTodayComponents()` (the runtime's local date). **Two more CI occurrences**, same assertion (`calendar-service.spec.ts:205`, `Expected to contain: "today"`). The received value was blank rather than "weekend" as in #296, because the Paris day was a Monday: - push run of #304: run 112, job `test` 912, 2026-10-18 23:13 UTC (01:13 Paris, Monday) - push run of #305: run 114, job `test` 928, 2026-10-18 23:35 UTC This test passed in their pull_request runs, which ran around 07:40 UTC, when both dates agree. **A repro that does not depend on the wall clock.** The existing test only fails inside the window, and never on a Paris-time machine. A test that pins the clock to this issue's instant fails against develop under `TZ=UTC` (every CI runner) and `TZ=Pacific/Honolulu`, and passes with the fix (branch `feature/ci-test-stability`, commit 036b136): ```ts vi.setSystemTime(new Date('2026-10-17T22:16:00Z')); const horizon = service.getDefaultPlanningHorizon(); expect(horizon.start).toBe('2026-10-18'); const { selections } = project(horizon); expect(selections.getClasses(day('2026-10-18'))).toContain(DayType.TODAY); expect(selections.getClasses(day('2026-10-17'))).not.toContain(DayType.TODAY); ``` To make it fail on a Paris-time machine too, set `process.env['TZ'] = 'UTC'` inside the test (restored in `finally`), the pattern the existing "derives the planning horizon from the instant in Europe/Paris" test already uses with `Pacific/Auckland`. Verified with a throwaway spec under `TZ=Europe/Paris`: fails without the fix, passes with it. **The attempted fix** (f458a83): in `project()`, derive today from `planningDateInParis(new Date())` (split into year, month, day; compare with `day.getMonth() + 1`) instead of `dateCache.getTodayComponents()`. Full suite 759 pass, ESLint, Prettier and `tsc` clean at the time. **To decide for the proper fix** 1. The same local-date assumption exists elsewhere (found by grep and by reading the template; not run in a browser, not fixed): - `calendar-month.html:37` has `[class.past]="day < getNow()"`, and `getNow()` is `DateCacheService.getNow()`, the local midnight. For a user whose local date is ahead of Paris, the Paris-today horizon start should be styled `past`. - `getHolidays()`'s default start year and `monthsInAYearFromNow()` use `getCurrentYear()` / `getCurrentMonth()` (local). `monthsInAYearFromNow()` has no caller outside tests. 2. With the attempted fix, `DateCacheService.getTodayComponents()` has no caller outside its own spec. Making `DateCacheService` Paris-aware once would cover every consumer, whereas patching `project()` alone leaves the items above. 3. `project()` reads `new Date()` internally, while `getDefaultPlanningHorizon(now = new Date())` already takes `now`. An injectable `now` on `project()` would avoid faking the clock, which is the "inject now" this issue asks for.
Author
Owner

Decisions from the design grilling (supersede the "To decide" list in the previous comment)

  1. Today is the Europe/Paris calendar date for the today marker and the past styling, as for the default planning horizon and each calculation. Recorded in CONTEXT.md (Today, avoid "local date"), commit b71ff20 on feature/301-paris-today.
  2. One today per projection, passed down. CalendarService.project(plan, { now }) computes the Paris date once and returns it as today in CalendarProjection; calendar-year passes it to <app-calendar-month [today]>, and past styling becomes dateKey < today. Delete DateCacheService, monthsInAYearFromNow() and the default year of getHolidays() (their only callers are specs), with their specs. Tests inject now instead of faking the clock: the existing default-horizon test passes the same now to getDefaultPlanningHorizon and project; add a regression at 2026-10-17T22:16:00Z (today = 2026-10-18, not 2026-10-17) and a past-styling test. Accepted: with a tab left open across midnight, marker and past styling both stay on the previous day until the next projection.
  3. Out of scope, filed separately: TIME_WINDOW rule dates shift one day earlier in time zones ahead of Paris, #311.
  4. Out of scope, deliberately unchanged: form defaults (new and random balances in user-input-service.ts, a new TIME_WINDOW rule in rules-panel.ts, the Christmas window in rule-service.ts) keep the device date. They are editable starting values, not the planner today, and differ only for a few hours around midnight outside Paris time.

Implementation goes on feature/301-paris-today (from origin/develop); it replaces f458a83 and 036b136 from the closed #307. The worker cancel-race fix af20c96 from #307 is not part of this issue and still lives only on feature/ci-test-stability.

**Decisions from the design grilling** (supersede the "To decide" list in the previous comment) 1. **Today is the Europe/Paris calendar date** for the today marker and the past styling, as for the default planning horizon and each calculation. Recorded in `CONTEXT.md` (**Today**, avoid "local date"), commit b71ff20 on `feature/301-paris-today`. 2. **One today per projection, passed down.** `CalendarService.project(plan, { now })` computes the Paris date once and returns it as `today` in `CalendarProjection`; `calendar-year` passes it to `<app-calendar-month [today]>`, and past styling becomes `dateKey < today`. Delete `DateCacheService`, `monthsInAYearFromNow()` and the default year of `getHolidays()` (their only callers are specs), with their specs. Tests inject `now` instead of faking the clock: the existing default-horizon test passes the same `now` to `getDefaultPlanningHorizon` and `project`; add a regression at `2026-10-17T22:16:00Z` (today = 2026-10-18, not 2026-10-17) and a past-styling test. Accepted: with a tab left open across midnight, marker and past styling both stay on the previous day until the next projection. 3. **Out of scope, filed separately:** TIME_WINDOW rule dates shift one day earlier in time zones ahead of Paris, #311. 4. **Out of scope, deliberately unchanged:** form defaults (new and random balances in `user-input-service.ts`, a new TIME_WINDOW rule in `rules-panel.ts`, the Christmas window in `rule-service.ts`) keep the device date. They are editable starting values, not the planner today, and differ only for a few hours around midnight outside Paris time. Implementation goes on `feature/301-paris-today` (from `origin/develop`); it replaces f458a83 and 036b136 from the closed #307. The worker cancel-race fix af20c96 from #307 is not part of this issue and still lives only on `feature/ci-test-stability`.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: nessar/vac-optimizer#301