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.

Validating date using a locale

See original GitHub issue

Hi!

Is there a way to validated a date using a locale? Something like dayjs('15/10/2018', {locale: 'pt-br'}).isValid()?

Thank you!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

3reactions
prantlfcommented, Oct 7, 2018

Yes, the #340 parses using only the specified format. It does not pass the input to the Date constructor as a fallback. For example:

dayjs('15/10/2018', { format: 'DD/MM/YYYY' }).isValid()

You see, that you do not need to provide the locale, but you need to know the Portuguese official date format. If you wanted to specify the format with the help of the locale and not so explicitly, this PR could join forces with #305 to specify a localizable date-only format, for example:

dayjs('15/10/2018', { format: 'L', locale: 'pt-br' }).isValid()

Of course, you would have to know, that “L” means date-only and how it translates in Portuguese 😃

0reactions
iamkuncommented, Feb 24, 2019

From v1.8.7, you could check like this

import 'dayjs/locale/es'
import customParseFormat from 'dayjs/plugin/customParseFormat'
dayjs.extend(customParseFormat)

dayjs('2018 Enero 15', 'YYYY MMMM DD', 'es').isValid()
Read more comments on GitHub >

github_iconTop Results From Across the Web

validate a date on the basis of locale argument (intl api)
The "locale" is actually a language code, which is an unreliable way to determine the order in which date components are typically presented....
Read more >
Localizing date and time validation - IBM
Dates can be stored in a standard format, but displayed according to the required format. If the date is entered on a screen,...
Read more >
Check If a String Is a Valid Date in Java - Baeldung
Check If a String Is a Valid Date in Java · 1. Overview · 2. Date Validation Overview · 3. Validate Using DateFormat...
Read more >
KB-2022 Date format validation is not translated based on locale
Validations on date components display in US date format: "mm/dd/yyyy" . For example, if the system language is set to English (United Kingdom)...
Read more >
Date.prototype.toLocaleDateString() - JavaScript | MDN
A string with a BCP 47 language tag, or an array of such strings. Corresponds to the locales parameter of the Intl.DateTimeFormat() constructor....
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