diff --git a/Cargo.toml b/Cargo.toml index 60d9fe2..b788ba5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ reqwest-middleware = "*" rand = {version="*", default_features = false, features = ["std", "std_rng", "getrandom"]} # to perform time-based calculations -time = {version="*", default_features = false, features = ["formatting", "parsing", "macros", "serde"]} +time = {version="*", default_features = false, features = ["formatting", "parsing", "macros", "serde", "serde-well-known"]} # compute distances between geo-points geoutils = {version="*", default_features = false} diff --git a/src/icao_to_trace.rs b/src/icao_to_trace.rs index 9e7e4e0..1fb84d9 100644 --- a/src/icao_to_trace.rs +++ b/src/icao_to_trace.rs @@ -5,7 +5,7 @@ use reqwest::{self, StatusCode}; use reqwest_middleware::ClientBuilder; use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware}; use time::Date; -use time::PrimitiveDateTime; +use time::OffsetDateTime; use super::Position; use crate::{fs, fs_s3}; @@ -174,7 +174,7 @@ pub async fn positions( trace.into_iter().filter_map(move |entry| { let time_seconds = entry[0].as_f64().unwrap(); let time = time::Time::MIDNIGHT + time_seconds.seconds(); - let datetime = PrimitiveDateTime::new(date.clone(), time); + let datetime = OffsetDateTime::new_utc(date.clone(), time); let latitude = entry[1].as_f64().unwrap(); let longitude = entry[2].as_f64().unwrap(); entry[3] diff --git a/src/lib.rs b/src/lib.rs index 1f46689..a9fe062 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,8 @@ pub use private_emissions::*; /// A position of an aircraft #[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] pub struct Position { - datetime: time::PrimitiveDateTime, + #[serde(with = "time::serde::rfc3339")] + datetime: time::OffsetDateTime, latitude: f64, longitude: f64, /// None means on the ground @@ -65,7 +66,7 @@ impl Position { self.altitude.unwrap_or(0.0) } - pub fn datetime(&self) -> time::PrimitiveDateTime { + pub fn datetime(&self) -> time::OffsetDateTime { self.datetime } diff --git a/tests/it/main.rs b/tests/it/main.rs index 009ab65..841d0fc 100644 --- a/tests/it/main.rs +++ b/tests/it/main.rs @@ -86,6 +86,8 @@ async fn ads_b_lost_on_ground() -> Result<(), Box> { Ok(()) } +/// Verifies that condition 2. of `M-4` is correctly applied. +/// https://globe.adsbexchange.com/?icao=459257&showTrace=2023-12-17 #[tokio::test] async fn case_459257_2023_12_17() -> Result<(), Box> { let legs = legs(date!(2023 - 12 - 17), date!(2023 - 12 - 20), "459257", None).await?;