Skip to content

Commit 97987b4

Browse files
committed
Improved stateful surpasses() impl that hews closely to the NonISODateSurpasses spec
This is not ready to go, but I wanted to get some feedback. Most of the following will not make sense until one has seen the code. - The priority here is to stick to the spec, and avoid recalculation. There are some clumsy aspects, like the need for the caller to invoke the checker in a specific way: 1. Large fields to small fields. 2. Before moving from field A to field B, make a final call with the computed value of field A, to set the internal state correctly. 3. Caller maintains their own y/m/w/d. I tried to work around unicode-org#2 and unicode-org#3, but couldn't come up with anything clean. It seems like the current approach is a good compromise. - For the debug assertions, clippy complained that I was calling a mut function. This is actually ok, because the object is reset to a new state immediately afterwards. The workaround to the clippy warning is expensive, but should be ok because it's just for debug. I tried other approaches but didn't get anything else to work. Adding an "allow" directive didn't work because debug_assert! is a macro. - There is now no in-library usage of surpasses(). All the testing for that was via until() as far as I can tell. The work item is to add test coverage for surpasses(), and once that looks good, I will refactor surpasses() to use the stateful checker, to optimize performance and eliminate duplicate code. Also included: Minor edits to balance some backticks.
1 parent 080991a commit 97987b4

File tree

5 files changed

+242
-181
lines changed

5 files changed

+242
-181
lines changed

components/calendar/src/cal/east_asian_traditional.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl KoreanTraditional {
401401
/// Use [`Self::new`].
402402
#[cfg(feature = "serde")]
403403
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER,Self::new)]
404-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
404+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
405405
pub fn try_new_with_buffer_provider(
406406
_provider: &(impl BufferProvider + ?Sized),
407407
) -> Result<Self, DataError> {
@@ -410,13 +410,13 @@ impl KoreanTraditional {
410410

411411
/// Use [`Self::new`].
412412
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
413-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
413+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
414414
pub fn try_new_unstable<D: ?Sized>(_provider: &D) -> Result<Self, DataError> {
415415
Ok(Self::new())
416416
}
417417

418418
/// Use [`Self::new`].
419-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
419+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
420420
pub fn new_always_calculating() -> Self {
421421
Self::new()
422422
}
@@ -548,21 +548,21 @@ impl ChineseTraditional {
548548

549549
#[cfg(feature = "serde")]
550550
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER,Self::new)]
551-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
551+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
552552
pub fn try_new_with_buffer_provider(
553553
_provider: &(impl BufferProvider + ?Sized),
554554
) -> Result<Self, DataError> {
555555
Ok(Self::new())
556556
}
557557

558558
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
559-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
559+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
560560
pub fn try_new_unstable<D: ?Sized>(_provider: &D) -> Result<Self, DataError> {
561561
Ok(Self::new())
562562
}
563563

564564
/// Use [`Self::new()`].
565-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
565+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
566566
pub fn new_always_calculating() -> Self {
567567
Self::new()
568568
}

components/calendar/src/cal/hijri.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,15 +1072,15 @@ impl<A: AsCalendar<Calendar = Hijri<R>>, R: Rules> Date<A> {
10721072

10731073
impl Date<Hijri<UmmAlQura>> {
10741074
/// Deprecated
1075-
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar")]
1075+
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar`")]
10761076
pub fn try_new_ummalqura(year: i32, month: u8, day: u8) -> Result<Self, RangeError> {
10771077
Date::try_new_hijri_with_calendar(year, month, day, Hijri::new_umm_al_qura())
10781078
}
10791079
}
10801080

10811081
impl<A: AsCalendar<Calendar = Hijri<TabularAlgorithm>>> Date<A> {
10821082
/// Deprecated
1083-
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar")]
1083+
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar`")]
10841084
pub fn try_new_hijri_tabular_with_calendar(
10851085
year: i32,
10861086
month: u8,

0 commit comments

Comments
 (0)