commonlibsse_ng\re\c\Calendar/year.rs
1/// Represents the 0-based year.
2///
3/// - Positive years represent years in the Common Era (CE).
4/// - Negative years represent years Before Common Era (BCE).
5///
6/// # Examples
7/// ```
8/// use commonlibsse_ng::re::Calendar::Year;
9/// let year = Year::new(77.0);
10/// assert_eq!(year.to_year(), 77); // CE
11///
12/// let year_bce = Year::new(-500.0);
13/// assert_eq!(year_bce.to_year(), -500); // BCE
14/// ```
15#[derive(Debug, Default, Clone, Copy, PartialEq)]
16#[repr(transparent)]
17pub struct Year(f32);
18
19impl Year {
20 /// The default value for `Year` (`0.0`), representing the start of the Common Era (1 CE).
21 pub const DEFAULT: Self = Self(0.0);
22
23 /// The game-defined default year (`77.0`).
24 pub const GAME_DEFAULT: Self = Self(77.0);
25
26 /// Creates a new `Year` with the specified value.
27 ///
28 /// - Positive values indicate CE years.
29 /// - Negative values indicate BCE years.
30 ///
31 /// # Examples
32 /// ```
33 /// use commonlibsse_ng::re::Calendar::Year;
34 /// let year = Year::new(105.5);
35 /// assert_eq!(year.to_year(), 105); // CE
36 ///
37 /// let year_bce = Year::new(-200.0);
38 /// assert_eq!(year_bce.to_year(), -200); // BCE
39 /// ```
40 #[inline]
41 pub const fn new(value: f32) -> Self {
42 Self(value)
43 }
44
45 /// Returns the year as an integer ([`i32`]), truncating the decimal part.
46 ///
47 /// - Positive values represent CE (e.g., `2025` → `2025 CE`).
48 /// - Negative values represent BCE (e.g., `-500` → `500 BCE`).
49 ///
50 /// # Examples
51 /// ```
52 /// use commonlibsse_ng::re::Calendar::Year;
53 /// let year = Year::new(203.75);
54 /// assert_eq!(year.to_year(), 203); // CE
55 ///
56 /// let year_bce = Year::new(-44.9);
57 /// assert_eq!(year_bce.to_year(), -44); // BCE
58 /// ```
59 #[inline]
60 pub const fn to_year(self) -> i32 {
61 self.0 as i32
62 }
63}