Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 8ed8227

Browse files
committed
Improve the error message when DateTime parsing fails verification.
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=150657659
1 parent 7f7a0f6 commit 8ed8227

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
UninitializedLocaleData.throwOnFallback.
1414
* Restore dependency on path which was removed when intl_translation was
1515
separated.
16+
* Improve the error message when date parsing fails validation to show what the
17+
parsed date was.
1618

1719
## 0.14.0
1820
* MAJOR BREAKING CHANGE! Remove message extraction and code generation into a

lib/src/intl/date_format_helpers.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,18 @@ class _DateBuilder {
6666
// check the year, which we otherwise can't verify, and the hours,
6767
// which will catch cases like "14:00:00 PM".
6868
var date = asDate();
69-
_verify(hour24, date.hour, date.hour, "hour", s);
70-
_verify(day, date.day, date.day, "day", s);
71-
_verify(year, date.year, date.year, "year", s);
69+
_verify(hour24, date.hour, date.hour, "hour", s, date);
70+
_verify(day, date.day, date.day, "day", s, date);
71+
_verify(year, date.year, date.year, "year", s, date);
7272
}
7373

74-
_verify(int value, int min, int max, String desc, String originalInput) {
74+
_verify(int value, int min, int max, String desc, String originalInput,
75+
[DateTime parsed]) {
7576
if (value < min || value > max) {
77+
var parsedDescription = parsed == null ? "" : " Date parsed as $parsed.";
7678
throw new FormatException(
7779
"Error parsing $originalInput, invalid $desc value: $value."
78-
" Expected value between $min and $max.");
80+
" Expected value between $min and $max.$parsedDescription");
7981
}
8082
}
8183

0 commit comments

Comments
 (0)