eio_okta_data/
comparable.rs

1use std::collections::BTreeMap;
2
3use ::chrono::{Datelike, Timelike};
4use ::mediatype::ReadParams;
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash, ::comparable::Comparable)]
7pub struct MediaType {
8  type_: String,
9  sub_type: String,
10  suffix: Option<String>,
11  params: BTreeMap<String, String>,
12}
13
14impl From<::mediatype::MediaType<'_>> for MediaType {
15  fn from(borrowed: ::mediatype::MediaType) -> Self {
16    let type_ = borrowed.ty.as_str().to_owned();
17    let sub_type = borrowed.subty.as_str().to_owned();
18    let suffix = borrowed.suffix.map(|suffix| suffix.as_str().to_owned());
19    let params = borrowed
20      .params()
21      .map(|(name, value)| (name.as_str().to_owned(), value.as_str().to_owned()))
22      .collect();
23
24    Self {
25      type_,
26      sub_type,
27      suffix,
28      params,
29    }
30  }
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, ::comparable::Comparable)]
34pub struct DateTime {
35  year: i32,
36  month: u32,
37  day: u32,
38  hour: u32,
39  minute: u32,
40  second: u32,
41}
42
43impl From<::chrono::DateTime<::chrono::Utc>> for DateTime {
44  fn from(datetime: ::chrono::DateTime<::chrono::Utc>) -> Self {
45    let naive = datetime.naive_utc();
46
47    let date = naive.date();
48    let year = date.year();
49    let month = date.month();
50    let day = date.day();
51
52    let time = naive.time();
53    let hour = time.hour();
54    let minute = time.minute();
55    let second = time.second();
56
57    Self {
58      year,
59      month,
60      day,
61      hour,
62      minute,
63      second,
64    }
65  }
66}