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..fffa70bf 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 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..eca1522b 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` 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 +/// 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 93884fba..7906e58e 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 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 //! 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 796d1a70..93bc3220 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 valid.description == "Y10K" { + continue; + } + let description = format!("{}: {}", test.description, valid.description); let canonical_bson = hex::decode(&valid.canonical_bson).expect(&description);