Skip to content

Commit

Permalink
add error handling for invalid format strings
Browse files Browse the repository at this point in the history
  • Loading branch information
janstarke committed Feb 6, 2024
1 parent 91a4962 commit 1b918e7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/common/forensics_timestamp.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use std::fmt::Display;

use chrono::format::StrftimeItems;
use chrono::offset::TimeZone;
use chrono::{DateTime, FixedOffset, LocalResult, NaiveDateTime};
use chrono_tz::Tz;
use lazy_static::lazy_static;

lazy_static! {
static ref TIMESTAMP_FORMAT: Option<String> = std::env::var("DFIR_DATE").ok();
static ref TIMESTAMP_FORMAT: Option<String> = {
if let Ok(format) = std::env::var("DFIR_DATE") {
if StrftimeItems::new(&format).any(|i| i == chrono::format::Item::Error) {

Check warning on line 12 in src/common/forensics_timestamp.rs

View check run for this annotation

Codecov / codecov/patch

src/common/forensics_timestamp.rs#L12

Added line #L12 was not covered by tests
panic!("ERROR: invalid date format: '{format}'! Aborting execution!")
} else {
Some(format)
}
} else {
None
}
};
static ref ZERO: DateTime<FixedOffset> =
DateTime::<FixedOffset>::parse_from_rfc3339("0000-00-00T00:00:00+00:00").unwrap();
}
Expand Down

0 comments on commit 1b918e7

Please # to comment.