Skip to content

Added documentation about out-of-range components to DateTime.parse. #44521

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
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions sdk/lib/core/date_time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,16 @@ class DateTime implements Comparable<DateTime> {
/// * `"2012-02-27T14+00:00"`
/// * `"-123450101 00:00:00 Z"`: in the year -12345.
/// * `"2002-02-27T14:00:00-0500"`: Same as `"2002-02-27T19:00:00Z"`
// TODO(lrn): restrict incorrect values like 2003-02-29T50:70:80.
// Or not, that may be a breaking change.
///
/// 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
/// interprted as 31 days of that month plus 11 days into the next month.
///
/// To detect and reject invalid component values, use
/// [DateFormat.parseStrict](https://pub.dev/documentation/intl/latest/intl/DateFormat/parseStrict.html)
/// from the [intl](https://pub.dev/packages/intl) package.
static DateTime parse(String formattedString) {
var re = _parseFormat;
Match? match = re.firstMatch(formattedString);
Expand Down