1pub mod account;
2pub mod app_auth;
3pub mod error_codes;
4pub mod forgot;
5pub mod login;
6pub mod oauth;
7pub mod project;
8pub mod repository;
9pub mod runner;
10pub mod signup;
11
12pub mod ar_date_format {
13 use chrono::{DateTime, Utc};
14 use serde::{self, Deserialize, Deserializer, Serializer};
15
16 const FORMAT: &str = "%Y-%m-%dT%H:%M:%S%.f%#z";
17
18 pub fn serialize<S>(date: &DateTime<Utc>, serializer: S) -> Result<S::Ok, S::Error>
26 where
27 S: Serializer,
28 {
29 let s = format!("{}", date.naive_utc());
30 serializer.serialize_str(&s)
31 }
32
33 pub fn deserialize<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
41 where
42 D: Deserializer<'de>,
43 {
44 let s = String::deserialize(deserializer)?;
45 DateTime::parse_from_str(&s, FORMAT)
46 .map(|dt| dt.with_timezone(&Utc))
47 .map_err(serde::de::Error::custom)
48 }
49
50 #[cfg(test)]
51 mod tests {
52 use super::*;
53 use chrono::TimeZone;
54 use serde_json::json;
55 #[test]
56 fn test_ar_date_format() {
57 let date = Utc.with_ymd_and_hms(2020, 1, 1, 0, 0, 0);
58 let json = json!("2020-01-01T00:00:00Z");
59 assert_eq!(serde_json::to_value(date.unwrap()).unwrap(), json);
60 }
61 }
62}