Skip to content

fix: use multi-calendar-dates' date helpers and bump it to 3.2.1 - #609

Open
kabaros wants to merge 5 commits into
masterfrom
refactor/multi-calendar-dates-helpers
Open

kabaros wants to merge 5 commits into
masterfrom
refactor/multi-calendar-dates-helpers

Conversation

@kabaros

@kabaros kabaros commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Use multi-calendar-dates' date helpers for calendar date strings

Follow-up to #604. @dhis2/multi-calendar-dates 3.2.0 adds formatCalendarDate and addToCalendarDate, so the app's own date-string formatting and day arithmetic in src/shared/date/ can go.

Dependency changes

  • @dhis2/multi-calendar-dates ^3.1.0 → ^3.2.1 (dependency and resolution).
  • @dhis2/ui ^10.19.2 → ^10.19.3 (dependency and resolution). In 10.19.3, @dhis2-ui/calendar depends on ^3.1.0 instead of the exact 3.0.0, so the lockfile keeps a single multi-calendar-dates copy (3.2.1) without relying on the resolution to override an exact pin.

Code changes (src/shared/date/)

  • getNowInCalendarString: stringifyDate is replaced by formatCalendarDate(now, { includeTime: long }). The output is unchanged.
  • convertFromIso8601ToString: formats with formatCalendarDate, which reads the year as eraYear ?? year. Before, it read eraYear only for calendar === 'ethiopian', so the ethiopic id gave the Amete Alem year (7516-10-08 instead of 2016-10-08). getNowInCalendarString already handled both ids, so the two functions disagreed for ethiopic.
  • convertToIso8601ToString: formats the ISO result with formatCalendarDate instead of padding the fields by hand. The output is unchanged.
  • addDaysToDateString: adds the days in the calendar with addToCalendarDate(date, { days }, calendar), instead of converting to ISO, adding days * 24h to a JS Date, and converting back. The time part, if any, is kept as it is. Its only caller is the expiry-days check in use-check-lock-status.js (selectedPeriod.endDate + expiryDays + 1).
  • Removed: padWithZeros and the ISO formatDate helper (and DAY_MS), which nothing else used.
  • The ethiopian addDaysToDateString test in date-utils.test.js was skipped; it passes now (it already passed on master), so it's re-enabled.

period-selector-bar-item.jsx, which reads eraYear/year itself, and DateText's display formatting (which slices the string and shows HH:MM) are left as they are.

What users will notice

Nothing, on a DHIS2 server. The server reports the Ethiopian calendar as ethiopian, which was already handled; the ethiopic fix only matters if that id is passed in. For addDaysToDateString, results are the same for every calendar tested; the difference is that adding days no longer goes through local time, so a date with a time part can't shift by an hour across a DST change.

Regression snapshot results

src/shared/date/date-utils.regression.test.js snapshots getNowInCalendarString (with a mocked current time), convertFromIso8601ToString, convertToIso8601ToString and addDaysToDateString for gregory, ethiopian, ethiopic, nepali and islamic (plus iso8601 and gregorian for convertFromIso8601ToString). The baseline was committed before the change, on the current code.

  • gregory, ethiopian, nepali, islamic: unchanged, for every function.
  • ethiopic, convertFromIso8601ToString: now gives the era year, e.g. 2024-06-15 → 2016-10-08 instead of 7516-10-08. This is the fix described above, and it matches getNowInCalendarString and the ethiopian output.
  • ethiopic, addDaysToDateString: the old version converted to ISO (reading the year as the era year) and back with convertFromIso8601ToString (writing the Amete Alem year), so the year changed on every call: 2016-02-30 +5 gave 7516-03-05, and 7516-02-30 +5 gave 13016-03-05. It now keeps the year the input was in: 2016-03-05 and 7516-03-05.

These snapshots were updated on purpose.

Verification

  • CI=true yarn test: 598 tests passed (34 skipped), 25 snapshots passed.
  • yarn lint: ESLint, Stylelint and Prettier pass on the repo's files. Note that yarn lint fails on a fresh clone until src/locales has been generated by a build; this is unrelated to this PR.
  • Not checked in a browser.

Note for maintainers: the regression snapshots (date-utils.regression.test.js and its .snap) were added to verify this change. Feel free to delete them once it has been confirmed.

🤖 Generated with Claude Code

kabaros and others added 5 commits October 15, 2026 11:18
Baseline for getNowInCalendarString, convertFromIso8601ToString and
addDaysToDateString in gregory, ethiopian, ethiopic, nepali and islamic,
taken before switching them to multi-calendar-dates' date helpers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to 10.19.3

3.2.0 adds the formatCalendarDate / addToCalendarDate helpers.
@dhis2/ui 10.19.3 (@dhis2-ui/calendar) depends on ^3.1.0 instead of
the exact 3.0.0, so the lockfile keeps a single 3.x copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rings

- getNowInCalendarString formats with formatCalendarDate instead of its
  own stringifyDate.
- convertFromIso8601ToString / convertToIso8601ToString format with
  formatCalendarDate. This fixes convertFromIso8601ToString for the
  `ethiopic` calendar id, which gave the Amete Alem year (7516) instead
  of the era year (2016) because it only read eraYear for `ethiopian`.
- addDaysToDateString adds the days in the calendar with
  addToCalendarDate, instead of converting to ISO and back through JS
  Date. The time part is kept as it is.
- padWithZeros and the ISO formatDate helper are removed; nothing else
  uses them.
- Re-enable the ethiopian addDaysToDateString test, which passes.

The ethiopic regression snapshots change because of the eraYear fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3.2.1 corrects the Nepali calendar data (dhis2/multi-calendar-dates#108).
The regression snapshots are unchanged: the only affected Nepali year they
cover is 2086, and only on 1 January, whose Jan-1 column didn't change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@dhis2-bot

Copy link
Copy Markdown
Contributor

🚀 Deployed on https://pr-609--dhis2-data-entry.netlify.app

@dhis2-bot
dhis2-bot temporarily deployed to netlify October 20, 2026 11:28 Inactive

This branch was previously deployed

1 inactive deployment
netlify — 690446b1 Deployed Oct 20, 2026 by dhis2-bot
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.

2 participants