Skip to content

bug: DEFAULT_DATE_RANGE captures the year once at module load and goes stale after New Year #4841

@Anexus5919

Description

@Anexus5919

Description

In utils/dateRange.ts, the fallback range was an exported constant whose year was evaluated once, when the module is first loaded:

export const DEFAULT_DATE_RANGE = {
  from: `${new Date().getUTCFullYear()}-01-01T00:00:00Z`,
  to: `${new Date().getUTCFullYear()}-12-31T23:59:59Z`,
};

Because new Date().getUTCFullYear() runs at module-load time, the value becomes stale once the process crosses a New Year boundary. A long-lived process that loaded the module in December would keep returning the previous year's range in January. formatDateRange returns this same value for missing or invalid years, so its fallback inherits the staleness.

DEFAULT_DATE_RANGE and formatDateRange currently have no production callers (only the module itself and its test reference them), so the present impact is limited to tests, but the value is incorrect by construction.

Steps to Reproduce

  1. Load utils/dateRange.ts in a process during December of year N.
  2. Keep the process alive past midnight UTC on January 1 of year N+1.
  3. Read DEFAULT_DATE_RANGE (or call formatDateRange('')).
  4. Observe the range still reports year N rather than N+1.

Expected Behavior

The default range reflects the current year whenever it is read, so it stays correct after a New Year rollover.

Screenshots / Logs

Not applicable.

Environment

Other

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions