From 7905f761123da37f112a53e157342d2c54d96041 Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Mon, 2 Jun 2025 15:51:48 -0400 Subject: [PATCH 1/4] RUST-1960 Make large-dates time feature optional --- Cargo.toml | 4 +++- README.md | 3 ++- src/lib.rs | 1 + src/tests/spec/corpus.rs | 5 +++++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 44c2eb37..c609a4e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,6 +37,8 @@ default = ["compat-3-0-0"] compat-3-0-0 = [] # if enabled, include API for interfacing with chrono 0.4 chrono-0_4 = ["dep:chrono"] +# enable the large-dates feature for the time crate +large_dates = ["time/large-dates"] # if enabled, include API for interfacing with uuid 1.x uuid-1 = [] # if enabled, include API for interfacing with time 0.3 @@ -62,7 +64,7 @@ once_cell = "1.5.1" uuid = { version = "1.1.2", features = ["serde", "v4"] } serde_bytes = "0.11.5" serde_with = { version = "3.1.0", optional = true } -time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] } +time = { version = "0.3.9", features = ["formatting", "parsing", "macros"] } bitvec = "1.0.1" serde_path_to_error = { version = "0.1.16", optional = true } diff --git a/README.md b/README.md index bbbd6c86..1a099149 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,8 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t | `time-0_3` | Enable support for v0.3 of the [`time`](https://docs.rs/time/0.3) crate in the public API. | n/a | no | | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no | | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | serde_path_to_error | no | -| `compat-3-0-0` | Required for future compatibility if default features are disabled. | no | +| `compat-3-0-0` | Required for future compatibility if default features are disabled. | n/a | no | +| `large_dates` | Increase the supported year range for `bson::DateTime` from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | n/a | no | ## Overview of the BSON Format diff --git a/src/lib.rs b/src/lib.rs index 93884fba..26739572 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,6 +67,7 @@ //! | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for [`DateTime`] and [`Uuid`]. | no | //! | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | no | //! | `compat-3-0-0` | Required for future compatibility if default features are disabled. | no | +//! | `large_dates` | Increase the supported year range for `bson::DateTime` from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | no | //! //! ## BSON values //! diff --git a/src/tests/spec/corpus.rs b/src/tests/spec/corpus.rs index 796d1a70..60457417 100644 --- a/src/tests/spec/corpus.rs +++ b/src/tests/spec/corpus.rs @@ -100,6 +100,11 @@ where fn run_test(test: TestFile) { let _guard = LOCK.run_concurrently(); for valid in test.valid { + #[cfg(not(feature = "large_dates"))] + if test.description == "Y10K" { + continue; + } + let description = format!("{}: {}", test.description, valid.description); let canonical_bson = hex::decode(&valid.canonical_bson).expect(&description); From be8f19723610e5382f36d520aec94abd955c5aaa Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Tue, 3 Jun 2025 11:50:01 -0400 Subject: [PATCH 2/4] improve docs --- README.md | 2 +- src/datetime.rs | 8 ++++++++ src/lib.rs | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a099149..fffa70bf 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for `bson::DateTime` and `bson::Uuid`.| serde_with | no | | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | serde_path_to_error | no | | `compat-3-0-0` | Required for future compatibility if default features are disabled. | n/a | no | -| `large_dates` | Increase the supported year range for `bson::DateTime` from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | n/a | no | +| `large_dates` | Increase the supported year range for some `bson::DateTime` utilities from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | n/a | no | ## Overview of the BSON Format diff --git a/src/datetime.rs b/src/datetime.rs index c14c37ad..5a7255c1 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -174,6 +174,14 @@ use serde::{Deserialize, Deserializer, Serialize}; /// # } /// # Ok::<(), Box>(()) /// ``` +/// +/// ## Large Dates +/// The range of dates supported by `DateTime` are defined by [`DateTime::MIN`] and +/// [`DateTime::MAX`]. However, some utilities for constructing and converting `DateTimes`, such as +/// interop with the [`time::OffsetDateTime`] type and with RFC 3339 strings, are bounded by the +/// [`time`] crate's supported date range. The `large_dates` feature can be enabled to expand this +/// range, which enables the +/// [`large-dates` feature for `time`](https://docs.rs/time/latest/time/#feature-flags). #[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)] pub struct DateTime(i64); diff --git a/src/lib.rs b/src/lib.rs index 26739572..7906e58e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ //! | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for [`DateTime`] and [`Uuid`]. | no | //! | `serde_path_to_error` | Enable support for error paths via integration with [`serde_path_to_error`](https://docs.rs/serde_path_to_err/latest). This is an unstable feature and any breaking changes to `serde_path_to_error` may affect usage of it via this feature. | no | //! | `compat-3-0-0` | Required for future compatibility if default features are disabled. | no | -//! | `large_dates` | Increase the supported year range for `bson::DateTime` from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | no | +//! | `large_dates` | Increase the supported year range for some `bson::DateTime` utilities from +/-9,999 (inclusive) to +/-999,999 (inclusive). Note that enabling this feature can impact performance and introduce parsing ambiguities. | no | //! //! ## BSON values //! From ee7ff7521b3a31e2d11722706b7fb888d09b8c74 Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Tue, 3 Jun 2025 11:55:42 -0400 Subject: [PATCH 3/4] skip tests --- src/tests/datetime.rs | 1 + src/tests/spec/corpus.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/tests/datetime.rs b/src/tests/datetime.rs index 56bba311..e69c24c8 100644 --- a/src/tests/datetime.rs +++ b/src/tests/datetime.rs @@ -37,6 +37,7 @@ fn datetime_to_rfc3339() { } #[test] +#[cfg(feature = "large_dates")] fn invalid_datetime_to_rfc3339() { assert!(crate::DateTime::MAX.try_to_rfc3339_string().is_err()); } diff --git a/src/tests/spec/corpus.rs b/src/tests/spec/corpus.rs index 60457417..93bc3220 100644 --- a/src/tests/spec/corpus.rs +++ b/src/tests/spec/corpus.rs @@ -101,7 +101,7 @@ fn run_test(test: TestFile) { let _guard = LOCK.run_concurrently(); for valid in test.valid { #[cfg(not(feature = "large_dates"))] - if test.description == "Y10K" { + if valid.description == "Y10K" { continue; } From e0e343097ee4a303a5ef81f287388382b792911d Mon Sep 17 00:00:00 2001 From: Isabel Atkinson Date: Tue, 3 Jun 2025 12:05:06 -0400 Subject: [PATCH 4/4] noun-verb agreement --- src/datetime.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/datetime.rs b/src/datetime.rs index 5a7255c1..eca1522b 100644 --- a/src/datetime.rs +++ b/src/datetime.rs @@ -176,7 +176,7 @@ use serde::{Deserialize, Deserializer, Serialize}; /// ``` /// /// ## Large Dates -/// The range of dates supported by `DateTime` are defined by [`DateTime::MIN`] and +/// The range of dates supported by `DateTime` is defined by [`DateTime::MIN`] and /// [`DateTime::MAX`]. However, some utilities for constructing and converting `DateTimes`, such as /// interop with the [`time::OffsetDateTime`] type and with RFC 3339 strings, are bounded by the /// [`time`] crate's supported date range. The `large_dates` feature can be enabled to expand this