rustolio_utils/time/
date.rs1use super::{CalendarMonth, Error, Month, Result, Timezone, Weekday};
12
13#[derive(Clone, Copy, PartialEq, Eq)]
14pub struct Date(pub(super) ::time::Date);
15
16impl Date {
17 pub const fn new(day: u8, month: Month, year: i32) -> Result<Self> {
18 let Ok(date) = time::Date::from_calendar_date(year, month, day) else {
19 return Err(Error::OutOfRange);
20 };
21 Ok(Self(date))
22 }
23
24 pub fn now(timezone: Timezone) -> Result<Self> {
25 let dt = super::DateTime::now(timezone)?;
26 Ok(dt.into_parts().0)
27 }
28
29 pub const fn year(&self) -> i32 {
30 self.0.year()
31 }
32
33 pub const fn month(&self) -> Month {
34 self.0.month()
35 }
36
37 pub const fn day(&self) -> u8 {
38 self.0.day()
39 }
40
41 pub const fn weekday(&self) -> Weekday {
42 self.0.weekday()
43 }
44
45 pub const fn iso_week(&self) -> u8 {
46 self.0.iso_week()
47 }
48
49 pub const fn calendar_month(&self) -> CalendarMonth {
50 CalendarMonth::new(self.year(), self.month())
51 }
52}