-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Locales can't be used in parsing dates #694
Comments
So I tried
and obtained
so the locales do work. I was under the impression that parsing would also respect locales, but this doesn't seem to be the case? |
It seems
but no locale-supported format string such as
which would be useful here because the command could be used regardless of the locale currently set. |
I did not get what you mean. Using locale will localize the week name 'Saturday' to 'Saturday in another language', but will of course not display as another day like you expected 'Wed' |
Sorry, at first I was confused about using locales without Babel (require vs. import), but it turns out my problems were based on my expectations about using locales for parsing the dates. If I pass "11/09/2019" to dayjs for parsing with locale en-gb, I would expect 2019-09-11 as the date, not 2019-11-09 as it happened. Turns out I needed to set a CustomParseFormat, but this one only allows non-locale placeholders for the format, as above, e.g. |
@raketenolli CustomParseFormat plugin supports tokens like 'Do' 'MMMM' which are all locale-aware. |
I know that if you provide a string containing e.g. "März", it would be parsed properly to March if "MMMM" is provided as the format string for the CustomParseFormat and locale is set to "de". But the CustomParseFormat does not support the localized formats like "L", "LTS" etc. which would enable the user to just set the locale but not have to worry about the exact formatting if they know they can expect e.g. an "L, LTS" formatted string ("10/31/2019, 08:30 PM" vs. "31.10.2019, 20:30"). |
Here's working around to get the locale formats |
Thanks, so a solution to my issue would be
|
Update: This was originally a bug about missing documentation about using locales without babel.
Describe the bug
I was under the assumption that locales would help in parsing dates.
I tried
and I get
Expected behavior
I was expecting an output like
Using
dayjs(datestring, { locale: enGB });
yielded the same result.Information
The text was updated successfully, but these errors were encountered: