Coverage Report

Created: 2025-08-13 21:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/home/a220/proj/radnelac/src/display/moment.rs
Line
Count
Source
1
// This Source Code Form is subject to the terms of the Mozilla Public
2
// License, v. 2.0. If a copy of the MPL was not distributed with this
3
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5
use crate::calendar::CalendarMoment;
6
use crate::display::private::DisplayItem;
7
use crate::display::private::DisplayOptions;
8
use crate::display::private::NumericContent;
9
use crate::display::private::TextContent;
10
use crate::display::Language;
11
use crate::display::PresetDisplay;
12
use crate::display::HHMMSS_COLON;
13
use std::fmt;
14
15
use crate::clock::ClockTime;
16
17
pub trait DisplayMomentItem {}
18
19
impl<T: DisplayItem + Clone + DisplayMomentItem> DisplayItem for CalendarMoment<T> {
20
0
    fn supported_lang(lang: Language) -> bool {
21
0
        T::supported_lang(lang) && ClockTime::supported_lang(lang)
22
0
    }
23
24
74.6k
    fn fmt_numeric(&self, n: NumericContent, opt: DisplayOptions) -> String {
25
74.6k
        match n {
26
            NumericContent::Hour1to12
27
            | NumericContent::Hour0to23
28
            | NumericContent::Minute
29
58.3k
            | NumericContent::Second => self.clone().time_of_day().fmt_numeric(n, opt),
30
16.3k
            _ => self.clone().date().fmt_numeric(n, opt),
31
        }
32
74.6k
    }
33
34
24.5k
    fn fmt_text(&self, t: TextContent, lang: Language, opt: DisplayOptions) -> String {
35
24.5k
        match t {
36
            TextContent::HalfDayName | TextContent::HalfDayAbbrev => {
37
0
                self.clone().time_of_day().fmt_text(t, lang, opt)
38
            }
39
24.5k
            _ => self.clone().date().fmt_text(t, lang, opt),
40
        }
41
24.5k
    }
42
}
43
44
impl<T: PresetDisplay + Clone + DisplayMomentItem> PresetDisplay for CalendarMoment<T> {
45
0
    fn long_date(&self) -> String {
46
0
        self.clone().date().long_date()
47
0
    }
48
49
0
    fn short_date(&self) -> String {
50
0
        self.clone().date().short_date()
51
0
    }
52
}
53
54
impl<T: fmt::Display + PresetDisplay + Clone + DisplayMomentItem> fmt::Display
55
    for CalendarMoment<T>
56
{
57
19.4k
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
58
19.4k
        write!(f, "{} ", self.preset_str(Language::EN, HHMMSS_COLON));
59
19.4k
        self.clone().date().fmt(f)
60
19.4k
    }
61
}