fix: enhance date formatting for calendar awareness #578
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request fixes an issue where non-Gregorian calendars (e.g., Jalali/Persian) do not display correct day or month values when a localized language code is passed (e.g.,
fa-IR-u-ca-persian).Currently,
frappe-ganttrelies on rawDateobject values fromthis.get_date_values(date), which always use the Gregorian calendar. As a result, when users select languages that use calendar systems like Jalali, the day and month fields are rendered incorrectly.Problem Example
When using:
gantt = new Gantt('#gantt', tasks, { language: 'fa-IR-u-ca-persian' });Expected: Days and months should follow the Jalali calendar.
Actual: Days of months are displayed incorrectly (see screenshot).
Fix Implemented
Switched to
Intl.DateTimeFormatfor extracting year, month, and day values.This ensures that values respect the active calendar system defined in the
langparameter.The new
format_mapseparates calendar-aware values (YYYY, MM, DD, D, MMMM, MMM) from time values (HH, mm, ss, SSS), ensuring correct rendering across different locales and calendars.Example:
YYYY: yearFmt.format(date), MM: month2Fmt.format(date), DD: day2Fmt.format(date), D: dayFmt.format(date), MMMM: month_name_capitalized, MMM: monthShortFmt.format(date)Requirements / Notes
✅ Tested with
fa-IR-u-ca-persian(Jalali calendar).✅ Backward compatible with default
en(Gregorian calendar).✅ No external dependencies added — relies only on
Intl.DateTimeFormat.📖 Reference: Unicode Locale Identifiers (e.g.,
fa-IR-u-ca-persian).Impact
This change improves internationalization support in
frappe-ganttand ensures correct date rendering for users working with non-Gregorian calendars.