66
77#[ cfg( feature = "unstable" ) ]
88pub use unstable:: {
9- DateAddOptions , DateDifferenceOptions , DateFromFieldsOptions , MissingFieldsStrategy , Overflow ,
9+ DateAddOptions , DateDifferenceOptions , DateDurationUnit , DateFromFieldsOptions ,
10+ MissingFieldsStrategy , Overflow ,
1011} ;
1112#[ cfg( not( feature = "unstable" ) ) ]
1213pub ( crate ) use unstable:: {
13- DateAddOptions , DateDifferenceOptions , DateFromFieldsOptions , MissingFieldsStrategy , Overflow ,
14+ DateAddOptions , DateDifferenceOptions , DateDurationUnit , DateFromFieldsOptions ,
15+ MissingFieldsStrategy , Overflow ,
1416} ;
1517
1618mod unstable {
@@ -177,12 +179,15 @@ mod unstable {
177179 /// associative or commutative in subsequent arithmetic operations, and it might require
178180 /// [`Overflow::Constrain`] in addition.
179181 ///
182+ /// The resultant duration will not have any `weeks` value unless [`DateDurationUnit::Weeks`]
183+ /// is explicitly specified as `largest_unit`.
184+ ///
180185 /// # Examples
181186 ///
182187 /// ```
183188 /// use icu::calendar::options::DateDifferenceOptions;
184189 /// use icu::calendar::types::DateDuration;
185- /// use icu::calendar::types ::DateDurationUnit;
190+ /// use icu::calendar::options ::DateDurationUnit;
186191 /// use icu::calendar::Date;
187192 ///
188193 /// let d1 = Date::try_new_iso(2025, 3, 31).unwrap();
@@ -206,6 +211,7 @@ mod unstable {
206211 /// assert_eq!(
207212 /// d1.try_until_with_options(&d2, options_weeks).unwrap(),
208213 /// DateDuration {
214+ /// // This is the only time there is a `weeks` value.
209215 /// weeks: 58,
210216 /// days: 4,
211217 /// ..Default::default()
@@ -236,10 +242,10 @@ mod unstable {
236242 /// );
237243 /// ```
238244 ///
239- /// [`Months`]: crate::types ::DateDurationUnit::Months
240- /// [`Years`]: crate::types ::DateDurationUnit::Years
245+ /// [`Months`]: crate::options ::DateDurationUnit::Months
246+ /// [`Years`]: crate::options ::DateDurationUnit::Years
241247 /// [`DateDuration`]: crate::types::DateDuration
242- pub largest_unit : Option < crate :: duration :: DateDurationUnit > ,
248+ pub largest_unit : Option < DateDurationUnit > ,
243249 }
244250
245251 /// Whether to constrain or reject out-of-bounds values when constructing a Date.
@@ -410,6 +416,30 @@ mod unstable {
410416 /// the identity of an ordinal month changes from year to year.
411417 Ecma ,
412418 }
419+
420+ /// A "duration unit" used to specify the minimum or maximum duration of time to
421+ /// care about.
422+ ///
423+ /// <div class="stab unstable">
424+ /// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
425+ /// including in SemVer minor releases. Do not use this type unless you are prepared for things to occasionally break.
426+ ///
427+ /// Graduation tracking issue: [issue #3964](https://github.com/unicode-org/icu4x/issues/3964).
428+ /// </div>
429+ ///
430+ /// ✨ *Enabled with the `unstable` Cargo feature.*
431+ #[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
432+ #[ allow( clippy:: exhaustive_enums) ] // this type should be stable
433+ pub enum DateDurationUnit {
434+ /// Duration in years
435+ Years ,
436+ /// Duration in months
437+ Months ,
438+ /// Duration in weeks
439+ Weeks ,
440+ /// Duration in days
441+ Days ,
442+ }
413443}
414444#[ cfg( test) ]
415445mod tests {
0 commit comments