From 6fab0d5176d9a636b7efe1adf405a7c66675164e Mon Sep 17 00:00:00 2001 From: zacharyburnett Date: Wed, 17 Jan 2024 11:20:39 -0500 Subject: [PATCH] fix deprecations --- src/configuration/mod.rs | 10 +++++++--- src/location/aprs.rs | 4 ++-- src/utilities.rs | 14 ++++++-------- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index f23399d6..a277cf99 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -183,9 +183,13 @@ mod tests { start: crate::location::Location { coord: geo::coord! { x: -78.4987, y: 40.0157 }, altitude: None, - time: chrono::Local - .datetime_from_str("2022-03-05 10:36:00", &crate::DATETIME_FORMAT) - .unwrap() + time: chrono::NaiveDateTime::parse_from_str( + "2022-03-05 10:36:00", + &crate::DATETIME_FORMAT + ) + .unwrap() + .and_local_timezone(chrono::Local) + .unwrap() }, profile: crate::configuration::prediction::StandardProfile { ascent_rate: 6.5, diff --git a/src/location/aprs.rs b/src/location/aprs.rs index 594281a9..82bec62b 100644 --- a/src/location/aprs.rs +++ b/src/location/aprs.rs @@ -99,7 +99,7 @@ impl crate::location::BalloonLocation { naive_packet_time = now.naive_utc(); } } - packet_time = chrono::DateTime::::from_utc( + packet_time = chrono::DateTime::::from_naive_utc_and_offset( naive_packet_time, chrono::Utc, ) @@ -289,7 +289,7 @@ mod tests { assert_eq!( packet.location.time, - chrono::DateTime::::from_utc( + chrono::DateTime::::from_naive_utc_and_offset( chrono::Utc::now() .date_naive() .and_hms_opt(7, 48, 49) diff --git a/src/utilities.rs b/src/utilities.rs index 64b2a1a2..e1c697da 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -4,7 +4,6 @@ pub fn approx_equal(a: f64, b: f64, decimal_precision: u8) -> bool { } pub mod optional_local_datetime_string { - use chrono::TimeZone; use serde::Deserialize; const FORMAT: &str = "%Y-%m-%d %H:%M:%S"; @@ -32,8 +31,8 @@ pub mod optional_local_datetime_string { if let Some(value) = value { return Ok(Some(match chrono::DateTime::parse_from_rfc3339(&value) { Ok(datetime) => datetime.with_timezone(&chrono::Local), - Err(_) => match chrono::Local.datetime_from_str(&value, FORMAT) { - Ok(datetime) => datetime, + Err(_) => match chrono::NaiveDateTime::parse_from_str(&value, FORMAT) { + Ok(datetime) => datetime.and_local_timezone(chrono::Local).unwrap(), Err(_) => chrono::NaiveDate::parse_from_str(&value, "%Y-%m-%d") .map_err(serde::de::Error::custom)? .and_hms_opt(0, 0, 0) @@ -49,7 +48,6 @@ pub mod optional_local_datetime_string { } pub mod local_datetime_string { - use chrono::TimeZone; use serde::Deserialize; const FORMAT: &str = "%Y-%m-%d %H:%M:%S"; @@ -72,10 +70,10 @@ pub mod local_datetime_string { let value: String = String::deserialize(deserializer)?; Ok(match chrono::DateTime::parse_from_rfc3339(&value) { Ok(datetime) => datetime.with_timezone(&chrono::Local), - Err(_) => match chrono::DateTime::parse_from_str(&value, "%Y-%m-%d %H:%M:%S %Z") { - Ok(datetime) => datetime.with_timezone(&chrono::Local), - Err(_) => match chrono::Local.datetime_from_str(&value, FORMAT) { - Ok(datetime) => datetime, + Err(_) => match chrono::NaiveDateTime::parse_from_str(&value, "%Y-%m-%d %H:%M:%S %Z") { + Ok(datetime) => datetime.and_local_timezone(chrono::Local).unwrap(), + Err(_) => match chrono::NaiveDateTime::parse_from_str(&value, FORMAT) { + Ok(datetime) => datetime.and_local_timezone(chrono::Local).unwrap(), Err(_) => chrono::NaiveDate::parse_from_str(&value, "%Y-%m-%d") .map_err(serde::de::Error::custom)? .and_hms_opt(0, 0, 0)