Skip to content

Commit

Permalink
fix deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharyburnett committed Jan 17, 2024
1 parent 7821c7a commit 6fab0d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
10 changes: 7 additions & 3 deletions src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/location/aprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl crate::location::BalloonLocation {
naive_packet_time = now.naive_utc();
}
}
packet_time = chrono::DateTime::<chrono::Utc>::from_utc(
packet_time = chrono::DateTime::<chrono::Utc>::from_naive_utc_and_offset(
naive_packet_time,
chrono::Utc,
)
Expand Down Expand Up @@ -289,7 +289,7 @@ mod tests {

assert_eq!(
packet.location.time,
chrono::DateTime::<chrono::Local>::from_utc(
chrono::DateTime::<chrono::Local>::from_naive_utc_and_offset(
chrono::Utc::now()
.date_naive()
.and_hms_opt(7, 48, 49)
Expand Down
14 changes: 6 additions & 8 deletions src/utilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand All @@ -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";
Expand All @@ -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)
Expand Down

0 comments on commit 6fab0d5

Please sign in to comment.