-
Notifications
You must be signed in to change notification settings - Fork 36
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
Incorrect date parsing using 2-digit year pattern #145
Comments
got same problem today i dont know why it was working correctly two days ago like datetime parse output is give 0020 instead of 2020 |
i use hacked workaround from this issue #263 at bottom of comments to fix it |
This should probably be closed as duplicate of #263. Which has been fixed in master btw. |
Agreed. Sorry I didn't find the dup before filing this one. |
mosuem
referenced
this issue
Mar 2, 2023
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Date parsing of strings with 2-digit years does not yield correct results. It returns '00' for the century digits, regardless of which 'y' pattern is specified to DateFormat. The DateFormat documentation indicates that parsing using the 'yy' pattern will process the the century digits based on year value -80/+20.
In trying to figure this out, I also noticed that the DateFormat documentation references a 'DateParse instance', but I can find no other reference to such a class. Is that an obsolete reference? It is very confusing, because the example date used with that particular reference does not match the rest of the example.
Sorry, I don't fully understand if this is an issue with DateFormat or an issue with DateTime.parse(). Please let me know if I should submit this issue in a different location.
I'm using:
intl: ^0.16.1
dart: 2.7.2
flutter: 1.12.13+hotfix.9
EXAMPLE:
The following code yields the same year output (0078) for all format patterns. The first two outputs should yield 1978 as the year. The last three yield 0078 as expected.
String dateString = '4/12/78'
List patterns = [
'MM/dd/yy',
'M/dd/yy',
'MM/dd/yyyy',
'M/dd/yyyy',
'yMd',
];
patterns.forEach((pattern) {
String isoDate = DateFormat(pattern).parse(dateString).toIso8601String();
print('input: $dateString output: $isoDate pattern: $pattern');
});
OUTPUT:
I/flutter (17971): input: 4/12/78 output: 0078-04-12T00:00:00.000 pattern: MM/dd/yy
I/flutter (17971): input: 4/12/78 output: 0078-04-12T00:00:00.000 pattern: M/dd/yy
I/flutter (17971): input: 4/12/78 output: 0078-04-12T00:00:00.000 pattern: MM/dd/yyyy
I/flutter (17971): input: 4/12/78 output: 0078-04-12T00:00:00.000 pattern: M/dd/yyyy
I/flutter (17971): input: 4/12/78 output: 0078-04-12T00:00:00.000 pattern: yMd
The text was updated successfully, but these errors were encountered: