Last active
January 30, 2019 09:35
-
-
Save endor/09339daf97ea33418ab69492d8f2cb75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn parse_date(string: String) -> Option<DateTime<Utc>> { | |
let year = string.get(..4).and_then(|y| y.parse::<i32>().ok()); | |
let month = string.get(4..6).and_then(|m| m.parse::<u32>().ok()); | |
let day = string.get(6..8).and_then(|d| d.parse::<u32>().ok()); | |
let hour = string.get(9..11).and_then(|h| h.parse::<u32>().ok()); | |
let minute = string.get(12..14).and_then(|mm| mm.parse::<u32>().ok()); | |
let sec = string.get(15..17).and_then(|s| s.parse::<u32>().ok()); | |
let ss = string.get(18..21).and_then(|ss| ss.parse::<u32>().ok()); | |
let r = if year.is_some() && month.is_some() && day.is_some() && hour.is_some() | |
&& minute.is_some() && sec.is_some() && ss.is_some() { | |
Some(Utc.ymd(year.unwrap(), month.unwrap(), day.unwrap()).and_hms_milli( | |
hour.unwrap(), minute.unwrap(), sec.unwrap(), ss.unwrap())) | |
} else { | |
None | |
}; | |
} | |
fn calculate_time_span(start_time: DateTime<Utc>, end_time: DateTime<Utc>) -> i32 { | |
(start_time.timestamp_millis() - end_time.timestamp_millis()).abs() as i32 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment