question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update date format to user local format

See original GitHub issue

Have you read the Contributing Guidelines on issues?

Prerequisites

  • I’m using the latest version of Docusaurus.
  • I have tried the npm run clear or yarn clear command.
  • I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • I have tried creating a repro with https://new.docusaurus.io.
  • I have read the console error message carefully (if applicable).

Description

Doc pages have e.g. Last updated on 4/25/2022 by Simen Bekkhus, which is the US locale. This makes the date ambiguous when the date is 1-12. While that would still be the case if the date uses the local locale, at least I’d read it correctly 😅

Reproducible demo

https://github.com/facebook/jest

Steps to reproduce

Look at the bottom of e.g. https://jestjs.io/docs/jest-object#fake-timers

Expected behavior

For non-US locales, that it says Last updated on 25/04/2022 by Simen Bekkhus, like new Intl.DateTimeFormat().format() returns when I run it in the Chrome console. I.e. uses local locale, not US locale.

Actual behavior

It uses US date formatting.

Your environment

  • Public source code:
  • Public site URL: https://jestjs.io/
  • Docusaurus version used: 2.0.0-beta.18
  • Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 100 (and whatever version of node Netlify uses)
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS): macOS 12.13.1

Self-service

  • I’d be willing to fix this bug myself.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
slorbercommented, Jun 29, 2022

Will keep this open until we provide more flexibility for users to define how they want to handle blog/doc date formats

See also https://github.com/facebook/docusaurus/pull/7673#issuecomment-1170186409

1reaction
Josh-Cenacommented, Apr 27, 2022

I’m not sure what scope you want that ISO format to apply: (a) to all locales, or (b) just to en, or © be a user config?

For (a), I’d say using the locale date format is usually not that ambiguous. e.g. fr would format the date as dd-MM-yyyy which seems reasonable to every French-speaking people (actually, maybe not, since fr-CA formats it as yyyy-MM-dd, so a fair proportion of them don’t format as dd-MM-yyyy). It’s just English that has this complication😅 And for ©, when it comes to i18n, it’s usually not the site creator’s call to say what to display, so a config option doesn’t seem right to me either. So the solutions I can think of are:

  • Special-case en (which is the default anyways, so it is already special in some sense) where we always use yyyy-MM-dd
  • Update the date format after hydration

Both seem like good ways out, but the second way could potentially solve other edge-cases if there are other diverging date formats in other locales that I’m not aware of.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change the date format for each User - Salesforce Help
Change how the date format is displayed by updating the "Locale" set on the User record. · Change the Date format in Classic....
Read more >
Display date/time in user's locale format and time offset
To convert date to local date use toLocaleDateString() method. var date = (new ...
Read more >
Formatting the user's local date-times using Hooks - Fly.io
Based on the user's default locale and timezone, this method returns the local date as a string.
Read more >
How to change date format depends on user locale?
There is a Date method for that: format(). Returns the Date as a string using the locale of the context user. Here are...
Read more >
Date and time localization - Lokalise Blog
In the long date format, the syntax of the date is MMM DD YYYY . Here, the month and ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found