use chrono::{DateTime, Datelike, NaiveDateTime, Offset, Timelike};
use super::DateTimeParts;
impl<Tz> DateTimeParts for DateTime<Tz>
where
Tz: chrono::TimeZone,
DateTime<Tz>: Ord,
{
#[inline]
fn year(&self) -> i32 {
Datelike::year(self)
}
#[inline]
fn month(&self) -> u8 {
Datelike::month(self) as u8
}
#[inline]
fn day(&self) -> u8 {
Datelike::day(self) as u8
}
#[inline]
fn hour(&self) -> u8 {
Timelike::hour(self) as u8
}
#[inline]
fn minute(&self) -> u8 {
Timelike::minute(self) as u8
}
#[inline]
fn second(&self) -> u8 {
Timelike::second(self) as u8
}
#[inline]
fn nanosecond(&self) -> u32 {
Timelike::nanosecond(self).min(999_999_999)
}
#[inline]
fn all_parts(&self) -> (i32, u8, u8, u8, u8, u8, u32) {
self.naive_local().all_parts()
}
#[inline]
fn to_same_time_zone(&self, other: Self) -> Self {
if self.offset().fix() == other.offset().fix() {
other
} else {
other.with_timezone(&self.timezone())
}
}
}
impl DateTimeParts for NaiveDateTime {
#[inline]
fn year(&self) -> i32 {
Datelike::year(self)
}
#[inline]
fn month(&self) -> u8 {
Datelike::month(self) as u8
}
#[inline]
fn day(&self) -> u8 {
Datelike::day(self) as u8
}
#[inline]
fn hour(&self) -> u8 {
Timelike::hour(self) as u8
}
#[inline]
fn minute(&self) -> u8 {
Timelike::minute(self) as u8
}
#[inline]
fn second(&self) -> u8 {
Timelike::second(self) as u8
}
#[inline]
fn nanosecond(&self) -> u32 {
Timelike::nanosecond(self).min(999_999_999)
}
}