lssa/explorer_service/src/format_utils.rs

18 lines
643 B
Rust
Raw Normal View History

2026-03-10 00:17:43 +03:00
//! Formatting utilities for the explorer.
2026-01-28 03:21:43 +03:00
2026-03-10 00:17:43 +03:00
/// Format timestamp to human-readable string.
2026-03-04 18:42:33 +03:00
#[expect(
clippy::integer_division,
clippy::integer_division_remainder_used,
reason = "We need to convert milliseconds to seconds, and this is the most straightforward way to do it"
)]
2026-01-28 03:21:43 +03:00
pub fn format_timestamp(timestamp: u64) -> String {
let seconds = timestamp / 1000;
2026-03-03 23:21:08 +03:00
let datetime = chrono::DateTime::from_timestamp(
i64::try_from(seconds).expect("Timestamp out of range"),
0,
)
.unwrap_or_else(|| chrono::DateTime::from_timestamp(0, 0).unwrap());
2026-01-28 03:21:43 +03:00
datetime.format("%Y-%m-%d %H:%M:%S UTC").to_string()
}