Skip to content

Commit b1ce9b5

Browse files
committed
fix(datetime): Use 2-digit values for ranges
1 parent 55da4af commit b1ce9b5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

crates/toml_datetime/src/datetime.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ impl FromStr for Datetime {
395395
if date.month < 1 || date.month > 12 {
396396
return Err(DatetimeParseError::new()
397397
.what("date")
398-
.expected("month between 1 and 12"));
398+
.expected("month between 01 and 12"));
399399
}
400400
let is_leap_year =
401401
(date.year % 4 == 0) && ((date.year % 100 != 0) || (date.year % 400 == 0));
402402
let (max_days_in_month, expected_day) = match date.month {
403-
2 if is_leap_year => (29, "day between 1 and 29"),
404-
2 => (28, "day between 1 and 28"),
405-
4 | 6 | 9 | 11 => (30, "day between 1 and 30"),
406-
_ => (31, "day between 1 and 31"),
403+
2 if is_leap_year => (29, "day between 01 and 29"),
404+
2 => (28, "day between 01 and 28"),
405+
4 | 6 | 9 | 11 => (30, "day between 01 and 30"),
406+
_ => (31, "day between 01 and 31"),
407407
};
408408
if date.day < 1 || date.day > max_days_in_month {
409409
return Err(DatetimeParseError::new()
@@ -516,18 +516,18 @@ impl FromStr for Datetime {
516516
if time.hour > 23 {
517517
return Err(DatetimeParseError::new()
518518
.what("time")
519-
.expected("hour between 0 and 23"));
519+
.expected("hour between 00 and 23"));
520520
}
521521
if time.minute > 59 {
522522
return Err(DatetimeParseError::new()
523523
.what("time")
524-
.expected("minute between 0 and 59"));
524+
.expected("minute between 00 and 59"));
525525
}
526526
// 00-58, 00-59, 00-60 based on leap second rules
527527
if time.second > 60 {
528528
return Err(DatetimeParseError::new()
529529
.what("time")
530-
.expected("second between 0 and 60"));
530+
.expected("second between 00 and 60"));
531531
}
532532
if time.nanosecond > 999_999_999 {
533533
return Err(DatetimeParseError::new()
@@ -589,12 +589,12 @@ impl FromStr for Datetime {
589589
if hours > 23 {
590590
return Err(DatetimeParseError::new()
591591
.what("offset")
592-
.expected("hours between 0 and 23"));
592+
.expected("hours between 00 and 23"));
593593
}
594594
if minutes > 59 {
595595
return Err(DatetimeParseError::new()
596596
.what("offset")
597-
.expected("minutes between 0 and 59"));
597+
.expected("minutes between 00 and 59"));
598598
}
599599

600600
let total_minutes = sign * (hours as i16 * 60 + minutes as i16);

0 commit comments

Comments
 (0)