Skip to main content

nil_log/
timer.rs

1// Copyright (C) Call of Nil contributors
2// SPDX-License-Identifier: AGPL-3.0-only
3
4use jiff::Zoned;
5use jiff::fmt::StdFmtWrite;
6use jiff::fmt::temporal::DateTimePrinter;
7use std::fmt;
8use tracing_subscriber::fmt::format::Writer;
9use tracing_subscriber::fmt::time::FormatTime;
10
11const PRINTER: DateTimePrinter = DateTimePrinter::new()
12  .separator(b' ')
13  .precision(Some(3));
14
15#[derive(Debug)]
16pub struct Timer;
17
18impl FormatTime for Timer {
19  fn format_time(&self, w: &mut Writer<'_>) -> fmt::Result {
20    PRINTER
21      .print_datetime(&Zoned::now().datetime(), StdFmtWrite(w))
22      .map_err(|_| fmt::Error)
23  }
24}