From 7cee2f9a61fb04f7cfafbd4cd7f50cec5f4f9b69 Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:11:59 -0500 Subject: [PATCH] `sniff`: move SystemTime format logic to helper fn in util.rs --- src/cmd/sniff.rs | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/cmd/sniff.rs b/src/cmd/sniff.rs index 4bbeb44b8..7abf61923 100644 --- a/src/cmd/sniff.rs +++ b/src/cmd/sniff.rs @@ -105,7 +105,7 @@ use std::{ fmt, fs, io::{copy, Seek, SeekFrom, Write}, path::PathBuf, - time::{Duration, SystemTime}, + time::Duration, }; use bytes::Bytes; @@ -125,7 +125,9 @@ use url::Url; use crate::{ config::{Config, Delimiter}, - util, CliResult, + util, + util::format_systemtime, + CliResult, }; #[derive(Deserialize)] @@ -617,18 +619,8 @@ async fn get_file_to_sniff(args: &Args, tmpdir: &tempfile::TempDir) -> CliResult let file_size = metadata.len() as usize; let last_modified = match metadata.modified() { Ok(time) => { - let timestamp = time - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - let naive = chrono::NaiveDateTime::from_timestamp_opt(timestamp as i64, 0) - .unwrap_or_default(); - let datetime = chrono::DateTime::::from_naive_utc_and_offset( - naive, - chrono::Utc, - ); // format the datetime to RFC3339 - format!("{datetime}", datetime = datetime.format("%+")) + format_systemtime(time, "%+") }, Err(_) => "N/A".to_string(), };