Skip to content

fix(#11241): ensure Bikram Sambat date conversion uses local date string format#11251

Open
binokaryg wants to merge 2 commits into
medic:masterfrom
binokaryg:11241-bikram-sambat-local-date
Open

fix(#11241): ensure Bikram Sambat date conversion uses local date string format#11251
binokaryg wants to merge 2 commits into
medic:masterfrom
binokaryg:11241-bikram-sambat-local-date

Conversation

@binokaryg

Copy link
Copy Markdown
Member

Description

When the webapp is used in Nepali (Bikram Sambat calendar), the displayed date rolled over to the next day several hours before local midnight. In Nepal (UTC+5:45) it changed at 18:15 (6:15 PM) instead of midnight.

Root cause: FormatDateService passed a moment object to bikram-sambat, whose toBik_text/toBik expect an ISO date string (YYYY-MM-DD). The library's Date.parse then consumed the full timestamp, so an evening time-of-day rolled the day over early in timezones ahead of UTC. Additionally, with the ne locale active, moment.format emits Devanagari numerals, which Date.parse cannot read, causing the "Date outside supported range" crash.

Fix: format the moment to a local YYYY-MM-DD string before passing it to the library, and force the en locale on a clone so the numerals stay ASCII (the datetime time-portion remains localised). This pins the conversion to the local calendar day so the date changes at local midnight.

Tests: updated the existing date/datetime/dayMonth specs to assert the library now receives the local date string, and added two regression tests in format-date.service.spec.ts

  • one proving time-of-day independence (start-of-day and end-of-day map to the same date),
  • and another proving ASCII digits are passed even when the locale renders Devanagari.

Both new tests were verified to fail on the unfixed code and pass with the fix.

Fixes: #11241

AI disclosure

Per the AI contribution guidelines:

  • Tool: Claude Code (Anthropic).
  • How it was used: investigating the bug report and understanding the relevant code, identifying the root cause (passing a moment to bikram-sambat instead of an ISO date string, plus the ne-locale Devanagari-numeral crash), implementing the fix, and writing the unit tests and code comments.

All changes were reviewed and tested by me; the new tests were verified to fail without the fix and pass with it.

Code review checklist

  • UI/UX backwards compatible: Test it works for the new design (enabled by default). And test it works in the old design, enable can_view_old_navigation permission to see the old design. Test it has appropriate design for RTL languages.
  • Readable: Concise, well named, follows the style guide
  • Documented: Configuration and user documentation on cht-docs
  • Tested: Unit and/or e2e where appropriate
  • Internationalised: All user facing text
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.
  • AI disclosure: Please disclose use of AI per the guidelines.

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

…e string format

Pass a local YYYY-MM-DD string to  bikram-sambat instead of a moment, so an evening time-of-day no longer rolls the date over before local midnight in timezones ahead of UTC (Nepal, from 18:15). Force the 'en' locale on a clone so the active 'ne' locale doesn't emit Devanagari numerals that Date.parse can't read.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@binokaryg
binokaryg marked this pull request as draft July 14, 2026 21:01
@binokaryg

Copy link
Copy Markdown
Member Author

Before:
image

After:
image

@binokaryg
binokaryg marked this pull request as ready for review July 15, 2026 01:07
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.

Bikram Sambat (Nepali) date changes at 6:15 PM instead of local midnight

2 participants