diff options
| -rw-r--r-- | src/date.rs | 2 | ||||
| -rw-r--r-- | src/datetime.rs | 61 | ||||
| -rw-r--r-- | src/lib.rs | 4 | ||||
| -rw-r--r-- | src/time.rs | 10 |
4 files changed, 71 insertions, 6 deletions
diff --git a/src/date.rs b/src/date.rs index 2751e53..bc2d7dd 100644 --- a/src/date.rs +++ b/src/date.rs @@ -37,6 +37,8 @@ impl Date { Self { year, month, day } } + // TODO docs + pub const fn year(self) -> Year { self.year } diff --git a/src/datetime.rs b/src/datetime.rs new file mode 100644 index 0000000..54685ec --- /dev/null +++ b/src/datetime.rs @@ -0,0 +1,61 @@ +use crate::{Date, Month, Time, Year}; + +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +pub struct NaiveDateTime { + date: Date, + time: Time, +} + +impl NaiveDateTime { + // TODO docs + + pub const fn new(date: Date, time: Time) -> Self { + Self { date, time } + } + + pub const fn date(self) -> Date { + self.date + } + + pub const fn time(self) -> Time { + self.time + } + + pub const fn year(self) -> Year { + self.date.year() + } + + pub const fn month(self) -> Month { + self.date.month() + } + + pub const fn day(self) -> u8 { + self.date.day() + } + + pub const fn hour(self) -> u8 { + self.time.hour() + } + + pub const fn minute(self) -> u8 { + self.time.minute() + } + + pub const fn second(self) -> u8 { + self.time.second() + } + + pub const fn millisecond(self) -> u16 { + self.time.millisecond() + } + + pub const fn microsecond(self) -> u32 { + self.time.microsecond() + } + + pub const fn nanosecond(self) -> u32 { + self.time.nanosecond() + } +} + +// TODO addition @@ -1,12 +1,16 @@ #![doc = include_str!("../README.md")] +// TODO must uses + mod date; +mod datetime; mod month; mod time; mod weekday; mod year; pub use date::Date; +pub use datetime::NaiveDateTime; pub use month::Month; pub use time::Time; pub use weekday::Weekday; diff --git a/src/time.rs b/src/time.rs index 6981c94..94f7cd8 100644 --- a/src/time.rs +++ b/src/time.rs @@ -1,5 +1,3 @@ -use std::ops::Add; - #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct Time { hour: u8, @@ -107,14 +105,14 @@ impl Time { // Get the millisecond within the second. // The returned value will always be in the range `0..1_000` - pub const fn millisecond(self) -> u8 { - (self.nanosecond / 1_000_000) as u8 + pub const fn millisecond(self) -> u16 { + (self.nanosecond / 1_000_000) as u16 } // Get the microsecond within the second. // The returned value will always be in the range `0..1_000_000` - pub const fn microsecond(self) -> u8 { - (self.nanosecond / 1_000) as u8 + pub const fn microsecond(self) -> u32 { + (self.nanosecond / 1_000) as u32 } // Get the nanosecond within the second. |
