replace libc date math with chrono, extract memory_subdir helper
- date_to_epoch, iso_week_info, weeks_in_month: replaced unsafe libc (mktime, strftime, localtime_r) with chrono NaiveDate and IsoWeek - epoch_to_local: replaced unsafe libc localtime_r with chrono Local - New util.rs with memory_subdir() helper: ensures subdir exists and propagates errors instead of silently ignoring them - Removed three duplicate agent_results_dir() definitions across digest.rs, consolidate.rs, enrich.rs - load_digest_files, parse_all_digest_links, find_consolidation_reports now return Result to properly propagate directory creation errors Co-Authored-By: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
parent
50da0b7b26
commit
f4364e299c
7 changed files with 75 additions and 129 deletions
|
|
@ -130,17 +130,15 @@ pub fn now_epoch() -> f64 {
|
|||
/// Convert epoch seconds to broken-down local time components.
|
||||
/// Returns (year, month, day, hour, minute, second).
|
||||
pub fn epoch_to_local(epoch: f64) -> (i32, u32, u32, u32, u32, u32) {
|
||||
// Use libc localtime_r for timezone-correct conversion
|
||||
let secs = epoch as libc::time_t;
|
||||
let mut tm: libc::tm = unsafe { std::mem::zeroed() };
|
||||
unsafe { libc::localtime_r(&secs, &mut tm) };
|
||||
use chrono::{Datelike, Local, TimeZone, Timelike};
|
||||
let dt = Local.timestamp_opt(epoch as i64, 0).unwrap();
|
||||
(
|
||||
tm.tm_year + 1900,
|
||||
(tm.tm_mon + 1) as u32,
|
||||
tm.tm_mday as u32,
|
||||
tm.tm_hour as u32,
|
||||
tm.tm_min as u32,
|
||||
tm.tm_sec as u32,
|
||||
dt.year(),
|
||||
dt.month(),
|
||||
dt.day(),
|
||||
dt.hour(),
|
||||
dt.minute(),
|
||||
dt.second(),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue