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 f52110c commit 7788a7e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 6 additions & 3 deletions src/configuration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ 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::DateTime::parse_from_str(
"2022-03-05 10:36:00",
&crate::DATETIME_FORMAT
)
.unwrap()
.with_timezone(&chrono::Local)
},
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
10 changes: 4 additions & 6 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::DateTime::parse_from_str(&value, FORMAT) {
Ok(datetime) => datetime.with_timezone(&chrono::Local),
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 @@ -74,8 +72,8 @@ pub mod local_datetime_string {
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::DateTime::parse_from_str(&value, FORMAT) {
Ok(datetime) => datetime.with_timezone(&chrono::Local),
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 7788a7e

Please sign in to comment.