diff options
Diffstat (limited to 'karld/src/condition.rs')
-rw-r--r-- | karld/src/condition.rs | 37 |
1 files changed, 20 insertions, 17 deletions
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 { |