Skip to content

fix(#7018): format task dates with latin digits in every locale - #11506

Draft
Gillinghammer wants to merge 1 commit into
medic:masterfrom
Gillinghammer:7018-task-dates-latin-digits
Draft

Gillinghammer wants to merge 1 commit into
medic:masterfrom
Gillinghammer:7018-task-dates-latin-digits

Conversation

@Gillinghammer

Copy link
Copy Markdown

Description

Task docs created by users whose language is Nepali or Hindi (or Arabic) were saved with dueDate, startDate and endDate in Devanagari (or Arabic-Indic) digits, e.g. २०२१-०३-१७. The webapp sets the global moment locale to the user's language, and task-states.js formatted those dates without pinning a locale. provider-wireup.js already uses .locale('en') for the same reason.

As well as breaking analytics, this also affected task states: a window saved in Latin digits was compared against a Devanagari "today", so a current task could come out as Failed.

Changes, all in shared-libs/rules-engine/src/task-states.js:

  • Window dates and the "today" used in calculateState are now always formatted in the en locale.
  • Windows already stored on task docs with Devanagari or Arabic-Indic digits are converted to Latin digits when read, so existing tasks still compare correctly after upgrading. Active tasks get rewritten with Latin digits the next time they're recalculated. Docs that are already in a terminal state keep the old digits on disk. Fixing those would need a migration, which I left out of this PR.

How I tested it:

  • Reproduced on master with a small node script: with moment.locale(['ne', 'en']) the window came out as २०२१-०३-१७, and a window saved in Latin digits came out Failed instead of Ready. Both are correct after the change.
  • Added unit tests in shared-libs/rules-engine/test/task-states.spec.js for the ne and ar locales and for windows saved with localized digits. The 6 new tests fail on master and pass with the fix.
  • cd shared-libs/rules-engine && TZ=<tz> npm test with Canada/Pacific, Africa/Monrovia and Pacific/Auckland: 230 passing in each, no failures.
  • npx eslint on the two changed files: clean. I didn't run the webapp Karma suite locally.

Fixes #7018

Code review checklist

  • Readable: Concise, well named, follows the style guide
  • Tested: Unit and/or e2e where appropriate
  • 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.

AI Disclosure: Prepared with Claude Code via TOA, reviewed by @Gillinghammer. Claude Code (claude-opus-5-5) wrote the code and tests and a separate AI review pass checked them.

License

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

Task window dates were formatted with the global moment locale, so users
on ne/hi or ar saved dueDate, startDate and endDate with Devanagari or
Arabic-Indic digits. Format them in the 'en' locale instead, and convert
the digits of windows already saved on task docs so they still compare
correctly against today's date.

Assisted-by: Claude Code (claude-opus-5-5)

This branch has not been deployed

No deployments
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.

Date for tasks written in unicode format.

1 participant