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
15pub struct Timer;
16
17impl FormatTime for Timer {
18  fn format_time(&self, w: &mut Writer<'_>) -> fmt::Result {
19    PRINTER
20      .print_datetime(&Zoned::now().datetime(), StdFmtWrite(w))
21      .map_err(|_| fmt::Error)
22  }
23}