Skip to content

Commit b7b7896

Browse files
committed
calendar
1 parent affe02e commit b7b7896

File tree

17 files changed

+113
-73
lines changed

17 files changed

+113
-73
lines changed

components/calendar/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ datagen = ["serde", "dep:databake", "zerovec/databake", "tinystr/databake", "all
5656
compiled_data = ["dep:icu_calendar_data", "dep:icu_locale", "icu_locale?/compiled_data", "icu_provider/baked"]
5757

5858
alloc = []
59+
unstable = []
5960

6061
[[bench]]
6162
name = "date"

components/calendar/src/any_calendar.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,8 @@ impl AnyCalendar {
648648
}
649649

650650
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
651+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
652+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
651653
pub fn try_new_unstable<P>(provider: &P, kind: AnyCalendarKind) -> Result<Self, DataError>
652654
where
653655
P: DataProvider<crate::provider::CalendarJapaneseModernV1>
@@ -903,29 +905,49 @@ impl fmt::Display for AnyCalendarKind {
903905
}
904906

905907
/// Trait for calendars that may be converted to [`AnyCalendar`]
908+
///
909+
/// <div class="stab unstable">
910+
/// 🚫 This trait is sealed; it should not be implemented by user code. If an API requests an item that implements this
911+
/// trait, please consider using a type from the implementors listed below.
912+
///
913+
/// It is still possible to implement this trait in userland (since `UnstableSealed` is public),
914+
/// do not do so unless you are prepared for things to occasionally break.
915+
/// </div>
906916
pub trait IntoAnyCalendar: Calendar + Sized {
907917
/// Convert this calendar into an [`AnyCalendar`], moving it
908918
///
909919
/// You should not need to call this method directly
920+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
921+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
910922
fn to_any(self) -> AnyCalendar;
911923

912924
/// The [`AnyCalendarKind`] enum variant associated with this calendar
925+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
926+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
913927
fn kind(&self) -> AnyCalendarKind;
914928

915929
/// Move an [`AnyCalendar`] into a `Self`, or returning it as an error
930+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
931+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
916932
/// if the types do not match.
917933
///
918934
/// You should not need to call this method directly
935+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
936+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
919937
fn from_any(any: AnyCalendar) -> Result<Self, AnyCalendar>;
920938

921939
/// Convert an [`AnyCalendar`] reference into a `Self` reference.
922940
///
923941
/// You should not need to call this method directly
942+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
943+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
924944
fn from_any_ref(any: &AnyCalendar) -> Option<&Self>;
925945

926946
/// Convert a date for this calendar into an `AnyDateInner`
927947
///
928948
/// You should not need to call this method directly
949+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
950+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
929951
fn date_to_any(&self, d: &Self::DateInner) -> AnyDateInner;
930952
}
931953

components/calendar/src/cal/chinese.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ impl Chinese {
133133
]);
134134

135135
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
136+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
137+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
136138
pub fn try_new_unstable<D: DataProvider<CalendarChineseV1> + ?Sized>(
137139
provider: &D,
138140
) -> Result<Self, DataError> {
@@ -216,12 +218,14 @@ impl Calendar for Chinese {
216218
date.0.days_in_month()
217219
}
218220

219-
#[doc(hidden)] // unstable
221+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
222+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
220223
fn offset_date(&self, date: &mut Self::DateInner, offset: DateDuration<Self>) {
221224
date.0.offset_date(offset, &self.get_precomputed_data());
222225
}
223226

224-
#[doc(hidden)] // unstable
227+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
228+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
225229
#[allow(clippy::field_reassign_with_default)]
226230
/// Calculate `date2 - date` as a duration
227231
///

components/calendar/src/cal/dangi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ impl Dangi {
131131
]);
132132

133133
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
134+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
135+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
134136
pub fn try_new_unstable<D: DataProvider<CalendarDangiV1> + ?Sized>(
135137
provider: &D,
136138
) -> Result<Self, DataError> {

components/calendar/src/cal/hijri.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ impl HijriSimulated {
142142
]);
143143

144144
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new_mecca)]
145+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
146+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
145147
pub fn try_new_mecca_unstable<D: DataProvider<CalendarHijriSimulatedMeccaV1> + ?Sized>(
146148
provider: &D,
147149
) -> Result<Self, DataError> {

components/calendar/src/cal/japanese.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ impl Japanese {
118118
]);
119119

120120
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
121+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
122+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
121123
pub fn try_new_unstable<D: DataProvider<CalendarJapaneseModernV1> + ?Sized>(
122124
provider: &D,
123125
) -> Result<Self, DataError> {
@@ -151,6 +153,8 @@ impl JapaneseExtended {
151153
]);
152154

153155
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
156+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
157+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
154158
pub fn try_new_unstable<D: DataProvider<CalendarJapaneseExtendedV1> + ?Sized>(
155159
provider: &D,
156160
) -> Result<Self, DataError> {

components/calendar/src/cal/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ pub use roc::Roc;
3939
pub use crate::any_calendar::{AnyCalendar, AnyCalendarKind};
4040

4141
/// Internal scaffolding types
42+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
43+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
4244
pub mod scaffold {
4345
/// Trait marking other traits that are considered unstable and should not generally be
4446
/// implemented outside of the calendar crate.
45-
///
46-
/// <div class="stab unstable">
47-
/// 🚧 This trait is considered unstable; it may change at any time, in breaking or non-breaking ways,
48-
/// including in SemVer minor releases. Do not implement this trait in userland unless you are prepared for things to occasionally break.
49-
/// </div>
5047
pub trait UnstableSealed {}
5148
}

components/calendar/src/calendar.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,21 @@ use core::fmt;
2626
/// </div>
2727
pub trait Calendar: crate::cal::scaffold::UnstableSealed {
2828
/// The internal type used to represent dates
29+
30+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
31+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
2932
type DateInner: Eq + Copy + fmt::Debug;
3033
/// The type of YearInfo returned by the date
34+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
35+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
3136
type Year: fmt::Debug + Into<types::YearInfo>;
3237

3338
/// Construct a date from era/month codes and fields
3439
///
3540
/// The year is extended_year if no era is provided
3641
#[allow(clippy::wrong_self_convention)]
42+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
43+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
3744
fn from_codes(
3845
&self,
3946
era: Option<&str>,
@@ -44,43 +51,71 @@ pub trait Calendar: crate::cal::scaffold::UnstableSealed {
4451

4552
/// Construct the date from an ISO date
4653
#[allow(clippy::wrong_self_convention)]
54+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
55+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
4756
fn from_iso(&self, iso: IsoDateInner) -> Self::DateInner;
4857
/// Obtain an ISO date from this date
58+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
59+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
4960
fn to_iso(&self, date: &Self::DateInner) -> IsoDateInner;
5061

5162
/// Construct the date from a [`RataDie`]
5263
#[allow(clippy::wrong_self_convention)]
64+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
65+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
5366
fn from_rata_die(&self, rd: RataDie) -> Self::DateInner;
5467
/// Obtain a [`RataDie`] from this date
68+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
69+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
5570
fn to_rata_die(&self, date: &Self::DateInner) -> RataDie;
5671

5772
/// Count the number of months in a given year, specified by providing a date
5873
/// from that year
74+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
75+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
5976
fn months_in_year(&self, date: &Self::DateInner) -> u8;
6077
/// Count the number of days in a given year, specified by providing a date
6178
/// from that year
79+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
80+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
6281
fn days_in_year(&self, date: &Self::DateInner) -> u16;
6382
/// Count the number of days in a given month, specified by providing a date
6483
/// from that year/month
84+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
85+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
6586
fn days_in_month(&self, date: &Self::DateInner) -> u8;
6687
/// Calculate if a date is in a leap year
88+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
89+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
6790
fn is_in_leap_year(&self, date: &Self::DateInner) -> bool;
6891

6992
/// Information about the year
93+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
94+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
7095
fn year_info(&self, date: &Self::DateInner) -> Self::Year;
7196
/// The extended year value
97+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
98+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
7299
fn extended_year(&self, date: &Self::DateInner) -> i32;
73100
/// The calendar-specific month represented by `date`
101+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
102+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
74103
fn month(&self, date: &Self::DateInner) -> types::MonthInfo;
75104
/// The calendar-specific day-of-month represented by `date`
105+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
106+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
76107
fn day_of_month(&self, date: &Self::DateInner) -> types::DayOfMonth;
77108
/// Information of the day of the year
109+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
110+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
78111
fn day_of_year(&self, date: &Self::DateInner) -> types::DayOfYear;
79112

80-
#[doc(hidden)] // unstable
113+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
114+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
81115
/// Add `offset` to `date`
82116
fn offset_date(&self, date: &mut Self::DateInner, offset: DateDuration<Self>);
83-
#[doc(hidden)] // unstable
117+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
118+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
84119
/// Calculate `date2 - date` as a duration
85120
///
86121
/// `calendar2` is the calendar object associated with `date2`. In case the specific calendar objects
@@ -98,8 +133,12 @@ pub trait Calendar: crate::cal::scaffold::UnstableSealed {
98133
/// when parsing into this calendar.
99134
///
100135
/// If left empty, any algorithm will parse successfully.
136+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
137+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
101138
fn calendar_algorithm(&self) -> Option<crate::preferences::CalendarAlgorithm>;
102139

103140
/// Obtain a name for the calendar for debug printing
141+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
142+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
104143
fn debug_name(&self) -> &'static str;
105144
}

components/calendar/src/date.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ impl<A: AsCalendar> Date<A> {
193193
}
194194

195195
/// Add a `duration` to this date, mutating it
196-
#[doc(hidden)] // unstable
196+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
197+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
197198
#[inline]
198199
pub fn add(&mut self, duration: DateDuration<A::Calendar>) {
199200
self.calendar
@@ -202,15 +203,17 @@ impl<A: AsCalendar> Date<A> {
202203
}
203204

204205
/// Add a `duration` to this date, returning the new one
205-
#[doc(hidden)] // unstable
206+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
207+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
206208
#[inline]
207209
pub fn added(mut self, duration: DateDuration<A::Calendar>) -> Self {
208210
self.add(duration);
209211
self
210212
}
211213

212214
/// Calculating the duration between `other - self`
213-
#[doc(hidden)] // unstable
215+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
216+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
214217
#[inline]
215218
pub fn until<B: AsCalendar<Calendar = A::Calendar>>(
216219
&self,
@@ -278,12 +281,16 @@ impl<A: AsCalendar> Date<A> {
278281
/// AnyCalendar *will* panic if AnyCalendar [`Date`] objects with mismatching
279282
/// date and calendar types are constructed
280283
#[inline]
284+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
285+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
281286
pub fn from_raw(inner: <A::Calendar as Calendar>::DateInner, calendar: A) -> Self {
282287
Self { inner, calendar }
283288
}
284289

285290
/// Get the inner date implementation. Should not be called outside of calendar implementations
286291
#[inline]
292+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
293+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
287294
pub fn inner(&self) -> &<A::Calendar as Calendar>::DateInner {
288295
&self.inner
289296
}

components/calendar/src/duration.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ use core::marker::PhantomData;
6464
/// Currently unstable for ICU4X 1.0
6565
#[derive(Eq, PartialEq)]
6666
#[allow(clippy::exhaustive_structs)] // this type should be stable (and is intended to be constructed manually)
67-
#[doc(hidden)] // unstable
67+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
68+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
6869
pub struct DateDuration<C: Calendar + ?Sized> {
6970
/// The number of years
7071
pub years: i32,
@@ -92,7 +93,8 @@ impl<C: Calendar + ?Sized> Copy for DateDuration<C> {}
9293
/// care about
9394
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
9495
#[allow(clippy::exhaustive_enums)] // this type should be stable
95-
#[doc(hidden)] // unstable
96+
#[cfg_attr(not(feature = "unstable"), doc(hidden))]
97+
#[cfg_attr(docsrs, doc(cfg(feature = "unstable")))]
9698
pub enum DateDurationUnit {
9799
/// Duration in years
98100
Years,

0 commit comments

Comments
 (0)