diff --git a/Cargo.toml b/Cargo.toml index 519a73e..a05824e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ exclude = [ ] [dependencies] -chrono = { version = "0.4.19", features = ["std", "serde"], default-features = false } +chrono = { version = "0.4.31", features = ["std", "serde"], default-features = false } serde = { version = "1.0.126", features = ["derive"] } serde_json = "1.0.64" lazy_static = "1.4.0" diff --git a/src/entity.rs b/src/entity.rs index 2968946..35cd26b 100755 --- a/src/entity.rs +++ b/src/entity.rs @@ -542,6 +542,8 @@ pub enum EntityError { ExpectedPidString, /// A mainsnak is missing MissingMainsnak, + /// An hour/minute/second is out of bounds. + OutOfBoundsTime, } fn get_json_string(json: Value) -> Result { @@ -622,6 +624,7 @@ fn parse_wb_time(time: &str) -> Result, En }, None => None, }; + #[allow(deprecated)] // TODO: avoid using ymd_opt here let maybe_date = Utc.ymd_opt(year, month.unwrap_or(1), day.unwrap_or(1)); let date = match maybe_date { chrono::offset::LocalResult::Single(date) => date, @@ -650,7 +653,9 @@ fn parse_wb_time(time: &str) -> Result, En } else { (0, 0, 0) }; - Ok(date.and_hms(hour, min, sec)) + Ok(date + .and_hms_opt(hour, min, sec) + .ok_or(EntityError::OutOfBoundsTime)?) } impl ClaimValueData {