diff --git a/Cargo.lock b/Cargo.lock index 5aaf6b6723..b4819f9f37 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6992,9 +6992,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.34" +version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749" +checksum = "ef89ece63debf11bc32d1ed8d078ac870cbeb44da02afb02a9ff135ae7ca0582" dependencies = [ "deranged", "itoa", @@ -7015,9 +7015,9 @@ checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.17" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", diff --git a/crates/analytics/Cargo.toml b/crates/analytics/Cargo.toml index 2b1cc798a7..c3e35519dc 100644 --- a/crates/analytics/Cargo.toml +++ b/crates/analytics/Cargo.toml @@ -37,5 +37,5 @@ serde_json = "1.0.115" sqlx = { version = "0.7.3", features = ["postgres", "runtime-tokio", "runtime-tokio-native-tls", "time", "bigdecimal"] } strum = { version = "0.26.2", features = ["derive"] } thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } diff --git a/crates/api_models/Cargo.toml b/crates/api_models/Cargo.toml index cdcee9c506..0bd0b01a27 100644 --- a/crates/api_models/Cargo.toml +++ b/crates/api_models/Cargo.toml @@ -30,7 +30,7 @@ reqwest = { version = "0.11.27", optional = true } serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" strum = { version = "0.26", features = ["derive"] } -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } url = { version = "2.5.0", features = ["serde"] } utoipa = { version = "4.2.0", features = ["preserve_order", "preserve_path_order"] } frunk = "0.4.2" diff --git a/crates/cards/Cargo.toml b/crates/cards/Cargo.toml index ab4152893a..ac8a417fb9 100644 --- a/crates/cards/Cargo.toml +++ b/crates/cards/Cargo.toml @@ -14,7 +14,7 @@ error-stack = "0.4.1" luhn = "1.0.1" serde = { version = "1.0.197", features = ["derive"] } thiserror = "1.0.58" -time = "0.3.34" +time = "0.3.35" # First party crates common_utils = { version = "0.1.0", path = "../common_utils" } diff --git a/crates/common_utils/Cargo.toml b/crates/common_utils/Cargo.toml index 285d423958..6f08649fbd 100644 --- a/crates/common_utils/Cargo.toml +++ b/crates/common_utils/Cargo.toml @@ -36,7 +36,7 @@ serde_urlencoded = "0.7.1" signal-hook = { version = "0.3.17", optional = true } strum = { version = "0.26.2", features = ["derive"] } thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"], optional = true } semver = { version = "1.0.22", features = ["serde"] } uuid = { version = "1.8.0", features = ["v7"] } diff --git a/crates/common_utils/src/custom_serde.rs b/crates/common_utils/src/custom_serde.rs index e4608c4f37..79e0c5b85e 100644 --- a/crates/common_utils/src/custom_serde.rs +++ b/crates/common_utils/src/custom_serde.rs @@ -265,3 +265,22 @@ pub mod iso8601custom { }) } } + +#[cfg(test)] +mod tests { + use serde::{Deserialize, Serialize}; + use serde_json::json; + + #[test] + fn test_leap_second_parse() { + #[derive(Serialize, Deserialize)] + struct Try { + #[serde(with = "crate::custom_serde::iso8601")] + f: time::PrimitiveDateTime, + } + let leap_second_date_time = json!({"f": "2023-12-31T23:59:60.000Z"}); + let deser = serde_json::from_value::(leap_second_date_time); + + assert!(deser.is_ok()) + } +} diff --git a/crates/common_utils/src/lib.rs b/crates/common_utils/src/lib.rs index b1a708f7a0..7b8b7bb949 100644 --- a/crates/common_utils/src/lib.rs +++ b/crates/common_utils/src/lib.rs @@ -23,15 +23,15 @@ pub mod validation; /// Date-time utilities. pub mod date_time { + #[cfg(feature = "async_ext")] + use std::time::Instant; use std::{marker::PhantomData, num::NonZeroU8}; use masking::{Deserialize, Serialize}; - #[cfg(feature = "async_ext")] - use time::Instant; use time::{ format_description::{ well_known::iso8601::{Config, EncodedConfig, Iso8601, TimePrecision}, - FormatItem, + BorrowedFormatItem, }, OffsetDateTime, PrimitiveDateTime, }; @@ -68,7 +68,7 @@ pub mod date_time { ) -> (T, f64) { let start = Instant::now(); let result = block().await; - (result, start.elapsed().as_seconds_f64() * 1000f64) + (result, start.elapsed().as_secs_f64() * 1000f64) } /// Return the given date and time in UTC with the given format Eg: format: YYYYMMDDHHmmss Eg: 20191105081132 @@ -76,7 +76,7 @@ pub mod date_time { date: PrimitiveDateTime, format: DateFormat, ) -> Result { - let format = <&[FormatItem<'_>]>::from(format); + let format = <&[BorrowedFormatItem<'_>]>::from(format); date.format(&format) } @@ -90,7 +90,7 @@ pub mod date_time { now().assume_utc().format(&Iso8601::) } - impl From for &[FormatItem<'_>] { + impl From for &[BorrowedFormatItem<'_>] { fn from(format: DateFormat) -> Self { match format { DateFormat::YYYYMMDDHHmmss => time::macros::format_description!("[year repr:full][month padding:zero repr:numerical][day padding:zero][hour padding:zero repr:24][minute padding:zero][second padding:zero]"), diff --git a/crates/data_models/Cargo.toml b/crates/data_models/Cargo.toml index 6da89dc232..54130ca002 100644 --- a/crates/data_models/Cargo.toml +++ b/crates/data_models/Cargo.toml @@ -26,4 +26,4 @@ error-stack = "0.4.1" serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } diff --git a/crates/diesel_models/Cargo.toml b/crates/diesel_models/Cargo.toml index 85533d0cf3..577233cdf1 100644 --- a/crates/diesel_models/Cargo.toml +++ b/crates/diesel_models/Cargo.toml @@ -21,7 +21,7 @@ serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" strum = { version = "0.26.2", features = ["derive"] } thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } # First party crates common_enums = { version = "0.1.0", path = "../common_enums" } diff --git a/crates/router/Cargo.toml b/crates/router/Cargo.toml index 1adecf37c6..8915ab573e 100644 --- a/crates/router/Cargo.toml +++ b/crates/router/Cargo.toml @@ -87,7 +87,7 @@ sqlx = { version = "0.7.3", features = ["postgres", "runtime-tokio", "runtime-to strum = { version = "0.26", features = ["derive"] } tera = "1.19.1" thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } unicode-segmentation = "1.11.0" url = { version = "2.5.0", features = ["serde"] } @@ -135,7 +135,7 @@ awc = { version = "3.4.0", features = ["rustls"] } derive_deref = "1.1.1" rand = "0.8.5" serial_test = "3.0.0" -time = { version = "0.3.34", features = ["macros"] } +time = { version = "0.3.35", features = ["macros"] } tokio = "1.37.0" wiremock = "0.6.0" diff --git a/crates/router_env/Cargo.toml b/crates/router_env/Cargo.toml index 72f0f0b39a..3b95d5f22f 100644 --- a/crates/router_env/Cargo.toml +++ b/crates/router_env/Cargo.toml @@ -20,7 +20,7 @@ serde = { version = "1.0.197", features = ["derive"] } serde_json = "1.0.115" serde_path_to_error = "0.1.16" strum = { version = "0.26.2", features = ["derive"] } -time = { version = "0.3.34", default-features = false, features = ["formatting"] } +time = { version = "0.3.35", default-features = false, features = ["formatting"] } tokio = { version = "1.37.0" } tracing = { version = "0.1.40" } tracing-actix-web = { version = "0.7.10", features = ["opentelemetry_0_19", "uuid_v7"], optional = true } diff --git a/crates/scheduler/Cargo.toml b/crates/scheduler/Cargo.toml index f713b8f2f2..b98f212d67 100644 --- a/crates/scheduler/Cargo.toml +++ b/crates/scheduler/Cargo.toml @@ -23,7 +23,7 @@ serde = "1.0.197" serde_json = "1.0.115" strum = { version = "0.26.2", features = ["derive"] } thiserror = "1.0.58" -time = { version = "0.3.34", features = ["serde", "serde-well-known", "std"] } +time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] } tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] } uuid = { version = "1.8.0", features = ["v4"] } diff --git a/crates/test_utils/Cargo.toml b/crates/test_utils/Cargo.toml index 714e34f0e9..3b0dfe2b91 100644 --- a/crates/test_utils/Cargo.toml +++ b/crates/test_utils/Cargo.toml @@ -24,7 +24,7 @@ serde_json = "1.0.115" serde_urlencoded = "0.7.1" serial_test = "3.0.0" thirtyfour = "0.31.0" -time = { version = "0.3.34", features = ["macros"] } +time = { version = "0.3.35", features = ["macros"] } tokio = "1.37.0" toml = "0.8.12"