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/ethiopic.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::CommonWeekOfYear;
6
use crate::calendar::Ethiopic;
7
use crate::calendar::ToFromCommonDate;
8
use crate::calendar::ToFromOrdinalDate;
9
use crate::clock::TimeOfDay;
10
use crate::day_count::ToFixed;
11
use crate::day_cycle::Weekday;
12
use crate::display::moment::DisplayMomentItem;
13
use crate::display::prelude::PresetDisplay;
14
use crate::display::private::fmt_days_since_epoch;
15
use crate::display::private::fmt_number;
16
use crate::display::private::fmt_quarter;
17
use crate::display::private::fmt_seconds_since_epoch;
18
use crate::display::private::fmt_string;
19
use crate::display::private::get_dict;
20
use crate::display::private::DisplayItem;
21
use crate::display::private::DisplayOptions;
22
use crate::display::private::NumericContent;
23
use crate::display::private::TextContent;
24
use crate::display::text::prelude::Language;
25
use std::fmt;
26
//use crate::calendar::EthiopicMonth;
27
28
impl DisplayItem for Ethiopic {
29
1
    fn supported_lang(lang: Language) -> bool {
30
1
        get_dict(lang).ethiopic.as_ref().is_some()
31
1
    }
32
33
17.6k
    fn fmt_numeric(&self, n: NumericContent, opt: DisplayOptions) -> String {
34
17.6k
        match n {
35
            NumericContent::Month | NumericContent::DayOfMonth | NumericContent::Year => {
36
15.3k
                self.to_common_date().fmt_numeric(n, opt)
37
            }
38
0
            NumericContent::DayOfWeek => self.convert::<Weekday>().fmt_numeric(n, opt),
39
512
            NumericContent::DayOfYear => self.to_ordinal().fmt_numeric(n, opt),
40
            NumericContent::Hour1to12
41
            | NumericContent::Hour0to23
42
            | NumericContent::Minute
43
768
            | NumericContent::Second => self.convert::<TimeOfDay>().fmt_numeric(n, opt),
44
512
            NumericContent::SecondsSinceEpoch => fmt_seconds_since_epoch(*self, opt),
45
0
            NumericContent::Quarter => fmt_quarter(*self, opt),
46
512
            NumericContent::DaysSinceEpoch => fmt_days_since_epoch(*self, opt),
47
0
            NumericContent::ComplementaryDay => String::from(""),
48
0
            NumericContent::WeekOfYear => fmt_number(self.week_of_year() as i16, opt),
49
        }
50
17.6k
    }
51
52
11.0k
    fn fmt_text(&self, t: TextContent, lang: Language, opt: DisplayOptions) -> String {
53
11.0k
        match (t, get_dict(lang).ethiopic.as_ref()) {
54
3.58k
            (TextContent::MonthName, Some(dict)) => {
55
3.58k
                let months: [&str; 13] = [
56
3.58k
                    dict.maskaram,
57
3.58k
                    dict.teqemt,
58
3.58k
                    dict.hedar,
59
3.58k
                    dict.takhsas,
60
3.58k
                    dict.ter,
61
3.58k
                    dict.yakatit,
62
3.58k
                    dict.magabit,
63
3.58k
                    dict.miyazya,
64
3.58k
                    dict.genbot,
65
3.58k
                    dict.sane,
66
3.58k
                    dict.hamle,
67
3.58k
                    dict.nahase,
68
3.58k
                    dict.paguemen,
69
3.58k
                ];
70
3.58k
                let name = months[self.to_common_date().month as usize - 1];
71
3.58k
                fmt_string(name, opt)
72
            }
73
0
            (TextContent::DayOfMonthName, _) => fmt_string("", opt),
74
3.58k
            (TextContent::DayOfWeekName, _) => self.convert::<Weekday>().fmt_text(t, lang, opt),
75
            (TextContent::HalfDayName | TextContent::HalfDayAbbrev, _) => {
76
0
                self.convert::<TimeOfDay>().fmt_text(t, lang, opt)
77
            }
78
2.56k
            (TextContent::EraName, Some(dict)) => {
79
2.56k
                if self.to_common_date().year < 0 {
80
1.28k
                    fmt_string(dict.before_incarnation_full, opt)
81
                } else {
82
1.28k
                    fmt_string(dict.after_incarnation_full, opt)
83
                }
84
            }
85
1.02k
            (TextContent::EraAbbreviation, Some(dict)) => {
86
1.02k
                if self.to_common_date().year < 0 {
87
520
                    fmt_string(dict.before_incarnation_abr, opt)
88
                } else {
89
504
                    fmt_string(dict.after_incarnation_abr, opt)
90
                }
91
            }
92
256
            (_, _) => String::from(""),
93
        }
94
11.0k
    }
95
}
96
97
impl PresetDisplay for Ethiopic {}
98
99
impl fmt::Display for Ethiopic {
100
2.56k
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
101
2.56k
        write!(f, "{}", self.long_date())
102
2.56k
    }
103
}
104
105
impl DisplayMomentItem for Ethiopic {}
106
107
#[cfg(test)]
108
mod tests {
109
    use super::*;
110
111
    #[test]
112
1
    fn expected_languages() {
113
1
        assert!(Ethiopic::supported_lang(Language::EN));
114
1
    }
115
}