Skip to content

i18n: allow to provide DateTimeFormat calendar #5440

@slorber

Description

@slorber

🐛 Bug Report

    new Intl.DateTimeFormat("fa", {
      day: 'numeric',
      month: 'numeric',
      year: 'numeric',
      timeZone: 'UTC',
    }).format(new Date()).replace(/[۰-۹]/g, (chr) => {
      const persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
      return persian.indexOf(chr)
    })

This code does not use the same calendar on Node.js (Gregorian) and browsers (Solar Hijri), leading to a different date being rendered in SSR and after React hydration.

We should provide an i18n locale option to force a given calendar and make sure the formatted date is consistent between SSR/client.

    new Intl.DateTimeFormat("fa", {
      day: 'numeric',
      month: 'numeric',
      year: 'numeric',
      timeZone: 'UTC',
      calendar: "gregory"
    }).format(new Date()).replace(/[۰-۹]/g, (chr) => {
      const persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹']
      return persian.indexOf(chr)
    })

Issue initially reported here: #5410 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAn error in the Docusaurus core causing instability or issues with its executiondifficulty: starterIssues that are starter difficulty level, e.g. minimal tweaking with a clear test plan.domain: i18nRelated to the i18n systemstatus: accepting prThis issue has been accepted, and we are looking for community contributors to implement this

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions