eio_okta_data/
comparable.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
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::collections::BTreeMap;

use ::chrono::{Datelike, Timelike};
use ::mediatype::ReadParams;

#[derive(Debug, Clone, PartialEq, Eq, Hash, ::comparable::Comparable)]
pub struct MediaType {
  type_: String,
  sub_type: String,
  suffix: Option<String>,
  params: BTreeMap<String, String>,
}

impl From<::mediatype::MediaType<'_>> for MediaType {
  fn from(borrowed: ::mediatype::MediaType) -> Self {
    let type_ = borrowed.ty.as_str().to_owned();
    let sub_type = borrowed.subty.as_str().to_owned();
    let suffix = borrowed.suffix.map(|suffix| suffix.as_str().to_owned());
    let params = borrowed
      .params()
      .map(|(name, value)| (name.as_str().to_owned(), value.as_str().to_owned()))
      .collect();

    Self {
      type_,
      sub_type,
      suffix,
      params,
    }
  }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, ::comparable::Comparable)]
pub struct DateTime {
  year: i32,
  month: u32,
  day: u32,
  hour: u32,
  minute: u32,
  second: u32,
}

impl From<::chrono::DateTime<::chrono::Utc>> for DateTime {
  fn from(datetime: ::chrono::DateTime<::chrono::Utc>) -> Self {
    let naive = datetime.naive_utc();

    let date = naive.date();
    let year = date.year();
    let month = date.month();
    let day = date.day();

    let time = naive.time();
    let hour = time.hour();
    let minute = time.minute();
    let second = time.second();

    Self {
      year,
      month,
      day,
      hour,
      minute,
      second,
    }
  }
}