| 1 | /*! |
| 2 | This module defines the internal core time data types. |
| 3 | |
| 4 | This includes physical time (i.e., a timestamp) and civil time. |
| 5 | |
| 6 | These types exist to provide a home for the core algorithms in a datetime |
| 7 | crate. For example, converting from a timestamp to a Gregorian calendar date |
| 8 | and clock time. |
| 9 | |
| 10 | These routines are specifically implemented on simple primitive integer types |
| 11 | and implicitly assume that the inputs are valid (i.e., within Jiff's minimum |
| 12 | and maximum ranges). |
| 13 | |
| 14 | These exist to provide `const` capabilities, and also to provide a small |
| 15 | reusable core of important algorithms that can be shared between `jiff` and |
| 16 | `jiff-static`. |
| 17 | |
| 18 | # Naming |
| 19 | |
| 20 | The types in this module are prefixed with letter `I` to make it clear that |
| 21 | they are internal types. Specifically, to distinguish them from Jiff's public |
| 22 | types. For example, `Date` versus `IDate`. |
| 23 | */ |
| 24 | |
| 25 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 26 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { |
| 27 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second.: i64, |
| 28 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond.: i32, |
| 29 | } |
| 30 | |
| 31 | impl ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { |
| 32 | const MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]MIN.: ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# = |
| 33 | ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().377705023201, nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond.: 0 }; |
| 34 | const MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]MAX.: ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# = |
| 35 | ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second.: 253402207200, nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond.: 999_999_999 }; |
| 36 | |
| 37 | /// Creates an `ITimestamp` from a Unix timestamp in seconds. |
| 38 | #[inline] |
| 39 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn from_secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]from_second().(second: i64) -> ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { |
| 40 | ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second., nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond.: 0 } |
| 41 | } |
| 42 | |
| 43 | /// Converts a Unix timestamp with an offset to a Gregorian datetime. |
| 44 | /// |
| 45 | /// The offset should correspond to the number of seconds required to |
| 46 | /// add to this timestamp to get the local time. |
| 47 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 48 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_datetimerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]to_datetime().(&self, offset: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#) -> IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { |
| 49 | let ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { mut secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second., mut nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond. } = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self; |
| 50 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().offset.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#second. as i64; |
| 51 | let mut epoch_day = second.div_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]div_euclid().(86_400) as i32; |
| 52 | second = second.rem_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]rem_euclid().(86_400); |
| 53 | if nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 { |
| 54 | if second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]gt().0 { |
| 55 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().1; |
| 56 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1_000_000_000; |
| 57 | } else { |
| 58 | epoch_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1; |
| 59 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().86_399; |
| 60 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().1_000_000_000; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | let date = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day. }.to_daterust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]to_date().(); |
| 65 | let mut time = ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second.: second as i32 }.to_timerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimeSecond]to_time().(); |
| 66 | time.subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond. = nanosecond; |
| 67 | IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date., timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time. } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 72 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# { |
| 73 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#second.: i32, |
| 74 | } |
| 75 | |
| 76 | impl IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# { |
| 77 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const UTCrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IOffset]UTC.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# = IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#second.: 0 }; |
| 78 | } |
| 79 | |
| 80 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 81 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { |
| 82 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date.: IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, |
| 83 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#, |
| 84 | } |
| 85 | |
| 86 | impl IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { |
| 87 | const MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]MIN.: IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# = IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date.: IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]MIN., timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]MIN. }; |
| 88 | const MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]MAX.: IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# = IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date.: IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]MAX., timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]MAX. }; |
| 89 | |
| 90 | /// Converts a Gregorian datetime and its offset to a Unix timestamp. |
| 91 | /// |
| 92 | /// The offset should correspond to the number of seconds required to |
| 93 | /// subtract from this datetime in order to get to UTC. |
| 94 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 95 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn to_timestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]to_timestamp().(&self, offset: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#) -> ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { |
| 96 | let epoch_day = self.daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date..to_epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]to_epoch_day().().epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.; |
| 97 | let mut second = (epoch_day as i64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().86_400 |
| 98 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Add<Self>`]add().(self.timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time..to_secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]to_second().().secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second. as i64); |
| 99 | let mut nanosecond = self.timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time..subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond.; |
| 100 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`SubAssign<Self>`]sub_assign().offset.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#second. as i64; |
| 101 | if epoch_day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 && nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 { |
| 102 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().1; |
| 103 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`SubAssign<Self>`]sub_assign().1_000_000_000; |
| 104 | } |
| 105 | ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#second., nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#nanosecond. } |
| 106 | } |
| 107 | |
| 108 | /// Converts a Gregorian datetime and its offset to a Unix timestamp. |
| 109 | /// |
| 110 | /// If the timestamp would overflow Jiff's timestamp range, then this |
| 111 | /// returns `None`. |
| 112 | /// |
| 113 | /// The offset should correspond to the number of seconds required to |
| 114 | /// subtract from this datetime in order to get to UTC. |
| 115 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 116 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn to_timestamp_checkedrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]to_timestamp_checked().( |
| 117 | &self, |
| 118 | offset: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#, |
| 119 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#> { |
| 120 | let ts = self.to_timestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]to_timestamp().(offset); |
| 121 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().ts && ts rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().ITimestamprust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimestamp#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimestamp]MAX.) { |
| 122 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 123 | } |
| 124 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ts) |
| 125 | } |
| 126 | |
| 127 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 128 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn saturating_add_secondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]saturating_add_seconds().(&self, seconds: i32) -> IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { |
| 129 | self.checked_add_secondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]checked_add_seconds().(seconds).unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| { |
| 130 | if seconds rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().0 { |
| 131 | IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]MIN. |
| 132 | } else { |
| 133 | IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]MAX. |
| 134 | } |
| 135 | }) |
| 136 | } |
| 137 | |
| 138 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 139 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn checked_add_secondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDateTime]checked_add_seconds().( |
| 140 | &self, |
| 141 | seconds: i32, |
| 142 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 143 | let day_second = self |
| 144 | .timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time. |
| 145 | .to_secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]to_second().() |
| 146 | .secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second. |
| 147 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]checked_add().(seconds) |
| 148 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateTimeSecondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateTimeSeconds#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 149 | let days = day_second.div_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]div_euclid().(86400); |
| 150 | let second = day_second.rem_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]rem_euclid().(86400); |
| 151 | let date = self.daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date..checked_add_daysrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]checked_add_days().(days)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 152 | let time = ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second. }.to_timerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimeSecond]to_time().(); |
| 153 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { daterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#date., timerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime#time. }) |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 158 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { |
| 159 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.: i32, |
| 160 | } |
| 161 | |
| 162 | impl IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { |
| 163 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MIN.: IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().4371587 }; |
| 164 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MAX.: IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.: 2932896 }; |
| 165 | |
| 166 | /// Converts days since the Unix epoch to a Gregorian date. |
| 167 | /// |
| 168 | /// This is Neri-Schneider. There's no branching or divisions. |
| 169 | /// |
| 170 | /// Ref: <https://github.com/cassioneri/eaf/blob/684d3cc32d14eee371d0abe4f683d6d6a49ed5c1/algorithms/neri_schneider.hpp#L40C3-L40C34> |
| 171 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 172 | #[allow(non_upper_case_globals, non_snake_case)] // to mimic source |
| 173 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_daterust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]to_date().(&self) -> IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { |
| 174 | const srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.: u32 = 82; |
| 175 | const Krust-analyzer cargo jiff 0.2.18 shared/util/itime/K.: u32 = 719468 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().146097 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.; |
| 176 | const Lrust-analyzer cargo jiff 0.2.18 shared/util/itime/L.: u32 = 400 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.; |
| 177 | |
| 178 | let N_U = self.epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day. as u32; |
| 179 | let N = N_U.wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_add().(Krust-analyzer cargo jiff 0.2.18 shared/util/itime/K.); |
| 180 | |
| 181 | let N_1 = 4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().N rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().3; |
| 182 | let C = N_1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().146097; |
| 183 | let N_C = (N_1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().146097) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().4; |
| 184 | |
| 185 | let N_2 = 4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().N_C rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().3; |
| 186 | let P_2 = 2939745 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Mul<Self>`]mul().(N_2 as u64); |
| 187 | let Z = (P_2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().4294967296) as u32; |
| 188 | let N_Y = (P_2 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Rem<Self>`]rem().4294967296) as u32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().2939745 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().4; |
| 189 | let Y = 100 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().C rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().Z; |
| 190 | |
| 191 | let N_3 = 2141 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().N_Y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().197913; |
| 192 | let M = N_3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().65536; |
| 193 | let D = (N_3 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Rem<Self>`]rem().65536) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().2141; |
| 194 | |
| 195 | let J = N_Y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]ge().306; |
| 196 | let year = Y.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_sub().(Lrust-analyzer cargo jiff 0.2.18 shared/util/itime/L.).wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_add().(J as u32) as i16; |
| 197 | let month = (if J { M rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().12 } else { M }) as i8; |
| 198 | let day = (D rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().1) as i8; |
| 199 | IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. } |
| 200 | } |
| 201 | |
| 202 | /// Returns the day of the week for this epoch day. |
| 203 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 204 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn weekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]weekday().(&self) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 205 | // Based on Hinnant's approach here, although we use ISO weekday |
| 206 | // numbering by default. Basically, this works by using the knowledge |
| 207 | // that 1970-01-01 was a Thursday. |
| 208 | // |
| 209 | // Ref: http://howardhinnant.github.io/date_algorithms.html |
| 210 | IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_monday_zero_offset().( |
| 211 | (self.epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Add<Self>`]add().3).rem_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]rem_euclid().(7) as i8 |
| 212 | ) |
| 213 | } |
| 214 | |
| 215 | /// Add the given number of days to this epoch day. |
| 216 | /// |
| 217 | /// If this would overflow an `i32` or result in an out-of-bounds epoch |
| 218 | /// day, then this returns an error. |
| 219 | #[inline] |
| 220 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn checked_addrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]checked_add().( |
| 221 | &self, |
| 222 | amount: i32, |
| 223 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 224 | let epoch_day = self.epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.; |
| 225 | let sum = epoch_day |
| 226 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]checked_add().(amount) |
| 227 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::EpochDayI32rust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayI32#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 228 | let ret = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day.: sum }; |
| 229 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().ret && ret rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd#le().IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MAX.) { |
| 230 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::EpochDayDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayDays#); |
| 231 | } |
| 232 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ret) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 237 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { |
| 238 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year.: i16, |
| 239 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: i8, |
| 240 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: i8, |
| 241 | } |
| 242 | |
| 243 | impl IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { |
| 244 | const MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]MIN.: IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year.: -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().9999, monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: 1, dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 1 }; |
| 245 | const MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]MAX.: IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year.: 9999, monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: 12, dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 31 }; |
| 246 | |
| 247 | /// Fallibly builds a new date. |
| 248 | /// |
| 249 | /// This checks that the given day is valid for the given year/month. |
| 250 | /// |
| 251 | /// No other conditions are checked. This assumes `year` and `month` are |
| 252 | /// valid, and that `day >= 1`. |
| 253 | #[inline] |
| 254 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn try_newrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]try_new().( |
| 255 | year: i16, |
| 256 | month: i8, |
| 257 | day: i8, |
| 258 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 259 | if day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().28 { |
| 260 | let max_day = days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(year, month); |
| 261 | if day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().max_day { |
| 262 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateInvalidDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#month. }); |
| 263 | } |
| 264 | } |
| 265 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. }) |
| 266 | } |
| 267 | |
| 268 | /// Returns the date corresponding to the day of the given year. The day |
| 269 | /// of the year should be a value in `1..=366`, with `366` only being valid |
| 270 | /// if `year` is a leap year. |
| 271 | /// |
| 272 | /// This assumes that `year` is valid, but returns an error if `day` is |
| 273 | /// not in the range `1..=366`. |
| 274 | #[inline] |
| 275 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn from_day_of_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]from_day_of_year().( |
| 276 | year: i16, |
| 277 | day: i16, |
| 278 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 279 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().day && day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().366) { |
| 280 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateInvalidDayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear#year. }); |
| 281 | } |
| 282 | let start = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: 1, dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 1 }.to_epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]to_epoch_day().(); |
| 283 | let end = start |
| 284 | .checked_addrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]checked_add().(i32::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i32][`From<i16>`]from().(day) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Sub<Self>`]sub().1) |
| 285 | // This can only happen when `year=9999` and `day=366`. |
| 286 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DayOfYear#)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 287 | .to_daterust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]to_date().(); |
| 288 | // If we overflowed into the next year, then `day` is too big. |
| 289 | if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne().end.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. { |
| 290 | // Can only happen given day=366 and this is a leap year. |
| 291 | debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(day, 366); |
| 292 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_leap_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/is_leap_year().(year)); |
| 293 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateInvalidDayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear#year. }); |
| 294 | } |
| 295 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(end) |
| 296 | } |
| 297 | |
| 298 | /// Returns the date corresponding to the day of the given year. The day |
| 299 | /// of the year should be a value in `1..=365`, with February 29 being |
| 300 | /// completely ignored. That is, it is guaranteed that February 29 will |
| 301 | /// never be returned by this function. It is impossible. |
| 302 | /// |
| 303 | /// This assumes that `year` is valid, but returns an error if `day` is |
| 304 | /// not in the range `1..=365`. |
| 305 | #[inline] |
| 306 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn from_day_of_year_no_leaprust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]from_day_of_year_no_leap().( |
| 307 | year: i16, |
| 308 | mut day: i16, |
| 309 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 310 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().day && day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().365) { |
| 311 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateInvalidDayOfYearNoLeaprust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYearNoLeap#); |
| 312 | } |
| 313 | if day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().60 && is_leap_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/is_leap_year().(year) { |
| 314 | day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`AddAssign<Self>`]add_assign().1; |
| 315 | } |
| 316 | // The boundary check above guarantees this always succeeds. |
| 317 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#::from_day_of_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]from_day_of_year().(year, day).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 318 | } |
| 319 | |
| 320 | /// Converts a Gregorian date to days since the Unix epoch. |
| 321 | /// |
| 322 | /// This is Neri-Schneider. There's no branching or divisions. |
| 323 | /// |
| 324 | /// Ref: https://github.com/cassioneri/eaf/blob/684d3cc32d14eee371d0abe4f683d6d6a49ed5c1/algorithms/neri_schneider.hpp#L83 |
| 325 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 326 | #[allow(non_upper_case_globals, non_snake_case)] // to mimic source |
| 327 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]to_epoch_day().(&self) -> IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { |
| 328 | const srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.: u32 = 82; |
| 329 | const Krust-analyzer cargo jiff 0.2.18 shared/util/itime/K.: u32 = 719468 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().146097 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.; |
| 330 | const Lrust-analyzer cargo jiff 0.2.18 shared/util/itime/L.: u32 = 400 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().srust-analyzer cargo jiff 0.2.18 shared/util/itime/s.; |
| 331 | |
| 332 | let year = self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. as u32; |
| 333 | let month = self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month. as u32; |
| 334 | let day = self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. as u32; |
| 335 | |
| 336 | let J = month rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]le().2; |
| 337 | let Y = year.wrapping_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_add().(Lrust-analyzer cargo jiff 0.2.18 shared/util/itime/L.).wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_sub().(J as u32); |
| 338 | let M = if J { month rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().12 } else { month }; |
| 339 | let D = day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().1; |
| 340 | let C = Y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().100; |
| 341 | |
| 342 | let y_star = 1461 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().Y rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().4 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().C rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().C rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().4; |
| 343 | let m_star = (979 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Mul<Self>`]mul().M rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Sub<Self>`]sub().2919) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Div<Self>`]div().32; |
| 344 | let N = y_star rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().m_star rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`Add<Self>`]add().D; |
| 345 | |
| 346 | let N_U = N.wrapping_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]wrapping_sub().(Krust-analyzer cargo jiff 0.2.18 shared/util/itime/K.); |
| 347 | let epoch_day = N_U as i32; |
| 348 | IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay# { epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day. } |
| 349 | } |
| 350 | |
| 351 | /// Returns the day of the week for this date. |
| 352 | #[inline] |
| 353 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn weekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]weekday().(&self) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 354 | self.to_epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]to_epoch_day().().weekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]weekday().() |
| 355 | } |
| 356 | |
| 357 | /// Returns the `nth` weekday of the month represented by this date. |
| 358 | /// |
| 359 | /// `nth` must be non-zero and otherwise in the range `-5..=5`. If it |
| 360 | /// isn't, an error is returned. |
| 361 | /// |
| 362 | /// This also returns an error if `abs(nth)==5` and there is no "5th" |
| 363 | /// weekday of this month. |
| 364 | #[inline] |
| 365 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn nth_weekday_of_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]nth_weekday_of_month().( |
| 366 | &self, |
| 367 | nth: i8, |
| 368 | weekday: IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#, |
| 369 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 370 | if nth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().0 || !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][Neg]neg().5 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le().nth && nth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]le().5) { |
| 371 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::NthWeekdayOfMonthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#NthWeekdayOfMonth#); |
| 372 | } |
| 373 | if nth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]gt().0 { |
| 374 | let first_weekday = self.first_of_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]first_of_month().().weekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]weekday().(); |
| 375 | let diff = weekday.sincerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]since().(first_weekday); |
| 376 | let day = diff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().(nth rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul().7; |
| 377 | IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#::try_newrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]try_new().(self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., day) |
| 378 | } else { |
| 379 | let last = self.last_of_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]last_of_month().(); |
| 380 | let last_weekday = last.weekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]weekday().(); |
| 381 | let diff = last_weekday.sincerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]since().(weekday); |
| 382 | let day = last.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().diff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().(nth.absrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]abs().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Mul<Self>`]mul().7; |
| 383 | // Our math can go below 1 when nth is -5 and there is no "5th from |
| 384 | // last" weekday in this month. Since this is outside the bounds |
| 385 | // of `Day`, we can't let this boundary condition escape. So we |
| 386 | // check it here. |
| 387 | if day rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]lt().1 { |
| 388 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::DateInvalidDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays# { |
| 389 | yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#year.: self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., |
| 390 | monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#month.: self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., |
| 391 | }); |
| 392 | } |
| 393 | IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#::try_newrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]try_new().(self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., day) |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /// Returns the day before this date. |
| 398 | #[inline] |
| 399 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn yesterdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]yesterday().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 400 | if self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().1 { |
| 401 | if self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().1 { |
| 402 | let year = self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().1; |
| 403 | if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().10000 { |
| 404 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::Yesterdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Yesterday#); |
| 405 | } |
| 406 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: 12, dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 31 }); |
| 407 | } |
| 408 | let month = self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1; |
| 409 | let day = days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., month); |
| 410 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day., ..self }); |
| 411 | } |
| 412 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1, ..self }) |
| 413 | } |
| 414 | |
| 415 | /// Returns the day after this date. |
| 416 | #[inline] |
| 417 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn tomorrowrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]tomorrow().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 418 | if self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialOrd<Self>`]ge().28 && self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.) { |
| 419 | if self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().12 { |
| 420 | let year = self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1; |
| 421 | if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().10000 { |
| 422 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::Tomorrowrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Tomorrow#); |
| 423 | } |
| 424 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.: 1, dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 1 }); |
| 425 | } |
| 426 | let month = self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().1; |
| 427 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month., dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 1, ..self }); |
| 428 | } |
| 429 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: self.dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().1, ..self }) |
| 430 | } |
| 431 | |
| 432 | /// Returns the year one year before this date. |
| 433 | #[inline] |
| 434 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn prev_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]prev_year().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i16, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 435 | let year = self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Sub<Self>`]sub().1; |
| 436 | if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]le().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][Neg]neg().10_000 { |
| 437 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::YearPreviousrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearPrevious#); |
| 438 | } |
| 439 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(year) |
| 440 | } |
| 441 | |
| 442 | /// Returns the year one year from this date. |
| 443 | #[inline] |
| 444 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn next_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]next_year().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<i16, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 445 | let year = self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Add<Self>`]add().1; |
| 446 | if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().10_000 { |
| 447 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::YearNextrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearNext#); |
| 448 | } |
| 449 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(year) |
| 450 | } |
| 451 | |
| 452 | /// Add the number of days to this date. |
| 453 | #[inline] |
| 454 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn checked_add_daysrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]checked_add_days().( |
| 455 | &self, |
| 456 | amount: i32, |
| 457 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#, RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#> { |
| 458 | match amount { |
| 459 | 0 => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self), |
| 460 | -1 => self.yesterdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]yesterday().(), |
| 461 | 1 => self.tomorrowrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]tomorrow().(), |
| 462 | n => self.to_epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]to_epoch_day().().checked_addrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]checked_add().(n).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|d| d.to_daterust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]to_date().()), |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | #[inline] |
| 467 | fn first_of_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]first_of_month().(&self) -> IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { |
| 468 | IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: 1, ..*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self } |
| 469 | } |
| 470 | |
| 471 | #[inline] |
| 472 | fn last_of_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IDate]last_of_month().(&self) -> IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { |
| 473 | IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#day.: days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(self.yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#year., self.monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate#month.), ..*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self } |
| 474 | } |
| 475 | |
| 476 | #[cfg(test)] |
| 477 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) fn at( |
| 478 | &self, |
| 479 | hour: i8, |
| 480 | minute: i8, |
| 481 | second: i8, |
| 482 | subsec_nanosecond: i32, |
| 483 | ) -> IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { |
| 484 | let time = ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { hour, minute, second, subsec_nanosecond }; |
| 485 | IDateTimerust-analyzer cargo jiff 0.2.18 shared/util/itime/IDateTime# { date: *selfrust-analyzer cargo jiff 0.2.18 shared/util/itime/, time } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /// Represents a clock time. |
| 490 | /// |
| 491 | /// This uses units of hours, minutes, seconds and fractional seconds (to |
| 492 | /// nanosecond precision). |
| 493 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 494 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { |
| 495 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour.: i8, |
| 496 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute.: i8, |
| 497 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second.: i8, |
| 498 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond.: i32, |
| 499 | } |
| 500 | |
| 501 | impl ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { |
| 502 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const ZEROrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]ZERO.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# = |
| 503 | ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour.: 0, minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute.: 0, secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second.: 0, subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond.: 0 }; |
| 504 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]MIN.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# = |
| 505 | ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour.: 0, minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute.: 0, secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second.: 0, subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond.: 0 }; |
| 506 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]MAX.: ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# = ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { |
| 507 | hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour.: 23, |
| 508 | minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute.: 59, |
| 509 | secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second.: 59, |
| 510 | subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond.: 999_999_999, |
| 511 | }; |
| 512 | |
| 513 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 514 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]to_second().(&self) -> ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { |
| 515 | let mut second: i32 = 0; |
| 516 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().(self.hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour. as i32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().3600; |
| 517 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().(self.minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute. as i32) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Mul<Self>`]mul().60; |
| 518 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`AddAssign<Self>`]add_assign().self.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second. as i32; |
| 519 | ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second. } |
| 520 | } |
| 521 | |
| 522 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 523 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]to_nanosecond().(&self) -> ITimeNanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond# { |
| 524 | let mut nanosecond: i64 = 0; |
| 525 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().(self.hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour. as i64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().3_600_000_000_000; |
| 526 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().(self.minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute. as i64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().60_000_000_000; |
| 527 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().(self.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second. as i64) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Mul<Self>`]mul().1_000_000_000; |
| 528 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`AddAssign<Self>`]add_assign().self.subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond. as i64; |
| 529 | ITimeNanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond# { nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond#nanosecond. } |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | /// Represents a single point in the day, to second precision. |
| 534 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 535 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { |
| 536 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second.: i32, |
| 537 | } |
| 538 | |
| 539 | impl ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { |
| 540 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 541 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_timerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimeSecond]to_time().(&self) -> ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { |
| 542 | let mut second = self.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond#second.; |
| 543 | let mut time = ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#::ZEROrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]ZERO.; |
| 544 | if second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 { |
| 545 | time.hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour. = (second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div().3600) as i8; |
| 546 | second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`RemAssign<Self>`]rem_assign().3600; |
| 547 | if second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().0 { |
| 548 | time.minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute. = (second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Div<Self>`]div().60) as i8; |
| 549 | time.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second. = (second rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][`Rem<Self>`]rem().60) as i8; |
| 550 | } |
| 551 | } |
| 552 | time |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | /// Represents a single point in the day, to nanosecond precision. |
| 557 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 558 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct ITimeNanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond# { |
| 559 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond#nanosecond.: i64, |
| 560 | } |
| 561 | |
| 562 | impl ITimeNanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond# { |
| 563 | #[cfg_attr(feature = "perf-inline", inline(always))] |
| 564 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_timerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITimeNanosecond]to_time().(&self) -> ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime# { |
| 565 | let mut nanosecond = self.nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond#nanosecond.; |
| 566 | let mut time = ITimerust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#::ZEROrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[ITime]ZERO.; |
| 567 | if nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().0 { |
| 568 | time.hourrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#hour. = (nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div().3_600_000_000_000) as i8; |
| 569 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign().3_600_000_000_000; |
| 570 | if nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().0 { |
| 571 | time.minuterust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#minute. = (nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div().60_000_000_000) as i8; |
| 572 | nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign().%=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`RemAssign<Self>`]rem_assign().60_000_000_000; |
| 573 | if nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialEq<Self>`]ne().0 { |
| 574 | time.secondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#second. = (nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Div<Self>`]div().1_000_000_000) as i8; |
| 575 | time.subsec_nanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITime#subsec_nanosecond. = |
| 576 | (nanosecond rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][`Rem<Self>`]rem().1_000_000_000) as i32; |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | time |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | /// Represents a weekday. |
| 585 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:)] |
| 586 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) struct IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 587 | /// Range is `1..=6` with `1=Monday`. |
| 588 | offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#offset.: i8, |
| 589 | } |
| 590 | |
| 591 | impl IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 592 | /// Creates a weekday assuming the week starts on Monday and Monday is at |
| 593 | /// offset `0`. |
| 594 | #[inline] |
| 595 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn from_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_monday_zero_offset().(offset: i8) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 596 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(0 <= offset && offset <= 6); |
| 597 | IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_monday_one_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_monday_one_offset().(offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Add<Self>`]add().1) |
| 598 | } |
| 599 | |
| 600 | /// Creates a weekday assuming the week starts on Monday and Monday is at |
| 601 | /// offset `1`. |
| 602 | #[inline] |
| 603 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn from_monday_one_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_monday_one_offset().(offset: i8) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 604 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(1 <= offset && offset <= 7); |
| 605 | IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#offset. } |
| 606 | } |
| 607 | |
| 608 | /// Creates a weekday assuming the week starts on Sunday and Sunday is at |
| 609 | /// offset `0`. |
| 610 | #[inline] |
| 611 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn from_sunday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_sunday_zero_offset().(offset: i8) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 612 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(0 <= offset && offset <= 6); |
| 613 | IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]from_monday_zero_offset().((offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1).rem_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]rem_euclid().(7)) |
| 614 | } |
| 615 | |
| 616 | /// Creates a weekday assuming the week starts on Sunday and Sunday is at |
| 617 | /// offset `1`. |
| 618 | #[cfg(test)] // currently dead code |
| 619 | #[inline] |
| 620 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn from_sunday_one_offset(offset: i8) -> IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday# { |
| 621 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(1 <= offset && offset <= 7); |
| 622 | IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(offset - 1) |
| 623 | } |
| 624 | |
| 625 | /// Returns this weekday as an offset in the range `0..=6` where |
| 626 | /// `0=Monday`. |
| 627 | #[inline] |
| 628 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]to_monday_zero_offset().(self) -> i8 { |
| 629 | self.to_monday_one_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]to_monday_one_offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().1 |
| 630 | } |
| 631 | |
| 632 | /// Returns this weekday as an offset in the range `1..=7` where |
| 633 | /// `1=Monday`. |
| 634 | #[inline] |
| 635 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_monday_one_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]to_monday_one_offset().(self) -> i8 { |
| 636 | self.offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#offset. |
| 637 | } |
| 638 | |
| 639 | /// Returns this weekday as an offset in the range `0..=6` where |
| 640 | /// `0=Sunday`. |
| 641 | #[cfg(test)] // currently dead code |
| 642 | #[inline] |
| 643 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_sunday_zero_offset(self) -> i8 { |
| 644 | (selfrust-analyzer cargo jiff 0.2.18 shared/util/itime/.to_monday_zero_offset() + 1) % 7 |
| 645 | } |
| 646 | |
| 647 | /// Returns this weekday as an offset in the range `1..=7` where |
| 648 | /// `1=Sunday`. |
| 649 | #[cfg(test)] // currently dead code |
| 650 | #[inline] |
| 651 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn to_sunday_one_offset(self) -> i8 { |
| 652 | selfrust-analyzer cargo jiff 0.2.18 shared/util/itime/.to_sunday_zero_offset() + 1 |
| 653 | } |
| 654 | |
| 655 | #[inline] |
| 656 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn sincerust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]since().(self, other: IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#) -> i8 { |
| 657 | (self.to_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]to_monday_zero_offset().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i8][`Sub<Self>`]sub().other.to_monday_zero_offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IWeekday]to_monday_zero_offset().()) |
| 658 | .rem_euclidrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i8]rem_euclid().(7) |
| 659 | } |
| 660 | } |
| 661 | |
| 662 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 663 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) enum IAmbiguousOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset# { |
| 664 | Unambiguousrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Unambiguous# { offsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Unambiguous#offset.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# }, |
| 665 | Gaprust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Gap# { beforerust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Gap#before.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#, afterrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Gap#after.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# }, |
| 666 | Foldrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Fold# { beforerust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Fold#before.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset#, afterrust-analyzer cargo jiff 0.2.18 shared/util/itime/IAmbiguousOffset#Fold#after.: IOffsetrust-analyzer cargo jiff 0.2.18 shared/util/itime/IOffset# }, |
| 667 | } |
| 668 | |
| 669 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)] |
| 670 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) enum RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError# { |
| 671 | DateInvalidDayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear#year.: i16 }, |
| 672 | DateInvalidDayOfYearNoLeaprust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYearNoLeap#, |
| 673 | DateInvalidDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#year.: i16, monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#month.: i8 }, |
| 674 | DateTimeSecondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateTimeSeconds#, |
| 675 | DayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DayOfYear#, |
| 676 | EpochDayDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayDays#, |
| 677 | EpochDayI32rust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayI32#, |
| 678 | NthWeekdayOfMonthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#NthWeekdayOfMonth#, |
| 679 | Tomorrowrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Tomorrow#, |
| 680 | YearNextrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearNext#, |
| 681 | YearPreviousrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearPrevious#, |
| 682 | Yesterdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Yesterday#, |
| 683 | } |
| 684 | |
| 685 | impl corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError# { |
| 686 | fn fmtrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[RangeError][Display]fmt().(&self, f: &mut corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 687 | use selfrust-analyzer cargo jiff 0.2.18 shared/util/itime/::RangeErrorrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#::*; |
| 688 | |
| 689 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 690 | DateInvalidDayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYear#year. } => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 691 | f, |
| 692 | "number of days for `{year:04}` is invalid, \ |
| 693 | must be in range `1..={max_day}`", |
| 694 | max_day = days_in_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_year().(year), |
| 695 | ), |
| 696 | DateInvalidDayOfYearNoLeaprust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDayOfYearNoLeap# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 697 | "number of days is invalid, must be in range `1..=365`", |
| 698 | ), |
| 699 | DateInvalidDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays# { yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#year., monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateInvalidDays#month. } => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 700 | f, |
| 701 | "number of days for `{year:04}-{month:02}` is invalid, \ |
| 702 | must be in range `1..={max_day}`", |
| 703 | max_day = days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(year, month), |
| 704 | ), |
| 705 | DateTimeSecondsrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DateTimeSeconds# => { |
| 706 | f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("adding seconds to datetime overflowed") |
| 707 | } |
| 708 | DayOfYearrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#DayOfYear# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().("day of year is invalid"), |
| 709 | EpochDayDaysrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayDays# => writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!( |
| 710 | f, |
| 711 | "adding to epoch day resulted in a value outside \ |
| 712 | the allowed range of `{min}..={max}`", |
| 713 | min = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#::MINrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MIN..epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day., |
| 714 | max = IEpochDayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#::MAXrust-analyzer cargo jiff 0.2.18 shared/util/itime/impl#[IEpochDay]MAX..epoch_dayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IEpochDay#epoch_day., |
| 715 | ), |
| 716 | EpochDayI32rust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#EpochDayI32# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 717 | "adding to epoch day overflowed 32-bit signed integer", |
| 718 | ), |
| 719 | NthWeekdayOfMonthrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#NthWeekdayOfMonth# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 720 | "invalid nth weekday of month, \ |
| 721 | must be non-zero and in range `-5..=5`", |
| 722 | ), |
| 723 | Tomorrowrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Tomorrow# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 724 | "returning tomorrow for `9999-12-31` is not \ |
| 725 | possible because it is greater than Jiff's supported |
| 726 | maximum date", |
| 727 | ), |
| 728 | YearNextrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearNext# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 729 | "creating a date for a year following `9999` is \ |
| 730 | not possible because it is greater than Jiff's supported \ |
| 731 | maximum date", |
| 732 | ), |
| 733 | YearPreviousrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#YearPrevious# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 734 | "creating a date for a year preceding `-9999` is \ |
| 735 | not possible because it is less than Jiff's supported \ |
| 736 | minimum date", |
| 737 | ), |
| 738 | Yesterdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/RangeError#Yesterday# => f.write_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[`Formatter<'a>`]write_str().( |
| 739 | "returning yesterday for `-9999-01-01` is not \ |
| 740 | possible because it is less than Jiff's supported |
| 741 | minimum date", |
| 742 | ), |
| 743 | } |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | /// Returns true if and only if the given year is a leap year. |
| 748 | /// |
| 749 | /// A leap year is a year with 366 days. Typical years have 365 days. |
| 750 | #[inline] |
| 751 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn is_leap_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/is_leap_year().(year: i16) -> bool { |
| 752 | // From: https://github.com/BurntSushi/jiff/pull/23 |
| 753 | let d = if year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem().25 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]ne().0 { 4 } else { 16 }; |
| 754 | (year rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem().%rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i16][`Rem<Self>`]rem().d) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialEq<Self>`]eq().0 |
| 755 | } |
| 756 | |
| 757 | /// Return the number of days in the given year. |
| 758 | #[inline] |
| 759 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn days_in_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_year().(year: i16) -> i16 { |
| 760 | if is_leap_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/is_leap_year().(year) { |
| 761 | 366 |
| 762 | } else { |
| 763 | 365 |
| 764 | } |
| 765 | } |
| 766 | |
| 767 | /// Return the number of days in the given month. |
| 768 | #[inline] |
| 769 | pub(craterust-analyzer cargo jiff 0.2.18 crate/) const fn days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(year: i16, month: i8) -> i8 { |
| 770 | // From: https://github.com/BurntSushi/jiff/pull/23 |
| 771 | if month rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i8][`PartialEq<Self>`]eq().2 { |
| 772 | if is_leap_yearrust-analyzer cargo jiff 0.2.18 shared/util/itime/is_leap_year().(year) { |
| 773 | 29 |
| 774 | } else { |
| 775 | 28 |
| 776 | } |
| 777 | } else { |
| 778 | 30 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitOr<Self>`]bitor().|rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitOr<Self>`]bitor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitOr<Self>`]bitor().(month rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitXor<Self>`]bitxor().^rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitXor<Self>`]bitxor(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`BitXor<Self>`]bitxor().month rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[i8][`Shr<i32>`]shr().3) |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | #[cfg(test)] |
| 783 | mod tests { |
| 784 | use superrust-analyzer cargo jiff 0.2.18 shared/util/::*; |
| 785 | |
| 786 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 787 | fn roundtrip_epochday_date() { |
| 788 | for year in -9999..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#9999 { |
| 789 | for month in 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#12 { |
| 790 | for day in 1..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#days_in_monthrust-analyzer cargo jiff 0.2.18 shared/util/itime/days_in_month().(year, month) { |
| 791 | let date = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year, month, day }; |
| 792 | let epoch_day = date.to_epoch_day(); |
| 793 | let date_roundtrip = epoch_day.to_date(); |
| 794 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(date, date_roundtrip); |
| 795 | } |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 801 | fn roundtrip_second_time() { |
| 802 | for second in 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#86_399 { |
| 803 | let second = ITimeSecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeSecond# { second }; |
| 804 | let time = second.to_time(); |
| 805 | let second_roundtrip = time.to_second(); |
| 806 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(second, second_roundtrip); |
| 807 | } |
| 808 | } |
| 809 | |
| 810 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 811 | fn roundtrip_nanosecond_time() { |
| 812 | for second in 0..=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeInclusive#86_399 { |
| 813 | for nanosecond in |
| 814 | [0, 250_000_000, 500_000_000, 750_000_000, 900_000_000] |
| 815 | { |
| 816 | let nanosecond = ITimeNanosecondrust-analyzer cargo jiff 0.2.18 shared/util/itime/ITimeNanosecond# { |
| 817 | nanosecond: (second * 1_000_000_000 + nanosecond), |
| 818 | }; |
| 819 | let time = nanosecond.to_time(); |
| 820 | let nanosecond_roundtrip = time.to_nanosecond(); |
| 821 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(nanosecond, nanosecond_roundtrip); |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 827 | fn nth_weekday() { |
| 828 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2017, month: 3, day: 1 }; |
| 829 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(5); |
| 830 | let d2 = d1.nth_weekday_of_month(2, wday).unwrap(); |
| 831 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2017, month: 3, day: 10 }); |
| 832 | |
| 833 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2024, month: 3, day: 1 }; |
| 834 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(4); |
| 835 | let d2 = d1.nth_weekday_of_month(-1, wday).unwrap(); |
| 836 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2024, month: 3, day: 28 }); |
| 837 | |
| 838 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2024, month: 3, day: 25 }; |
| 839 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(1); |
| 840 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d1.nth_weekday_of_month(5, wday).is_err()); |
| 841 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(d1.nth_weekday_of_month(-5, wday).is_err()); |
| 842 | |
| 843 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 1998, month: 1, day: 1 }; |
| 844 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(6); |
| 845 | let d2 = d1.nth_weekday_of_month(5, wday).unwrap(); |
| 846 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 1998, month: 1, day: 31 }); |
| 847 | } |
| 848 | |
| 849 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 850 | fn weekday() { |
| 851 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(0); |
| 852 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday.to_monday_one_offset(), 7); |
| 853 | |
| 854 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_monday_one_offset(7); |
| 855 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday.to_sunday_zero_offset(), 0); |
| 856 | |
| 857 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_one_offset(1); |
| 858 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday.to_monday_zero_offset(), 6); |
| 859 | |
| 860 | let wday = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_monday_zero_offset(6); |
| 861 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday.to_sunday_one_offset(), 1); |
| 862 | } |
| 863 | |
| 864 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 865 | fn weekday_since() { |
| 866 | let wday1 = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(0); |
| 867 | let wday2 = IWeekdayrust-analyzer cargo jiff 0.2.18 shared/util/itime/IWeekday#::from_sunday_zero_offset(6); |
| 868 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday2.since(wday1), 6); |
| 869 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(wday1.since(wday2), 1); |
| 870 | } |
| 871 | |
| 872 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 873 | fn leap_year() { |
| 874 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!is_leap_year(1900)); |
| 875 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_leap_year(2000)); |
| 876 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!is_leap_year(2001)); |
| 877 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!is_leap_year(2002)); |
| 878 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!is_leap_year(2003)); |
| 879 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_leap_year(2004)); |
| 880 | } |
| 881 | |
| 882 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 883 | fn number_of_days_in_month() { |
| 884 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 1), 31); |
| 885 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 2), 29); |
| 886 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 3), 31); |
| 887 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 4), 30); |
| 888 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 5), 31); |
| 889 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 6), 30); |
| 890 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 7), 31); |
| 891 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 8), 31); |
| 892 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 9), 30); |
| 893 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 10), 31); |
| 894 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 11), 30); |
| 895 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2024, 12), 31); |
| 896 | |
| 897 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 1), 31); |
| 898 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 2), 28); |
| 899 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 3), 31); |
| 900 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 4), 30); |
| 901 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 5), 31); |
| 902 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 6), 30); |
| 903 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 7), 31); |
| 904 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 8), 31); |
| 905 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 9), 30); |
| 906 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 10), 31); |
| 907 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 11), 30); |
| 908 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2025, 12), 31); |
| 909 | |
| 910 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(1900, 2), 28); |
| 911 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(days_in_month(2000, 2), 29); |
| 912 | } |
| 913 | |
| 914 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 915 | fn yesterday() { |
| 916 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 4, day: 7 }; |
| 917 | let d2 = d1.yesterday().unwrap(); |
| 918 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2025, month: 4, day: 6 }); |
| 919 | |
| 920 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 4, day: 1 }; |
| 921 | let d2 = d1.yesterday().unwrap(); |
| 922 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2025, month: 3, day: 31 }); |
| 923 | |
| 924 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 1, day: 1 }; |
| 925 | let d2 = d1.yesterday().unwrap(); |
| 926 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2024, month: 12, day: 31 }); |
| 927 | |
| 928 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: -9999, month: 1, day: 1 }; |
| 929 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d1.yesterday().ok(), None); |
| 930 | } |
| 931 | |
| 932 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 933 | fn tomorrow() { |
| 934 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 4, day: 7 }; |
| 935 | let d2 = d1.tomorrow().unwrap(); |
| 936 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2025, month: 4, day: 8 }); |
| 937 | |
| 938 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 3, day: 31 }; |
| 939 | let d2 = d1.tomorrow().unwrap(); |
| 940 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2025, month: 4, day: 1 }); |
| 941 | |
| 942 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 2025, month: 12, day: 31 }; |
| 943 | let d2 = d1.tomorrow().unwrap(); |
| 944 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d2, IDate { year: 2026, month: 1, day: 1 }); |
| 945 | |
| 946 | let d1 = IDaterust-analyzer cargo jiff 0.2.18 shared/util/itime/IDate# { year: 9999, month: 12, day: 31 }; |
| 947 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(d1.tomorrow().ok(), None); |
| 948 | } |
| 949 | |
| 950 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 951 | fn from_day_of_year() { |
| 952 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 953 | IDate::from_day_of_year(9999, 365), |
| 954 | Ok(IDate { year: 9999, month: 12, day: 31 }), |
| 955 | ); |
| 956 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 957 | IDate::from_day_of_year(9998, 366), |
| 958 | Err(RangeError::DateInvalidDayOfYear { year: 9998 }), |
| 959 | ); |
| 960 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!( |
| 961 | IDate::from_day_of_year(9999, 366), |
| 962 | Err(RangeError::DayOfYear), |
| 963 | ); |
| 964 | } |
| 965 | } |