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