formkit / tempo

📆 Parse, format, manipulate, and internationalize dates and times in JavaScript and TypeScript.
https://tempo.formkit.com
MIT License
2.37k stars 33 forks source link

Example on front page broken in German (and possibly other languages) #1

Closed AaronDewes closed 9 months ago

AaronDewes commented 9 months ago

Quite a few examples on the front page throw an error in a German browser:

grafik

Date (Dienstag, 13. Februar 2024) does not match format (dddd, MMMM D, YYYY)


format() seems to default to the browser language. parse() should do that too in my opinion, and fall back to english if the local language fails.

andrew-boyd commented 9 months ago

Thanks for the report. Would you mind sharing what browser and version you are using?

AaronDewes commented 9 months ago

I can reproduce this in Chrome 121 and Firefox 122. I also amended the issue with the root cause:

format() seems to default to the browser language.

parse() should do that too in my opinion, and fall back to English if the local language fails (or something else, what's the intended behaviour is your decision, but a broken example isn't good in my opinion).

AaronDewes commented 9 months ago

You could also just change the example to be

import { format, parse } from "@formkit/tempo"

const readable = format(new Date(), "full")

parse(readable, "full", "device")

or

import { format, parse } from "@formkit/tempo"

const readable = format(new Date(), "full", "en")

parse(readable, "full")
justin-schroeder commented 9 months ago

This should be fixed now. parse had a default locale of en instead of device.