summaryrefslogtreecommitdiffstats
path: root/vendor/toml_datetime/src/datetime.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-07 05:48:48 +0000
commitef24de24a82fe681581cc130f342363c47c0969a (patch)
tree0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/toml_datetime/src/datetime.rs
parentReleasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz
rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/toml_datetime/src/datetime.rs')
-rw-r--r--vendor/toml_datetime/src/datetime.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/vendor/toml_datetime/src/datetime.rs b/vendor/toml_datetime/src/datetime.rs
index 15781b915..1b37c7009 100644
--- a/vendor/toml_datetime/src/datetime.rs
+++ b/vendor/toml_datetime/src/datetime.rs
@@ -308,7 +308,15 @@ impl FromStr for Datetime {
if date.month < 1 || date.month > 12 {
return Err(DatetimeParseError {});
}
- if date.day < 1 || date.day > 31 {
+ let is_leap_year =
+ (date.year % 4 == 0) && ((date.year % 100 != 0) || (date.year % 400 == 0));
+ let max_days_in_month = match date.month {
+ 2 if is_leap_year => 29,
+ 2 => 28,
+ 4 | 6 | 9 | 11 => 30,
+ _ => 31,
+ };
+ if date.day < 1 || date.day > max_days_in_month {
return Err(DatetimeParseError {});
}
@@ -381,7 +389,8 @@ impl FromStr for Datetime {
if time.minute > 59 {
return Err(DatetimeParseError {});
}
- if time.second > 59 {
+ // 00-58, 00-59, 00-60 based on leap second rules
+ if time.second > 60 {
return Err(DatetimeParseError {});
}
if time.nanosecond > 999_999_999 {
@@ -451,7 +460,7 @@ impl FromStr for Datetime {
fn digit(chars: &mut str::Chars<'_>) -> Result<u8, DatetimeParseError> {
match chars.next() {
- Some(c) if ('0'..='9').contains(&c) => Ok(c as u8 - b'0'),
+ Some(c) if c.is_ascii_digit() => Ok(c as u8 - b'0'),
_ => Err(DatetimeParseError {}),
}
}