blob: df366f6717aa7c5f81fb5d0dcda0b604bf15a724 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
use crate::Time;
use chrono::{FixedOffset as Offset, NaiveDate};
/// A convenienc wrapper around [chrono::NaiveDate](chrono::NaiveDate)
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
pub struct Date {
inner: NaiveDate,
}
impl Date {
pub fn today() -> Self {
Self::from(Time::now().date())
}
pub(crate) fn from(d: chrono::Date<Offset>) -> Self {
Self {
inner: d.naive_local(),
}
}
}
impl From<NaiveDate> for Date {
fn from(inner: NaiveDate) -> Self {
Self { inner }
}
}
impl ToString for Date {
fn to_string(&self) -> String {
format!("{}", self.inner.format("%Y-%m-%d"))
}
}
|