mirror of
https://github.com/veeso/termscp.git
synced 2026-04-15 14:41:34 -07:00
draw log list
This commit is contained in:
20
src/utils.rs
20
src/utils.rs
@@ -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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user