Skip to content

Commit

Permalink
Show current time if fs::metadata errors
Browse files Browse the repository at this point in the history
  • Loading branch information
TanmayPatil105 committed Apr 4, 2024
1 parent 61fb065 commit 72da7fc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ pub fn do_write_line(
pub fn get_modification_time(file_path: &str) -> String {
use chrono::{DateTime, Local};
use std::fs;
use std::time::SystemTime;

let modification_time: SystemTime = fs::metadata(file_path)
.and_then(|m| m.modified())
.unwrap_or(SystemTime::now());

let metadata = fs::metadata(file_path).expect("Failed to get metadata");
let modification_time = metadata
.modified()
.expect("Failed to get modification time");
let modification_time: DateTime<Local> = modification_time.into();
let modification_time: String = modification_time
.format("%Y-%m-%d %H:%M:%S%.9f %z")
Expand Down

0 comments on commit 72da7fc

Please sign in to comment.