dos_date_time/dos_date/
consts.rs

1// SPDX-FileCopyrightText: 2025 Shun Sakai
2//
3// SPDX-License-Identifier: Apache-2.0 OR MIT
4
5//! Constants for [`Date`].
6
7use super::Date;
8
9impl Date {
10    /// The smallest value that can be represented by the MS-DOS date.
11    ///
12    /// This is "1980-01-01".
13    ///
14    /// # Examples
15    ///
16    /// ```
17    /// # use dos_date_time::{Date, time::macros::date};
18    /// #
19    /// assert_eq!(Date::MIN, Date::from_date(date!(1980-01-01)).unwrap());
20    /// ```
21    // SAFETY: the given MS-DOS date is valid as the smallest MS-DOS date.
22    pub const MIN: Self = unsafe { Self::new_unchecked(0b0000_0000_0010_0001) };
23
24    /// The largest value that can be represented by the MS-DOS date.
25    ///
26    /// This is "2107-12-31".
27    ///
28    /// # Examples
29    ///
30    /// ```
31    /// # use dos_date_time::{Date, time::macros::date};
32    /// #
33    /// assert_eq!(Date::MAX, Date::from_date(date!(2107-12-31)).unwrap());
34    /// ```
35    // SAFETY: the given MS-DOS date is valid as the largest MS-DOS date.
36    pub const MAX: Self = unsafe { Self::new_unchecked(0b1111_1111_1001_1111) };
37}
38
39#[cfg(test)]
40mod tests {
41    use time::macros::date;
42
43    use super::*;
44
45    #[test]
46    fn min() {
47        assert_eq!(Date::MIN, Date::from_date(date!(1980-01-01)).unwrap());
48    }
49
50    #[test]
51    fn max() {
52        assert_eq!(Date::MAX, Date::from_date(date!(2107-12-31)).unwrap());
53    }
54}