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