isbnlib/jsonb/
block.rs

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
use serde::{Deserialize, Serialize};
use chrono;

#[derive(
    Serialize,
    Deserialize,
    Debug,
    Clone,
    PartialEq,
)]
pub struct Block {
    #[serde(rename(deserialize = "type"))]
    pub value_type: String,
    pub value: String
}

impl Block {
    pub fn to_string(self) -> String {
        self.value.to_string()
    }

    pub fn to_timestamp(self) -> chrono::NaiveDateTime {
        chrono::NaiveDateTime::parse_from_str(&self.to_string(), "%Y-%m-%dT%H:%M:%S%.f").expect("Failed parse datetime")
    }
}