time_c/
format.rs

1//! Formatting module
2
3use core::fmt;
4
5use crate::Time;
6use crate::sys::tm;
7
8#[repr(transparent)]
9///RFC-3339 encoder for tm
10pub struct Rfc3339<'a, T>(pub &'a T);
11
12impl fmt::Display for Rfc3339<'_, tm> {
13    #[inline(always)]
14    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
15        let normalized = self.0.normalize();
16        fmt::Display::fmt(&Rfc3339(&normalized), fmt)
17    }
18}
19
20impl fmt::Display for Rfc3339<'_, Time> {
21    #[inline(always)]
22    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
23        let Time {
24            sec,
25            min,
26            hour,
27            month_day,
28            month,
29            year,
30            ..
31        } = self.0;
32
33        fmt.write_fmt(format_args!("{year:04}-{month:02}-{month_day:02}T{hour:02}:{min:02}:{sec:02}Z"))
34    }
35}