Skip to content
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

isValid fails to recognise valid formats #5884

Open
rijnhard opened this issue May 5, 2021 · 2 comments
Open

isValid fails to recognise valid formats #5884

rijnhard opened this issue May 5, 2021 · 2 comments

Comments

@rijnhard
Copy link

rijnhard commented May 5, 2021

Describe the bug
I am using moment to test if a user-provided format is correct.

moment(moment().format(format)).isValid();

And this always emits a deprecation warning if the format is not correct which is unnecessary.

relates heavily to #2535
and https://stackoverflow.com/questions/44595835/validate-date-format-not-date-string-using-momentjs

To Reproduce

function test(format) {
    return moment(moment().format(format)).isValid();
}

test('YYYY'); // returns true, no warning
test('hamster'); // returns false, and issues warning

Expected behavior
return false without warning.

Screenshots
If applicable, add screenshots to help explain your problem.

Moment-specific environment

  • The time zone setting of the machine the code is running on: GMT+2
  • The time and date at which the code was run: 20210505T14h25

Please run the following code in your environment and include the output:

Wed May 05 2021 14:28:19 GMT+0200 (South Africa Standard Time)
2021/05/05, 14:28:19
-120
// errors (nodejs not browser)
2.29.1
@rijnhard
Copy link
Author

rijnhard commented May 5, 2021

Ontop of this I get some pretty strange behaviour in terms of false negatives with isValid

test('YYYYMMDD'); // true, no error
test('YYYYMMDDHH'); // false, with deprecation warning
test('YYYYMMDD HH'); // true, no error
test('YYYYMMDD HHmm'); // true, no error
test('YYYYMMDD HH mm'); // false, with deprecation warning
test('YYYYMMDD [T]'); // false, with deprecation warning

the inconsistency is unreal, my actual test case is YYYYMMDD[T]HH[h]mm which it utterly fails on.

@rijnhard rijnhard changed the title allow isValid to be used without deprecation warnings isValid fails to recognise valid date formats May 5, 2021
@rijnhard rijnhard changed the title isValid fails to recognise valid date formats isValid fails to recognise valid formats May 5, 2021
@ChechenWiki
Copy link

Moment.js doesn't have a Chechen (ce) time format support and falls back to Russian, so Notifications are in an incorrect time format. Can this be fixed here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants