Debian Codegraph @

debian/rust-vendor/icu_calendar/src/jiff.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 use crate::Date;
6 use crate::Gregorian;
7 use crate::cal::abstract_gregorian::AbstractGregorianYear;
8 use crate::cal::gregorian::GregorianDateInner;
9 use crate::calendar_arithmetic::ArithmeticDate;
10
11 impl From<jiff::civil::Date> for Date<Gregorian> {
12 fn from(jiff: jiff::civil::Date) -> Self {
13 // jiff's MIN/MAX value are inside VALID_RD_RANGE
14 Self::from_raw(
15 GregorianDateInner(ArithmeticDate::new_unchecked(
16 AbstractGregorianYear::from_iso_year(jiff.year() as i32),
17 jiff.month() as u8,
18 jiff.day() as u8,
19 )),
20 Gregorian,
21 )
22 }
23 }
24
25 #[test]
26 fn assert_range() {
27 use crate::calendar_arithmetic::VALID_RD_RANGE;
28
29 assert!(VALID_RD_RANGE.contains(
30 &(calendrical_calculations::gregorian::fixed_from_gregorian(
31 jiff::civil::Date::MIN.year() as i32,
32 jiff::civil::Date::MIN.month() as u8,
33 jiff::civil::Date::MIN.day() as u8
34 ))
35 ));
36 assert!(VALID_RD_RANGE.contains(
37 &(calendrical_calculations::gregorian::fixed_from_gregorian(
38 jiff::civil::Date::MAX.year() as i32,
39 jiff::civil::Date::MAX.month() as u8,
40 jiff::civil::Date::MAX.day() as u8
41 ))
42 ));
43 }
44
45 impl From<jiff::civil::Weekday> for crate::types::Weekday {
46 fn from(value: jiff::civil::Weekday) -> Self {
47 match value {
48 jiff::civil::Weekday::Monday => Self::Monday,
49 jiff::civil::Weekday::Tuesday => Self::Tuesday,
50 jiff::civil::Weekday::Wednesday => Self::Wednesday,
51 jiff::civil::Weekday::Thursday => Self::Thursday,
52 jiff::civil::Weekday::Friday => Self::Friday,
53 jiff::civil::Weekday::Saturday => Self::Saturday,
54 jiff::civil::Weekday::Sunday => Self::Sunday,
55 }
56 }
57 }