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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use crate::Error;
use rbs::Value;
use std::fmt::{Debug, Display, Formatter};
use std::str::FromStr;

#[derive(serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq, Hash)]
#[serde(rename = "Date")]
pub struct Date(pub fastdate::Date);

impl Display for Date {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "Date({})", self.0)
    }
}

impl Debug for Date {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "Date({})", self.0)
    }
}

impl From<Date> for Value {
    fn from(arg: Date) -> Self {
        Value::Ext("Date", Box::new(Value::String(arg.0.to_string())))
    }
}

impl FromStr for Date {
    type Err = Error;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Ok(Date(fastdate::Date::from_str(s)?))
    }
}

impl From<Date> for fastdate::Date{
    fn from(value: Date) -> Self {
        value.0
    }
}

impl Default for Date{
    fn default() -> Self {
        Date(fastdate::Date{
            day: 1,
            mon: 1,
            year: 1970,
        })
    }
}