Skip to content

DateTime.tryParse parses invalid dates, substituting a valid date #50083

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

Closed
WorikQCI opened this issue Sep 29, 2022 · 3 comments
Closed

DateTime.tryParse parses invalid dates, substituting a valid date #50083

WorikQCI opened this issue Sep 29, 2022 · 3 comments

Comments

@WorikQCI
Copy link

DateTime.tryParse("2022-02-34")
DateTime (2022-03-06 00:00:00.000)

The input string was invalid. The correct value to return is null

  • Dart core libraries ("dart:async", "dart:io", etc.)

This the correct place?

% dart --version
Dart SDK version: 2.18.1 (stable) (Tue Sep 13 11:42:55 2022 +0200) on "macos_arm64"
@Cat-sushi
Copy link

parse method - DateTime class - dart:core library - Dart API says :

This method accepts out-of-range component values and interprets them as overflows into the next larger component. For example, "2020-01-42" will be parsed as 2020-02-11, because the last valid date in that month is 2020-01-31, so 42 days is interpreted as 31 days of that month plus 11 days into the next month.

@lrhn
Copy link
Member

lrhn commented Sep 29, 2022

See #11189

We decided at some point to not try to be strict here.

@lrhn lrhn closed this as completed Sep 29, 2022
@WorikQCI
Copy link
Author

What a terrible idea.

There is no valid output for invalid input

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

3 participants