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/coptic.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::Coptic;
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::CopticMonth;
27
28
impl DisplayItem for Coptic {
29
1
    fn supported_lang(lang: Language) -> bool {
30
1
        get_dict(lang).coptic.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
10.7k
    fn fmt_text(&self, t: TextContent, lang: Language, opt: DisplayOptions) -> String {
53
10.7k
        match (t, get_dict(lang).coptic.as_ref()) {
54
3.58k
            (TextContent::MonthName, Some(dict)) => {
55
3.58k
                let months: [&str; 13] = [
56
3.58k
                    dict.thoout,
57
3.58k
                    dict.paope,
58
3.58k
                    dict.athor,
59
3.58k
                    dict.koiak,
60
3.58k
                    dict.tobe,
61
3.58k
                    dict.meshir,
62
3.58k
                    dict.paremotep,
63
3.58k
                    dict.parmoute,
64
3.58k
                    dict.pashons,
65
3.58k
                    dict.paone,
66
3.58k
                    dict.epep,
67
3.58k
                    dict.mesore,
68
3.58k
                    dict.epagomene,
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
3.58k
            (TextContent::DayOfWeekName, _) => self.convert::<Weekday>().fmt_text(t, lang, opt),
74
            (TextContent::HalfDayName | TextContent::HalfDayAbbrev, _) => {
75
0
                self.convert::<TimeOfDay>().fmt_text(t, lang, opt)
76
            }
77
2.56k
            (TextContent::EraName, Some(dict)) => {
78
2.56k
                if self.to_common_date().year < 0 {
79
1.22k
                    fmt_string(dict.before_martyrs_full, opt)
80
                } else {
81
1.33k
                    fmt_string(dict.after_martyrs_full, opt)
82
                }
83
            }
84
1.02k
            (TextContent::EraAbbreviation, Some(dict)) => {
85
1.02k
                if self.to_common_date().year < 0 {
86
500
                    fmt_string(dict.before_martyrs_abr, opt)
87
                } else {
88
524
                    fmt_string(dict.after_martyrs_abr, opt)
89
                }
90
            }
91
0
            (_, _) => String::from(""),
92
        }
93
10.7k
    }
94
}
95
96
impl PresetDisplay for Coptic {}
97
98
impl fmt::Display for Coptic {
99
2.56k
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
100
2.56k
        write!(f, "{}", self.long_date())
101
2.56k
    }
102
}
103
104
impl DisplayMomentItem for Coptic {}
105
106
#[cfg(test)]
107
mod tests {
108
    use super::*;
109
110
    #[test]
111
1
    fn expected_languages() {
112
1
        assert!(Coptic::supported_lang(Language::EN));
113
1
    }
114
}