oxedyne/fe2o3/fe2o3_net/src/time.rs
1000 bytes, 7 runs
created by r1870400018:603, which is this file's identity for as long as the history lasts, whatever it is later renamed to
download · who wrote it · its history
| 1 | use oxedyne_fe2o3_core::prelude::*; |
| 2 | |
| 3 | use chrono::{ |
| 4 | Utc, |
| 5 | TimeZone, |
| 6 | }; |
| 7 | |
| 8 | use std::time::Duration; |
| 9 | |
| 10 | pub struct Time {} |
| 11 | |
| 12 | impl Time { |
| 13 | |
| 14 | pub fn fmt_http(duration_since_epoch: &Duration) -> Outcome<String> { |
| 15 | let datetime = match Utc.timestamp_opt( |
| 16 | duration_since_epoch.as_secs() as i64, |
| 17 | duration_since_epoch.subsec_nanos(), |
| 18 | ).single() { |
| 19 | Some(dt) => dt, |
| 20 | None => { |
| 21 | debug!("There was a problem with the supplied duration since the UNIX epoch:"); |
| 22 | debug!(" secs: {}", duration_since_epoch.as_secs() as i64); |
| 23 | debug!(" nanos: {}", duration_since_epoch.subsec_nanos()); |
| 24 | return Err(err!( |
| 25 | "The duration '{:?}' has not allowed construction of a valid date/time.", |
| 26 | duration_since_epoch; |
| 27 | Invalid, Input, Mismatch)); |
| 28 | }, |
| 29 | }; |
| 30 | |
| 31 | Ok(datetime.format("%a, %d %b %Y %H:%M:%S GMT").to_string()) |
| 32 | } |
| 33 | |
| 34 | } |