From 08ca335492435b4b8110fd3982af322ce43e99d7 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Mon, 31 Jul 2023 16:37:21 +0200 Subject: [PATCH] Clarify serialization behavior of Duration* and Timestamp* types Closes #625 --- serde_with/src/lib.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/serde_with/src/lib.rs b/serde_with/src/lib.rs index ce2f6438..e350ff96 100644 --- a/serde_with/src/lib.rs +++ b/serde_with/src/lib.rs @@ -797,6 +797,7 @@ pub struct BytesOrString; /// [`formats::Strict`] means that deserialization only supports the type given in `FORMAT`, e.g., if `FORMAT` is `u64` deserialization from a `f64` will error. /// [`formats::Flexible`] means that deserialization will perform a best effort to extract the correct duration and allows deserialization from any type. /// For example, deserializing `DurationSeconds` will discard any subsecond precision during deserialization from `f64` and will parse a `String` as an integer number. +/// Serialization of integers will round the duration to the nearest value. /// /// This type also supports [`chrono::Duration`] with the `chrono_0_4`-[feature flag]. /// This type also supports [`time::Duration`][::time_0_3::Duration] with the `time_0_3`-[feature flag]. @@ -937,6 +938,7 @@ pub struct DurationSeconds< /// De/serialize durations as number of seconds with subsecond precision. /// Subsecond precision is *only* supported for [`DurationSecondsWithFrac`], but not for [`DurationSeconds`]. /// You can configure the serialization format between integers, floats, and stringified numbers with the `FORMAT` specifier and configure the deserialization with the `STRICTNESS` specifier. +/// Serialization of integers will round the duration to the nearest value. /// /// The `STRICTNESS` specifier can either be [`formats::Strict`] or [`formats::Flexible`] and defaults to [`formats::Strict`]. /// [`formats::Strict`] means that deserialization only supports the type given in `FORMAT`, e.g., if `FORMAT` is `u64` deserialization from a `f64` will error. @@ -1116,6 +1118,7 @@ pub struct DurationNanoSecondsWithFrac< /// De/serialize timestamps as seconds since the UNIX epoch. /// Subsecond precision is *only* supported for [`TimestampSecondsWithFrac`], but not for [`TimestampSeconds`]. /// You can configure the serialization format between integers, floats, and stringified numbers with the `FORMAT` specifier and configure the deserialization with the `STRICTNESS` specifier. +/// Serialization of integers will round the timestamp to the nearest value. /// /// The `STRICTNESS` specifier can either be [`formats::Strict`] or [`formats::Flexible`] and defaults to [`formats::Strict`]. /// [`formats::Strict`] means that deserialization only supports the type given in `FORMAT`, e.g., if `FORMAT` is `i64` deserialization from a `f64` will error. @@ -1269,6 +1272,7 @@ pub struct TimestampSeconds< /// De/serialize timestamps as seconds since the UNIX epoch. /// Subsecond precision is *only* supported for [`TimestampSecondsWithFrac`], but not for [`TimestampSeconds`]. /// You can configure the serialization format between integers, floats, and stringified numbers with the `FORMAT` specifier and configure the deserialization with the `STRICTNESS` specifier. +/// Serialization of integers will round the timestamp to the nearest value. /// /// The `STRICTNESS` specifier can either be [`formats::Strict`] or [`formats::Flexible`] and defaults to [`formats::Strict`]. /// [`formats::Strict`] means that deserialization only supports the type given in `FORMAT`, e.g., if `FORMAT` is `i64` deserialization from a `f64` will error.