-
Notifications
You must be signed in to change notification settings - Fork 41
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
Parsing two-digit year 16
with results in 0016
and not 2016
#263
Comments
Nearly 3 years later I've stumbled across the same issue via the unit tests in my Flutter app. The issue occurs even when using the specific example from the comments in date_format.dart (pattern: "MM/dd/yy", input "01/11/12" ; the resulting year is 0012). This contradicts in the description in date_format.dart (line 202) which states it should resolve to 2012. Needs to be fixed. Tested with intl: ^0.15.8 |
A hacky workaround by adding Duration could be:
|
@altherat That hacky workaround isn't correct since it will change the time. (That is, adding 24 * 60 * 60 seconds to a date might not necessarily be the same as incrementing the day by 1 due to leap seconds, daylight saving, ...). An even bigger problem with your hack is that when this bug is fixed, your hack will be broken. You'd be better off taking the result of |
@jamesderlin that would problem but they did not fixed bug for 4 years already the closest to fixed is dart-archive/intl#125 but it got rejected |
I think @jamesderlin was right all along. I used the hacky workaround and after sometime it was giving me a wrong month. So I switched back to adding 2000 in the year as in |
Please do not unconditionally add 2000. As I mentioned, such hacks will break when this bug is fixed. Add 2000 only to 2-digit years. And yes, a fix is forthcoming. |
@jamesderlin, i was just showing how to simply add 2000, of course, there are checks before it arrives to that.. |
Okay, I just don't want people to copy-and-paste that workaround blindly. I have seen other people also suggest workarounds that omit any checks. |
Understood, simple check can be?
|
This is now fixed on |
@jamesderlin when will 17.0 show up on pub.dev? edit (this works in the interim) |
0.17 probably will not be available on pub.dev until In the meantime, yes, you can have your |
A prerelease version of 0.17 is now available. |
The `DateFormat` documentation claims that two-digit years will be interpreted to be within 80 years before and 20 years after the current date. I don't know if that was ever true (that documentation predates the creation of the GitHub repository). While I'm tempted to just remove that false claim, there are multiple GitHub issues about this not working, so some people want it. * https://github.com/dart-lang/intl/issues/123 * https://github.com/dart-lang/intl/issues/275 PiperOrigin-RevId: 311079631 PiperOrigin-RevId: 311101503 PiperOrigin-RevId: 311412441
This code results in a year of
0016
and not2016
. Same thing happens whether I usey
oryy
in the format. Unfortunately it's tricky to fix this, because you can't even.add
2000 years, because the Duration class only goes up to days!Other languages make assumptions about two-digit years being 19/20; it probably makes sense to do the same.
The text was updated successfully, but these errors were encountered: