diff options
Diffstat (limited to 'karld')
-rw-r--r-- | karld/Cargo.toml | 6 | ||||
-rw-r--r-- | karld/src/condition.rs | 37 | ||||
-rw-r--r-- | karld/src/main.rs | 7 |
3 files changed, 28 insertions, 22 deletions
diff --git a/karld/Cargo.toml b/karld/Cargo.toml index 2cfe55b..9495df6 100644 --- a/karld/Cargo.toml +++ b/karld/Cargo.toml @@ -7,12 +7,12 @@ edition = "2021" karlcommon = { path = "../karlcommon" } serde = { version = "1.0.137", features = ["derive"] } -anyhow = "1.0.57" +anyhow = "1.0.66" log = "0.4.17" -env_logger = "0.9.0" +env_logger = "0.10.0" crossbeam-channel = "0.5.4" serde_json = "1.0.81" -chrono = "0.4.19" +chrono = "0.4.23" lazy_static = "1.4.0" tungstenite = { version = "0.17.3", optional = true } diff --git a/karld/src/condition.rs b/karld/src/condition.rs index 643ca5e..2b0d2e3 100644 --- a/karld/src/condition.rs +++ b/karld/src/condition.rs @@ -118,8 +118,8 @@ impl ConditionFind for Condition { None } else { Some(NaiveDateTime::new( - NaiveDate::from_ymd((value + off) as i32, 1, 1), - NaiveTime::from_hms(0, 0, 0), + NaiveDate::from_ymd_opt((value + off) as i32, 1, 1).unwrap(), + NaiveTime::from_hms_opt(0, 0, 0).unwrap(), )) } } @@ -129,21 +129,23 @@ impl ConditionFind for Condition { // month still coming for this year if from.month0() < value as u32 { Some(NaiveDateTime::new( - NaiveDate::from_ymd( + NaiveDate::from_ymd_opt( from.year() + (rollover + dir_off) as i32, value as u32 + 1, 1, - ), - NaiveTime::from_hms(0, 0, 0), + ) + .unwrap(), + NaiveTime::from_hms_opt(0, 0, 0).unwrap(), )) } else { Some(NaiveDateTime::new( - NaiveDate::from_ymd( + NaiveDate::from_ymd_opt( from.year() + (rollover + dir_off + 1) as i32, value as u32 + 1, 1, - ), - NaiveTime::from_hms(0, 0, 0), + ) + .unwrap(), + NaiveTime::from_hms_opt(0, 0, 0).unwrap(), )) } } @@ -183,8 +185,8 @@ impl ConditionFind for Condition { Property::Dayofweek => todo!(), Property::Hour => { let mut target = NaiveDateTime::new( - NaiveDate::from_ymd(from.year(), from.month(), from.day()), - NaiveTime::from_hms(value as u32, 0, 0), + NaiveDate::from_ymd_opt(from.year(), from.month(), from.day()).unwrap(), + NaiveTime::from_hms_opt(value as u32, 0, 0).unwrap(), ); if edge == End { target += Duration::hours(1) @@ -201,8 +203,8 @@ impl ConditionFind for Condition { } Property::Minute => { let mut target = NaiveDateTime::new( - NaiveDate::from_ymd(from.year(), from.month(), from.day()), - NaiveTime::from_hms(from.hour(), value as u32, 0), + NaiveDate::from_ymd_opt(from.year(), from.month(), from.day()).unwrap(), + NaiveTime::from_hms_opt(from.hour(), value as u32, 0).unwrap(), ); if edge == End { target += Duration::minutes(1) @@ -219,8 +221,9 @@ impl ConditionFind for Condition { } Property::Second => { let mut target = NaiveDateTime::new( - NaiveDate::from_ymd(from.year(), from.month(), from.day()), - NaiveTime::from_hms(from.hour(), from.minute(), value as u32), + NaiveDate::from_ymd_opt(from.year(), from.month(), from.day()).unwrap(), + NaiveTime::from_hms_opt(from.hour(), from.minute(), value as u32) + .unwrap(), ); if edge == End { target += Duration::seconds(1) @@ -243,7 +246,7 @@ impl ConditionFind for Condition { if geq(from.timestamp(), (value + off) as i64) { None } else { - Some(NaiveDateTime::from_timestamp(value, 0)) + Some(NaiveDateTime::from_timestamp_opt(value, 0).unwrap()) } } } @@ -258,8 +261,8 @@ impl ConditionFind for Condition { assert_eq!(*modulus, None); assert_eq!(*prop, Property::Unix); assert_eq!(dir, Direction::Forward); - let min = NaiveDateTime::from_timestamp(*min, 0); - let max = NaiveDateTime::from_timestamp(*max, 0); + let min = NaiveDateTime::from_timestamp_opt(*min, 0).unwrap(); + let max = NaiveDateTime::from_timestamp_opt(*max, 0).unwrap(); match edge { Start => { if min < from { diff --git a/karld/src/main.rs b/karld/src/main.rs index 6f92fe5..a1537d1 100644 --- a/karld/src/main.rs +++ b/karld/src/main.rs @@ -104,8 +104,11 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C } } Schedule::Condition(o) => { - let mut time = NaiveDateTime::from_timestamp(range.start.unwrap_or(0), 0); - let end_time = range.end.map(|e| NaiveDateTime::from_timestamp(e, 0)); + let mut time = + NaiveDateTime::from_timestamp_opt(range.start.unwrap_or(0), 0).unwrap(); + let end_time = range + .end + .map(|e| NaiveDateTime::from_timestamp_opt(e, 0).unwrap()); for _ in 0..limit { let start = o.find(condition::Edge::Start, condition::Direction::Forward, time); |