draw log list

This commit is contained in:
ChristianVisintin
2020-11-29 13:01:12 +01:00
parent c54cbed866
commit 87990d12b5
4 changed files with 109 additions and 35 deletions

View File

@@ -24,10 +24,14 @@
*/
// Dependencies
extern crate chrono;
extern crate whoami;
use crate::filetransfer::FileTransferProtocol;
use chrono::prelude::*;
use std::time::SystemTime;
/// ### parse_remote_opt
///
/// Parse remote option string. Returns in case of success a tuple made of (address, port, protocol, username)
@@ -119,6 +123,16 @@ pub fn parse_remote_opt(
Ok((address, port, protocol, username))
}
/// ### instant_to_str
///
/// Format a `Instant` into a time string
pub fn time_to_str(time: SystemTime, fmt: &str) -> String {
let datetime: DateTime<Local> = time.into();
// Format the datetime how you want
let newdate = datetime.to_rfc3339_opts(SecondsFormat::Secs, true);
format!("{}", datetime.format(fmt))
}
#[cfg(test)]
mod tests {
@@ -175,4 +189,10 @@ mod tests {
assert!(parse_remote_opt(&String::from("172.26.104.1:abc")).is_err()); // Bad port
}
#[test]
fn test_utils_time_to_str() {
let system_time: SystemTime = SystemTime::from(SystemTime::UNIX_EPOCH);
assert_eq!(time_to_str(system_time, "%Y-%m-%d"), String::from("1970-01-01"));
}
}