dmesg: support iso time-format.

This commit is contained in:
Fuad Ismail 2024-11-26 10:57:45 +07:00
parent 9f665333cf
commit c13e2f7b5a
2 changed files with 10 additions and 0 deletions

@ -158,6 +158,9 @@ impl Dmesg<'_> {
TimeFormat::Ctime => {
print!("[{}] ", time_formatter::ctime(record.timestamp_us))
}
TimeFormat::Iso => {
print!("{} ", time_formatter::iso(record.timestamp_us))
}
TimeFormat::Raw => {
print!("[{}] ", time_formatter::raw(record.timestamp_us))
}

@ -16,6 +16,13 @@ pub fn ctime(timestamp_us: u64) -> String {
date_time.format("%a %b %d %H:%M:%S %Y").to_string()
}
pub fn iso(timestamp_us: u64) -> String {
let date_time = boot_time()
.checked_add_signed(TimeDelta::microseconds(timestamp_us as i64))
.unwrap();
date_time.format("%Y-%m-%dT%H:%M:%S,%6f%:z").to_string()
}
static BOOT_TIME: OnceLock<DateTime<FixedOffset>> = OnceLock::new();
#[cfg(feature = "fixed-boot-time")]