Improve the error message when DateTime parsing fails verification.
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=150657659
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8911a33..816d139 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,8 @@
UninitializedLocaleData.throwOnFallback.
* Restore dependency on path which was removed when intl_translation was
separated.
+ * Improve the error message when date parsing fails validation to show what the
+ parsed date was.
## 0.14.0
* MAJOR BREAKING CHANGE! Remove message extraction and code generation into a
diff --git a/lib/src/intl/date_format_helpers.dart b/lib/src/intl/date_format_helpers.dart
index bc19716..05a6a49 100644
--- a/lib/src/intl/date_format_helpers.dart
+++ b/lib/src/intl/date_format_helpers.dart
@@ -66,16 +66,18 @@
// check the year, which we otherwise can't verify, and the hours,
// which will catch cases like "14:00:00 PM".
var date = asDate();
- _verify(hour24, date.hour, date.hour, "hour", s);
- _verify(day, date.day, date.day, "day", s);
- _verify(year, date.year, date.year, "year", s);
+ _verify(hour24, date.hour, date.hour, "hour", s, date);
+ _verify(day, date.day, date.day, "day", s, date);
+ _verify(year, date.year, date.year, "year", s, date);
}
- _verify(int value, int min, int max, String desc, String originalInput) {
+ _verify(int value, int min, int max, String desc, String originalInput,
+ [DateTime parsed]) {
if (value < min || value > max) {
+ var parsedDescription = parsed == null ? "" : " Date parsed as $parsed.";
throw new FormatException(
"Error parsing $originalInput, invalid $desc value: $value."
- " Expected value between $min and $max.");
+ " Expected value between $min and $max.$parsedDescription");
}
}