Skip to content

Commit 77eb609

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 88a0c21 commit 77eb609

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
@@ -386,7 +386,7 @@ impl KoreanTraditional {
386386
/// Use [`Self::new`].
387387
#[cfg(feature = "serde")]
388388
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER,Self::new)]
389-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
389+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
390390
pub fn try_new_with_buffer_provider(
391391
_provider: &(impl BufferProvider + ?Sized),
392392
) -> Result<Self, DataError> {
@@ -395,13 +395,13 @@ impl KoreanTraditional {
395395

396396
/// Use [`Self::new`].
397397
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
398-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
398+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
399399
pub fn try_new_unstable<D: ?Sized>(_provider: &D) -> Result<Self, DataError> {
400400
Ok(Self::new())
401401
}
402402

403403
/// Use [`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 new_always_calculating() -> Self {
406406
Self::new()
407407
}
@@ -527,21 +527,21 @@ impl ChineseTraditional {
527527

528528
#[cfg(feature = "serde")]
529529
#[doc = icu_provider::gen_buffer_unstable_docs!(BUFFER,Self::new)]
530-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
530+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
531531
pub fn try_new_with_buffer_provider(
532532
_provider: &(impl BufferProvider + ?Sized),
533533
) -> Result<Self, DataError> {
534534
Ok(Self::new())
535535
}
536536

537537
#[doc = icu_provider::gen_buffer_unstable_docs!(UNSTABLE, Self::new)]
538-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
538+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
539539
pub fn try_new_unstable<D: ?Sized>(_provider: &D) -> Result<Self, DataError> {
540540
Ok(Self::new())
541541
}
542542

543543
/// Use [`Self::new()`].
544-
#[deprecated(since = "2.1.0", note = "use `Self::new()")]
544+
#[deprecated(since = "2.1.0", note = "use `Self::new()`")]
545545
pub fn new_always_calculating() -> Self {
546546
Self::new()
547547
}

components/calendar/src/cal/hijri.rs

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

10391039
impl Date<Hijri<UmmAlQura>> {
10401040
/// Deprecated
1041-
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar")]
1041+
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar`")]
10421042
pub fn try_new_ummalqura(year: i32, month: u8, day: u8) -> Result<Self, RangeError> {
10431043
Date::try_new_hijri_with_calendar(year, month, day, Hijri::new_umm_al_qura())
10441044
}
10451045
}
10461046

10471047
impl<A: AsCalendar<Calendar = Hijri<TabularAlgorithm>>> Date<A> {
10481048
/// Deprecated
1049-
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar")]
1049+
#[deprecated(since = "2.1.0", note = "use `Date::try_new_hijri_with_calendar`")]
10501050
pub fn try_new_hijri_tabular_with_calendar(
10511051
year: i32,
10521052
month: u8,

0 commit comments

Comments
 (0)