1use std::fmt;
8use std::fmt::{Display, Formatter};
9
10use colored::Colorize as _;
11
12use crate::format::Config;
13use crate::{Context, Date};
14
15pub fn format_date<'cx>(cx: &'cx Context, cfg: Config, date: &'cx Date<'cx>) -> DateDisplay<'cx> {
17 DateDisplay { cx, date, cfg }
18}
19
20#[must_use]
21pub struct DateDisplay<'cx> {
22 cx: &'cx Context,
23 date: &'cx Date<'cx>,
24 cfg: Config,
25}
26
27impl Display for DateDisplay<'_> {
28 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
29 if let Some(date) = self.date.to_date(self.cx) {
30 date.to_string().color(self.cfg.colours.date).fmt(f)
31 } else {
32 panic!("Failed to unbox Date");
33 }
34 }
35}