Skip to content

fix(routines): resolve local timezone shift bug on naive dates#1251

Open
Marcelluxx wants to merge 2 commits into
wger-project:masterfrom
Marcelluxx:fix/timezone-dates-2334
Open

fix(routines): resolve local timezone shift bug on naive dates#1251
Marcelluxx wants to merge 2 commits into
wger-project:masterfrom
Marcelluxx:fix/timezone-dates-2334

Conversation

@Marcelluxx
Copy link
Copy Markdown

@Marcelluxx Marcelluxx commented May 24, 2026

API returns naive date strings (e.g., 'YYYY-MM-DD') representing routine start and end dates. When parsed and formatted locally, negative UTC offset browser timezones shift the date backward by one day (e.g., formatting UTC midnight as the previous day in local browser time).

Proposed Changes

  1. Implemented formatNaiveDate in date.ts to format date strings and standard Date objects timezone-agnostically using timeZone: UTC.
  2. Replaced dateToLocale calls with formatNaiveDate in routine detail, template detail, and overview screens.
  3. Added exhaustive unit test coverage in date.test.ts verifying parsing, month boundaries, Date object support, and invalid/fallback inputs.

Related Issue(s)

Closes wger-project/wger#2334

Please check that the PR fulfills these requirements

  • Tests for the changes have been added (for bug fixes / features)

API returns naive date strings (e.g., 'YYYY-MM-DD') representing routine start and end dates. When parsed and formatted locally, negative UTC offset browser timezones shift the date backward by one day (e.g., formatting UTC midnight as the previous day in local browser time).

To fix this, we: 1. Implemented 'formatNaiveDate' in 'date.ts' to format date strings and standard Date objects timezone-agnostically using 'timeZone: UTC'. 2. Replaced 'dateToLocale' calls with 'formatNaiveDate' in routine detail, template detail, and overview screens. 3. Added exhaustive unit test coverage in 'date.test.ts' verifying parsing, month boundaries, Date object support, and invalid/fallback inputs.
Comment thread src/core/lib/date.ts Outdated
return '';
}
utcDate = date;
} else if (typeof date === 'string') {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that at the moment (and probably in the future as well), we will not reach this branch as all objects convert the DateTime-String into an object. I think we should simplify this part of the helper and remove this section till the need arises.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! The data layer already ensures everything is normalized to standard Date objects, so we don't need to parse strings here. I've simplified the utility and updated the test suite.
Thanks for the feedback!

…jects

Per PR review feedback, removed string parsing and regex logic from formatNaiveDate as all dates are normalized to Date objects by the data layer. Updated corresponding unit tests in date.test.ts to use Date objects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Start and End Date of Routine are 1 day off

2 participants