-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Protected tokens consistency in format
and parse
functions (v3?)
#2950
Comments
I would really second this and I think it should be a priority. While Y off-by-one-year is not a bug, in the sense that it's ISO compliant, it's 100% a usability bug in the sense that I would guess that almost no-one who is using it is actually intending to. For example, my team used From our perspective, I think a dev either guessed or asked chat gpt for the format, it matched in ~5 unit tests, we looked at a data table full of a variety of dates and everything seemed good to go. Yes, we should've read and memorized the documentation, but given how subtle the 'gotcha' is, it feels like something that many devs are likely to overlook. Throwing a warning would be ideal behavior here. Something like, "HEY, /endrant thank you all for maintaining this library, it's truly the best-- just thought I'd share my experience around a rock that got caught in my shoe ;) |
It was designed to have all tokens throw an error. I can't tell when the bug was introduced, but I can't bring the exceptions now and mess up people's code. The solution is to add a warning to the console and hope people see it. |
For some reason, we made a decision to hand-pick tokens. In hindsight, it was a bad idea, but now I can do nothing. I added warnings on such tokens of any length. I hope it will help. Closed by a576d6e, coming in the next release |
Shipped with |
@kossnocorp Great! Looks like you forgot to handle the |
How come the
format
andparse
tokensY
andD
are protected, but not all their lengths and variants?I'm guessing it was put in place to help people migrate from other libraries, but the
Y
,YYYYY
,YYYYYY
are valid inmoment
too.DDD
andDDDD
behave the same in both, so it's probably not impactful for migration mistakes.EDIT: not quite the same in terms of padding, though. Ex: Jan 3rd 2021:
DDD
DDDD
I wouldn't rule out that this protection feature is also helping people that are simply just guessing the tokens without consulting the docs. If the output looks OK at first glance, it probably ships and creates weird bugs in many apps, especially
Y
.See #2133
Just wanted to put this out there, and suggest that all variants should be protected in v3.
Related:
https://date-fns.org/docs/format
https://date-fns.org/docs/parse
https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md
date-fns/src/_lib/protectedTokens/index.ts
Lines 12 to 34 in e5c7ac0
The text was updated successfully, but these errors were encountered: