Skip to main content

jiff_core/civil/
weekday.rs

1use crate::{
2    bounds::{self as b, RangeError},
3    macros::{rbail, unwrapr},
4};
5
6/// A representation for the day of the week.
7#[derive(#[automatically_derived]#[doc(hidden)]#[allow(missing_docs)]
unsafe impl ::core::clone::TrivialClone for Weekday { }
#[automatically_derived]#[allow(missing_docs)]
impl ::core::clone::Clone for Weekday {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]#[allow(missing_docs)]
impl ::core::marker::Copy for Weekday { }Copy, #[automatically_derived]#[allow(missing_docs)]
impl ::core::fmt::Debug for Weekday {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_c_like_enum_write_str(f,
            "Monday Tuesday Wednesday Thursday Friday Saturday Sunday",
            match self {
                Weekday::Monday => 0usize,
                Weekday::Tuesday => 7usize,
                Weekday::Wednesday => 15usize,
                Weekday::Thursday => 25usize,
                Weekday::Friday => 34usize,
                Weekday::Saturday => 41usize,
                Weekday::Sunday => 50usize,
            })
    }
}Debug, #[automatically_derived]#[allow(missing_docs)]
impl ::core::cmp::Eq for Weekday { }Eq, #[automatically_derived]#[allow(missing_docs)]
impl ::core::hash::Hash for Weekday {
    #[inline]
    fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) {
        ::core::hash::Hash::hash(&::core::intrinsics::discriminant_value(self),
            state)
    }
}Hash, #[automatically_derived]#[allow(missing_docs)]
impl ::core::marker::StructuralPartialEq for Weekday { }
#[automatically_derived]#[allow(missing_docs)]
impl ::core::cmp::PartialEq for Weekday {
    #[inline]
    fn eq(&self, other: &Self) -> bool {
        ::core::intrinsics::discriminant_value(self) ==
            ::core::intrinsics::discriminant_value(other)
    }
}PartialEq)]
8#[cfg_attr(feature = "defmt", derive(defmt::Format))]
9#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
10#[repr(u8)]
11#[allow(missing_docs)]
12pub enum Weekday {
13    Monday = 1,
14    Tuesday = 2,
15    Wednesday = 3,
16    Thursday = 4,
17    Friday = 5,
18    Saturday = 6,
19    Sunday = 7,
20}
21
22impl Weekday {
23    /// Convert a 0-offset to a `Weekday`. Monday corresponds to offset `0` and
24    /// Sunday corresponds to offset `6`.
25    #[inline]
26    pub const fn from_monday_zero_offset(
27        offset: i8,
28    ) -> Result<Weekday, RangeError> {
29        Ok(match offset {
30            0 => Weekday::Monday,
31            1 => Weekday::Tuesday,
32            2 => Weekday::Wednesday,
33            3 => Weekday::Thursday,
34            4 => Weekday::Friday,
35            5 => Weekday::Saturday,
36            6 => Weekday::Sunday,
37            _ => return Err(b::WeekdayMondayZero::error().into_range_error())rbail!(b::WeekdayMondayZero::error()),
38        })
39    }
40
41    /// Convert a 1-offset to a `Weekday`. Monday corresponds to offset `1` and
42    /// Sunday corresponds to offset `7`.
43    #[inline]
44    pub const fn from_monday_one_offset(
45        offset: i8,
46    ) -> Result<Weekday, RangeError> {
47        Ok(match offset {
48            1 => Weekday::Monday,
49            2 => Weekday::Tuesday,
50            3 => Weekday::Wednesday,
51            4 => Weekday::Thursday,
52            5 => Weekday::Friday,
53            6 => Weekday::Saturday,
54            7 => Weekday::Sunday,
55            _ => return Err(b::WeekdayMondayOne::error().into_range_error())rbail!(b::WeekdayMondayOne::error()),
56        })
57    }
58
59    /// Convert a 0-offset to a `Weekday`. Sunday corresponds to offset `0` and
60    /// Saturday corresponds to offset `6`.
61    #[inline]
62    pub const fn from_sunday_zero_offset(
63        offset: i8,
64    ) -> Result<Weekday, RangeError> {
65        Ok(match offset {
66            0 => Weekday::Sunday,
67            1 => Weekday::Monday,
68            2 => Weekday::Tuesday,
69            3 => Weekday::Wednesday,
70            4 => Weekday::Thursday,
71            5 => Weekday::Friday,
72            6 => Weekday::Saturday,
73            _ => return Err(b::WeekdaySundayZero::error().into_range_error())rbail!(b::WeekdaySundayZero::error()),
74        })
75    }
76
77    /// Convert a 1-offset to a `Weekday`. Sunday corresponds to offset `1` and
78    /// Saturday corresponds to offset `7`.
79    #[inline]
80    pub const fn from_sunday_one_offset(
81        offset: i8,
82    ) -> Result<Weekday, RangeError> {
83        Ok(match offset {
84            1 => Weekday::Sunday,
85            2 => Weekday::Monday,
86            3 => Weekday::Tuesday,
87            4 => Weekday::Wednesday,
88            5 => Weekday::Thursday,
89            6 => Weekday::Friday,
90            7 => Weekday::Saturday,
91            _ => return Err(b::WeekdaySundayOne::error().into_range_error())rbail!(b::WeekdaySundayOne::error()),
92        })
93    }
94
95    /// Returns the weekday as a 0-offset. Monday corresponds to offset `0`
96    /// and Sunday corresponds to offset `6`.
97    #[inline]
98    pub const fn to_monday_zero_offset(self) -> i8 {
99        self.to_monday_one_offset() - 1
100    }
101
102    /// Returns the weekday as a 1-offset. Monday corresponds to offset `1`
103    /// and Sunday corresponds to offset `7`.
104    #[inline]
105    pub const fn to_monday_one_offset(self) -> i8 {
106        self as i8
107    }
108
109    /// Returns the weekday as a 0-offset. Sunday corresponds to offset `0`
110    /// and Saturday corresponds to offset `6`.
111    #[inline]
112    pub const fn to_sunday_zero_offset(self) -> i8 {
113        let offset = self.to_monday_one_offset();
114        if offset == 7 { 0 } else { offset }
115    }
116
117    /// Returns the weekday as a 1-offset. Sunday corresponds to offset `1`
118    /// and Saturday corresponds to offset `7`.
119    #[inline]
120    pub const fn to_sunday_one_offset(self) -> i8 {
121        self.to_sunday_zero_offset() + 1
122    }
123
124    /// Add the given number of days to this weekday, using wrapping arithmetic,
125    /// and return the resulting weekday.
126    ///
127    /// Adding a multiple of `7` (including `0`) is guaranteed to produce the
128    /// same weekday as this one.
129    #[inline]
130    pub const fn wrapping_add(self, days: i64) -> Weekday {
131        let start = self.to_monday_zero_offset() as i64;
132        // We are careful to `rem_euclid` on `rhs` before doing
133        // wrapping arithmetic, otherwise the result is not
134        // correct. Namely, it would assume that, e.g., since
135        // `i64::MAX.rem_euclid(7)` is 0, then the next value would be
136        // `rem_euclid(7) == 1`. But `i64::MIN.rem_euclid(7)` is 6.
137        let end = (start.wrapping_add(days.rem_euclid(7)) % 7) as i8;
138        // Always valid because of the mod 7 above.
139        match Weekday::from_monday_zero_offset(end) {
    Ok(val) => val,
    Err(_) => {
        ::core::panicking::panic_fmt(format_args!("weekday is always 0..=6"));
    }
}unwrapr!(
140            Weekday::from_monday_zero_offset(end),
141            "weekday is always 0..=6",
142        )
143    }
144
145    /// Subtract the given number of days from this weekday, using wrapping
146    /// arithmetic, and return the resulting weekday.
147    ///
148    /// Subtracting a multiple of `7` (including `0`) is guaranteed to produce
149    /// the same weekday as this one.
150    #[inline]
151    pub const fn wrapping_sub(self, days: i64) -> Weekday {
152        // i64::MIN.rem_euclid(7) == 6
153        let days = match days.checked_neg() {
154            Some(days) => days,
155            None => -6,
156        };
157        self.wrapping_add(days)
158    }
159
160    /// Returns the next weekday, wrapping around at the end of week to the
161    /// beginning of the week.
162    ///
163    /// This is a convenience routing for calling [`Weekday::wrapping_add`]
164    /// with a value of `1`.
165    #[inline]
166    pub const fn next(self) -> Weekday {
167        self.wrapping_add(1)
168    }
169
170    /// Returns the previous weekday, wrapping around at the beginning of week
171    /// to the end of the week.
172    ///
173    /// This is a convenience routing for calling [`Weekday::wrapping_sub`]
174    /// with a value of `1`.
175    #[inline]
176    pub const fn previous(self) -> Weekday {
177        self.wrapping_sub(1)
178    }
179
180    /// Returns the number of days from `other` to this weekday.
181    ///
182    /// Adding the returned number of days to `other` is guaranteed to sum to
183    /// this weekday. The number of days returned is guaranteed to be in the
184    /// range `0..=6`.
185    #[inline]
186    pub const fn since(self, other: Weekday) -> i8 {
187        (self.to_monday_zero_offset() - other.to_monday_zero_offset())
188            .rem_euclid(7)
189    }
190
191    /// Returns the number of days until `other` from this weekday.
192    ///
193    /// Adding the returned number of days to this weekday is guaranteed to sum
194    /// to `other` weekday. The number of days returned is guaranteed to be in
195    /// the range `0..=6`.
196    #[inline]
197    pub const fn until(self, other: Weekday) -> i8 {
198        other.since(self)
199    }
200
201    /// Starting with this weekday, this returns an unending iterator that
202    /// cycles forward through the days of the week.
203    #[inline]
204    pub const fn cycle_forward(self) -> WeekdaysForward {
205        WeekdaysForward { next: self }
206    }
207
208    /// Starting with this weekday, this returns an unending iterator that
209    /// cycles backward through the days of the week.
210    #[inline]
211    pub const fn cycle_reverse(self) -> WeekdaysReverse {
212        WeekdaysReverse { next: self }
213    }
214}
215
216/// An unending iterator of the days of the week.
217///
218/// This iterator is created by calling [`Weekday::cycle_forward`].
219#[derive(#[automatically_derived]impl ::core::clone::Clone for WeekdaysForward {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        WeekdaysForward { next: ::core::clone::Clone::clone(&self.next) }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for WeekdaysForward {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f,
            "WeekdaysForward next", &&self.next)
    }
}Debug)]
220pub struct WeekdaysForward {
221    next: Weekday,
222}
223
224impl Iterator for WeekdaysForward {
225    type Item = Weekday;
226
227    #[inline]
228    fn next(&mut self) -> Option<Weekday> {
229        let next = self.next;
230        self.next = self.next.wrapping_add(1);
231        Some(next)
232    }
233}
234
235impl core::iter::FusedIterator for WeekdaysForward {}
236
237/// An unending iterator of the days of the week in reverse.
238///
239/// This iterator is created by calling [`Weekday::cycle_reverse`].
240#[derive(#[automatically_derived]impl ::core::clone::Clone for WeekdaysReverse {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        WeekdaysReverse { next: ::core::clone::Clone::clone(&self.next) }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for WeekdaysReverse {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f,
            "WeekdaysReverse next", &&self.next)
    }
}Debug)]
241pub struct WeekdaysReverse {
242    next: Weekday,
243}
244
245impl Iterator for WeekdaysReverse {
246    type Item = Weekday;
247
248    #[inline]
249    fn next(&mut self) -> Option<Weekday> {
250        let next = self.next;
251        self.next = self.next.wrapping_sub(1);
252        Some(next)
253    }
254}
255
256impl core::iter::FusedIterator for WeekdaysReverse {}
257
258#[cfg(test)]
259impl quickcheck::Arbitrary for Weekday {
260    fn arbitrary(g: &mut quickcheck::Gen) -> Weekday {
261        let offset = b::WeekdayMondayZero::arbitrary(g);
262        Weekday::from_monday_zero_offset(offset).unwrap()
263    }
264
265    fn shrink(&self) -> alloc::boxed::Box<dyn Iterator<Item = Weekday>> {
266        alloc::boxed::Box::new(
267            self.to_monday_zero_offset()
268                .shrink()
269                .filter_map(|n| Weekday::from_monday_zero_offset(n).ok()),
270        )
271    }
272}
273
274#[cfg(test)]
275mod tests {
276    use alloc::vec::Vec;
277
278    use super::*;
279
280    static WEEKDAYS: &[Weekday] = &[
281        Weekday::Monday,
282        Weekday::Tuesday,
283        Weekday::Wednesday,
284        Weekday::Thursday,
285        Weekday::Friday,
286        Weekday::Saturday,
287        Weekday::Sunday,
288    ];
289
290    #[test]
291    fn weekday_from_monday_zero() {
292        use self::Weekday::*;
293
294        assert_eq!(Weekday::from_monday_zero_offset(0), Ok(Monday));
295        assert_eq!(Weekday::from_monday_zero_offset(1), Ok(Tuesday));
296        assert_eq!(Weekday::from_monday_zero_offset(2), Ok(Wednesday));
297        assert_eq!(Weekday::from_monday_zero_offset(3), Ok(Thursday));
298        assert_eq!(Weekday::from_monday_zero_offset(4), Ok(Friday));
299        assert_eq!(Weekday::from_monday_zero_offset(5), Ok(Saturday));
300        assert_eq!(Weekday::from_monday_zero_offset(6), Ok(Sunday));
301    }
302
303    #[test]
304    fn weekday_from_monday_one() {
305        use self::Weekday::*;
306
307        assert_eq!(Weekday::from_monday_one_offset(1), Ok(Monday));
308        assert_eq!(Weekday::from_monday_one_offset(2), Ok(Tuesday));
309        assert_eq!(Weekday::from_monday_one_offset(3), Ok(Wednesday));
310        assert_eq!(Weekday::from_monday_one_offset(4), Ok(Thursday));
311        assert_eq!(Weekday::from_monday_one_offset(5), Ok(Friday));
312        assert_eq!(Weekday::from_monday_one_offset(6), Ok(Saturday));
313        assert_eq!(Weekday::from_monday_one_offset(7), Ok(Sunday));
314    }
315
316    #[test]
317    fn weekday_from_sunday_zero() {
318        use self::Weekday::*;
319
320        assert_eq!(Weekday::from_sunday_zero_offset(1), Ok(Monday));
321        assert_eq!(Weekday::from_sunday_zero_offset(2), Ok(Tuesday));
322        assert_eq!(Weekday::from_sunday_zero_offset(3), Ok(Wednesday));
323        assert_eq!(Weekday::from_sunday_zero_offset(4), Ok(Thursday));
324        assert_eq!(Weekday::from_sunday_zero_offset(5), Ok(Friday));
325        assert_eq!(Weekday::from_sunday_zero_offset(6), Ok(Saturday));
326        assert_eq!(Weekday::from_sunday_zero_offset(0), Ok(Sunday));
327    }
328
329    #[test]
330    fn weekday_from_sunday_one() {
331        use self::Weekday::*;
332
333        assert_eq!(Weekday::from_sunday_one_offset(2), Ok(Monday));
334        assert_eq!(Weekday::from_sunday_one_offset(3), Ok(Tuesday));
335        assert_eq!(Weekday::from_sunday_one_offset(4), Ok(Wednesday));
336        assert_eq!(Weekday::from_sunday_one_offset(5), Ok(Thursday));
337        assert_eq!(Weekday::from_sunday_one_offset(6), Ok(Friday));
338        assert_eq!(Weekday::from_sunday_one_offset(7), Ok(Saturday));
339        assert_eq!(Weekday::from_sunday_one_offset(1), Ok(Sunday));
340    }
341
342    #[test]
343    fn weekday_to_monday_zero() {
344        for &weekday in WEEKDAYS {
345            assert_eq!(
346                Weekday::from_monday_zero_offset(
347                    weekday.to_monday_zero_offset()
348                ),
349                Ok(weekday)
350            );
351        }
352    }
353
354    #[test]
355    fn weekday_to_monday_one() {
356        for &weekday in WEEKDAYS {
357            assert_eq!(
358                Weekday::from_monday_one_offset(
359                    weekday.to_monday_one_offset()
360                ),
361                Ok(weekday)
362            );
363        }
364    }
365
366    #[test]
367    fn weekday_to_sunday_zero() {
368        for &weekday in WEEKDAYS {
369            assert_eq!(
370                Weekday::from_sunday_zero_offset(
371                    weekday.to_sunday_zero_offset()
372                ),
373                Ok(weekday)
374            );
375        }
376    }
377
378    #[test]
379    fn weekday_to_sunday_one() {
380        for &weekday in WEEKDAYS {
381            assert_eq!(
382                Weekday::from_sunday_one_offset(
383                    weekday.to_sunday_one_offset()
384                ),
385                Ok(weekday)
386            );
387        }
388    }
389
390    #[test]
391    fn weekday_wrapping_add() {
392        use self::Weekday::*;
393
394        assert_eq!(Sunday.wrapping_add(0), Sunday);
395        assert_eq!(Sunday.wrapping_add(1), Monday);
396        assert_eq!(Sunday.wrapping_add(2), Tuesday);
397        assert_eq!(Sunday.wrapping_add(3), Wednesday);
398        assert_eq!(Sunday.wrapping_add(4), Thursday);
399        assert_eq!(Sunday.wrapping_add(5), Friday);
400        assert_eq!(Sunday.wrapping_add(6), Saturday);
401        assert_eq!(Sunday.wrapping_add(7), Sunday);
402
403        assert_eq!(Wednesday.wrapping_add(0), Wednesday);
404        assert_eq!(Wednesday.wrapping_add(1), Thursday);
405        assert_eq!(Wednesday.wrapping_add(2), Friday);
406        assert_eq!(Wednesday.wrapping_add(3), Saturday);
407        assert_eq!(Wednesday.wrapping_add(4), Sunday);
408        assert_eq!(Wednesday.wrapping_add(5), Monday);
409        assert_eq!(Wednesday.wrapping_add(6), Tuesday);
410        assert_eq!(Wednesday.wrapping_add(7), Wednesday);
411
412        assert_eq!(Sunday.wrapping_add(-1), Saturday);
413        assert_eq!(Sunday.wrapping_add(-2), Friday);
414        assert_eq!(Sunday.wrapping_add(-3), Thursday);
415        assert_eq!(Sunday.wrapping_add(-4), Wednesday);
416        assert_eq!(Sunday.wrapping_add(-5), Tuesday);
417        assert_eq!(Sunday.wrapping_add(-6), Monday);
418        assert_eq!(Sunday.wrapping_add(-7), Sunday);
419
420        assert_eq!(Wednesday.wrapping_add(-1), Tuesday);
421        assert_eq!(Wednesday.wrapping_add(-2), Monday);
422        assert_eq!(Wednesday.wrapping_add(-3), Sunday);
423        assert_eq!(Wednesday.wrapping_add(-4), Saturday);
424        assert_eq!(Wednesday.wrapping_add(-5), Friday);
425        assert_eq!(Wednesday.wrapping_add(-6), Thursday);
426        assert_eq!(Wednesday.wrapping_add(-7), Wednesday);
427
428        // This caught a bug where our wrapping arithmetic in
429        // `Weekday::wrapping_add` was incorrect when overflow occurred.
430        assert_eq!(Tuesday.wrapping_add(9223372036854775807i64), Tuesday);
431    }
432
433    #[test]
434    fn weekday_wrapping_sub() {
435        use self::Weekday::*;
436
437        assert_eq!(Sunday.wrapping_sub(0), Sunday);
438        assert_eq!(Sunday.wrapping_sub(1), Saturday);
439        assert_eq!(Sunday.wrapping_sub(2), Friday);
440        assert_eq!(Sunday.wrapping_sub(3), Thursday);
441        assert_eq!(Sunday.wrapping_sub(4), Wednesday);
442        assert_eq!(Sunday.wrapping_sub(5), Tuesday);
443        assert_eq!(Sunday.wrapping_sub(6), Monday);
444        assert_eq!(Sunday.wrapping_sub(7), Sunday);
445
446        assert_eq!(Wednesday.wrapping_sub(0), Wednesday);
447        assert_eq!(Wednesday.wrapping_sub(1), Tuesday);
448        assert_eq!(Wednesday.wrapping_sub(2), Monday);
449        assert_eq!(Wednesday.wrapping_sub(3), Sunday);
450        assert_eq!(Wednesday.wrapping_sub(4), Saturday);
451        assert_eq!(Wednesday.wrapping_sub(5), Friday);
452        assert_eq!(Wednesday.wrapping_sub(6), Thursday);
453        assert_eq!(Wednesday.wrapping_sub(7), Wednesday);
454
455        assert_eq!(Sunday.wrapping_sub(-1), Monday);
456        assert_eq!(Sunday.wrapping_sub(-2), Tuesday);
457        assert_eq!(Sunday.wrapping_sub(-3), Wednesday);
458        assert_eq!(Sunday.wrapping_sub(-4), Thursday);
459        assert_eq!(Sunday.wrapping_sub(-5), Friday);
460        assert_eq!(Sunday.wrapping_sub(-6), Saturday);
461        assert_eq!(Sunday.wrapping_sub(-7), Sunday);
462
463        assert_eq!(Wednesday.wrapping_sub(-1), Thursday);
464        assert_eq!(Wednesday.wrapping_sub(-2), Friday);
465        assert_eq!(Wednesday.wrapping_sub(-3), Saturday);
466        assert_eq!(Wednesday.wrapping_sub(-4), Sunday);
467        assert_eq!(Wednesday.wrapping_sub(-5), Monday);
468        assert_eq!(Wednesday.wrapping_sub(-6), Tuesday);
469        assert_eq!(Wednesday.wrapping_sub(-7), Wednesday);
470
471        // This found a bug where we were negating the integer
472        // given and assuming it wouldn't panic.
473        assert_eq!(Monday.wrapping_sub(-9223372036854775805i64), Saturday);
474        assert_eq!(Monday.wrapping_sub(-9223372036854775806i64), Sunday);
475        assert_eq!(Monday.wrapping_sub(-9223372036854775807i64), Monday);
476        assert_eq!(Monday.wrapping_sub(-9223372036854775808i64), Tuesday);
477    }
478
479    #[test]
480    fn weekday_since() {
481        for &wd1 in WEEKDAYS {
482            for (distance, wd2) in wd1.cycle_forward().enumerate().take(7) {
483                assert_eq!(
484                    usize::try_from(wd2.since(wd1)).unwrap(),
485                    distance,
486                    "{wd2:?} since {wd1:?} should be {distance}",
487                );
488            }
489        }
490    }
491
492    #[test]
493    fn weekday_until() {
494        for &wd1 in WEEKDAYS {
495            for (distance, wd2) in wd1.cycle_forward().enumerate().take(7) {
496                assert_eq!(
497                    usize::try_from(wd1.until(wd2)).unwrap(),
498                    distance,
499                    "{wd1:?} until {wd2:?} should be {distance}",
500                );
501            }
502        }
503    }
504
505    #[test]
506    fn weekday_cycle_forward() {
507        assert_eq!(
508            WEEKDAYS,
509            Weekday::Monday.cycle_forward().take(7).collect::<Vec<_>>(),
510        );
511    }
512
513    #[test]
514    fn weekday_cycle_reverse() {
515        let mut got =
516            Weekday::Sunday.cycle_reverse().take(7).collect::<Vec<_>>();
517        got.reverse();
518        assert_eq!(WEEKDAYS, got);
519    }
520
521    quickcheck::quickcheck! {
522        fn prop_weekday_add_sub(wd: Weekday, n: i64) -> bool {
523            wd.wrapping_add(n).wrapping_sub(n) == wd
524        }
525
526        fn prop_weekday_since_until(wd1: Weekday, wd2: Weekday) -> bool {
527            wd1.until(wd2) == wd2.since(wd1)
528        }
529
530        fn prop_since_add_equals_self(wd1: Weekday, wd2: Weekday) -> bool {
531            let days = wd1.since(wd2);
532            wd2.wrapping_add(days.into()) == wd1
533        }
534
535        fn prop_until_add_equals_other(wd1: Weekday, wd2: Weekday) -> bool {
536            let days = wd1.until(wd2);
537            wd1.wrapping_add(days.into()) == wd2
538        }
539    }
540}