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