Skip to content

Commit 84e43af

Browse files
RUST-1960 Make large-dates time feature optional (#546)
1 parent f2c07cd commit 84e43af

File tree

6 files changed

+20
-2
lines changed

6 files changed

+20
-2
lines changed

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ default = ["compat-3-0-0"]
3737
compat-3-0-0 = []
3838
# if enabled, include API for interfacing with chrono 0.4
3939
chrono-0_4 = ["dep:chrono"]
40+
# enable the large-dates feature for the time crate
41+
large_dates = ["time/large-dates"]
4042
# if enabled, include API for interfacing with uuid 1.x
4143
uuid-1 = []
4244
# if enabled, include API for interfacing with time 0.3
@@ -62,7 +64,7 @@ once_cell = "1.5.1"
6264
uuid = { version = "1.1.2", features = ["serde", "v4"] }
6365
serde_bytes = "0.11.5"
6466
serde_with = { version = "3.1.0", optional = true }
65-
time = { version = "0.3.9", features = ["formatting", "parsing", "macros", "large-dates"] }
67+
time = { version = "0.3.9", features = ["formatting", "parsing", "macros"] }
6668
bitvec = "1.0.1"
6769
serde_path_to_error = { version = "0.1.16", optional = true }
6870
simdutf8 = "0.1.5"

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ Note that if you are using `bson` through the `mongodb` crate, you do not need t
5252
| `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 |
5353
| `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 |
5454
| `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 |
55-
| `compat-3-0-0` | Required for future compatibility if default features are disabled. | no |
55+
| `compat-3-0-0` | Required for future compatibility if default features are disabled. | n/a | no |
56+
| `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 |
5657

5758
## Overview of the BSON Format
5859

src/datetime.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ use serde::{Deserialize, Deserializer, Serialize};
174174
/// # }
175175
/// # Ok::<(), Box<dyn std::error::Error>>(())
176176
/// ```
177+
///
178+
/// ## Large Dates
179+
/// The range of dates supported by `DateTime` is defined by [`DateTime::MIN`] and
180+
/// [`DateTime::MAX`]. However, some utilities for constructing and converting `DateTimes`, such as
181+
/// interop with the [`time::OffsetDateTime`] type and with RFC 3339 strings, are bounded by the
182+
/// [`time`] crate's supported date range. The `large_dates` feature can be enabled to expand this
183+
/// range, which enables the
184+
/// [`large-dates` feature for `time`](https://docs.rs/time/latest/time/#feature-flags).
177185
#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Copy, Clone)]
178186
pub struct DateTime(i64);
179187

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
//! | `serde_with-3` | Enable [`serde_with`](https://docs.rs/serde_with/3.x) 3.x integrations for [`DateTime`] and [`Uuid`]. | no |
6868
//! | `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 |
6969
//! | `compat-3-0-0` | Required for future compatibility if default features are disabled. | no |
70+
//! | `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 |
7071
//!
7172
//! ## BSON values
7273
//!

src/tests/datetime.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn datetime_to_rfc3339() {
3737
}
3838

3939
#[test]
40+
#[cfg(feature = "large_dates")]
4041
fn invalid_datetime_to_rfc3339() {
4142
assert!(crate::DateTime::MAX.try_to_rfc3339_string().is_err());
4243
}

src/tests/spec/corpus.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ where
100100
fn run_test(test: TestFile) {
101101
let _guard = LOCK.run_concurrently();
102102
for valid in test.valid {
103+
#[cfg(not(feature = "large_dates"))]
104+
if valid.description == "Y10K" {
105+
continue;
106+
}
107+
103108
let description = format!("{}: {}", test.description, valid.description);
104109

105110
let canonical_bson = hex::decode(&valid.canonical_bson).expect(&description);

0 commit comments

Comments
 (0)