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

FormatException on specific date and time (very strange) #483

Closed
akhatriST opened this issue Mar 20, 2023 · 8 comments · Fixed by #698
Closed

FormatException on specific date and time (very strange) #483

akhatriST opened this issue Mar 20, 2023 · 8 comments · Fixed by #698
Labels
P3 A lower priority bug or feature request package:intl type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@akhatriST
Copy link

Describe the bug
Getting the following exception on this specific date range only i.e. 23-03-12 02:00:00 to 23-03-12 02:59:59 with the following message

FormatException: Error parsing 23-03-12 02:00:00, invalid hour value: 2 in en_US with time zone offset -4:00:00.000000. Expected value between 3 and 3. Date parsed as 0023-03-12 03:00:00.000..

To Reproduce
The timezone should be either UTC -4, -5, -6, -7 and running a local test as following will reproduce it. Please note that this works fine for all the time windows except 02:00:00 till 02:59:59

void main(List<String> arguments) {
    String date = "23-03-12 02:00:00";
    DateTime? dateTime = DateFormat('y-MM-dd HH:mm:ss').parseStrict(date).toLocal();
}

Expected
The library should work as expected on the above mentioned time range.

@mosuem
Copy link
Member

mosuem commented Mar 27, 2023

This can be reproduced with

DateFormat('yy').parseStrict("23");

as the verify method checks if the year is valid, where 23 is not in the valid range of 2023 to 2023.

This should be fixed by adapting the validation code to check for the _hasAmbiguousCentury variable.

@mosuem mosuem added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P3 A lower priority bug or feature request labels Mar 27, 2023
@akhatriST
Copy link
Author

The issue I am facing is due to the Daylight saving adjustment in the mentioned timezones, which occurs on 12 March every year, hence the verify method fails because there is no consideration of Daylight saving.

@mosuem
Copy link
Member

mosuem commented Mar 27, 2023

I am not sure I understand - the problem you described in the first post is reproducible without any specific reference to a time, just using the year. Could you elaborate?

@akhatriST
Copy link
Author

The issue I am facing is specific to the time (particularly hour) and not the year. If you try to parse this date 23-03-12 02:00:00 with this format y-MM-dd HH:mm:ss then the time returned is DayLight saving adjusted, i.e. 23-03-12 03:00:00 which then goes through the series of verify checks as I am using the DateFormat.parseStrict method. It fails to verify the Hour field and throws the FormatException with the following Stack trace;

DateBuilder._verify (date_builder.dart:159)
DateBuilder.verify (date_builder.dart:131)
DateFormat._parse (date_format.dart:400)
DateFormat.parseStrict (date_format.dart:384)
Data.getDate (data.dart:875)

Hope the above stack trace helps.

@mosuem
Copy link
Member

mosuem commented Mar 27, 2023

The format y-MM-dd HH:mm:ss would expect the date to be 2023-03-12 02:00:00, which then works. Does this solve your problem?

@alan-knight
Copy link
Contributor

alan-knight commented Mar 27, 2023 via email

@mosuem mosuem transferred this issue from dart-archive/intl Apr 18, 2023
@slgobinath
Copy link

Facing the same error in Eastern Timezone. Any fix?

@mosuem
Copy link
Member

mosuem commented Jun 12, 2023

The error is that this DateTime does not exist, so there is no fix for this. This issue is open for fixing #483 (comment).

@mosuem mosuem mentioned this issue Aug 10, 2023
1 task
copybara-service bot pushed a commit that referenced this issue Aug 23, 2023
--
74641d7 by Moritz <[email protected]>:

Fix #483

--
f21ac06 by Moritz <[email protected]>:

Add changelog

--
7613552 by Moritz <[email protected]>:

Changes as per review

PiperOrigin-RevId: 559577268
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 A lower priority bug or feature request package:intl type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants