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/armenian.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::Armenian;
6
use crate::calendar::CommonWeekOfYear;
7
use crate::calendar::HasIntercalaryDays;
8
use crate::calendar::ToFromCommonDate;
9
use crate::calendar::ToFromOrdinalDate;
10
use crate::clock::TimeOfDay;
11
use crate::day_count::ToFixed;
12
use crate::day_cycle::Weekday;
13
use crate::display::moment::DisplayMomentItem;
14
use crate::display::prelude::PresetDisplay;
15
use crate::display::private::fmt_days_since_epoch;
16
use crate::display::private::fmt_number;
17
use crate::display::private::fmt_quarter;
18
use crate::display::private::fmt_seconds_since_epoch;
19
use crate::display::private::fmt_string;
20
use crate::display::private::get_dict;
21
use crate::display::private::DisplayItem;
22
use crate::display::private::NumericContent;
23
use crate::display::text::prelude::Language;
24
use crate::display::LONG_DATE;
25
use crate::display::LONG_DAY_OF_MONTH;
26
use crate::display::YYYYMMDD_DASH;
27
use std::fmt;
28
29
use crate::display::private::TextContent;
30
31
use crate::display::private::DisplayOptions;
32
33
impl DisplayItem for Armenian {
34
1
    fn supported_lang(lang: Language) -> bool {
35
1
        get_dict(lang).armenian.as_ref().is_some()
36
1
    }
37
38
15.1k
    fn fmt_numeric(&self, n: NumericContent, opt: DisplayOptions) -> String {
39
15.1k
        match n {
40
            NumericContent::Month | NumericContent::DayOfMonth | NumericContent::Year => {
41
12.8k
                self.to_common_date().fmt_numeric(n, opt)
42
            }
43
0
            NumericContent::DayOfWeek => self.convert::<Weekday>().fmt_numeric(n, opt),
44
512
            NumericContent::DayOfYear => self.to_ordinal().fmt_numeric(n, opt),
45
            NumericContent::Hour1to12
46
            | NumericContent::Hour0to23
47
            | NumericContent::Minute
48
768
            | NumericContent::Second => self.convert::<TimeOfDay>().fmt_numeric(n, opt),
49
512
            NumericContent::SecondsSinceEpoch => fmt_seconds_since_epoch(*self, opt),
50
0
            NumericContent::Quarter => fmt_quarter(*self, opt),
51
512
            NumericContent::DaysSinceEpoch => fmt_days_since_epoch(*self, opt),
52
0
            NumericContent::ComplementaryDay => "".to_string(),
53
0
            NumericContent::WeekOfYear => fmt_number(self.week_of_year() as i16, opt),
54
        }
55
15.1k
    }
56
13.2k
    fn fmt_text(&self, t: TextContent, lang: Language, opt: DisplayOptions) -> String {
57
        //https://en.wikipedia.org/wiki/Armenian_calendar
58
13.2k
        match (t, get_dict(lang).armenian.as_ref()) {
59
3.58k
            (TextContent::MonthName, Some(dict)) => {
60
3.58k
                let months: [&str; 13] = [
61
3.58k
                    dict.nawasardi,
62
3.58k
                    dict.hori,
63
3.58k
                    dict.sahmi,
64
3.58k
                    dict.tre,
65
3.58k
                    dict.kaloch,
66
3.58k
                    dict.arach,
67
3.58k
                    dict.mehekani,
68
3.58k
                    dict.areg,
69
3.58k
                    dict.ahekani,
70
3.58k
                    dict.mareri,
71
3.58k
                    dict.margach,
72
3.58k
                    dict.hrotich,
73
3.58k
                    dict.aweleac,
74
3.58k
                ];
75
3.58k
                let m = self.to_common_date().month;
76
3.58k
                let name = months[m as usize - 1];
77
3.58k
                fmt_string(name, opt)
78
            }
79
2.54k
            (TextContent::DayOfMonthName, Some(dict)) => {
80
2.54k
                let days: [&str; 30] = [
81
2.54k
                    dict.areg_day,
82
2.54k
                    dict.hrand,
83
2.54k
                    dict.aram,
84
2.54k
                    dict.margar,
85
2.54k
                    dict.ahrank,
86
2.54k
                    dict.mazdel,
87
2.54k
                    dict.astlik,
88
2.54k
                    dict.mihr,
89
2.54k
                    dict.jopaber,
90
2.54k
                    dict.murc,
91
2.54k
                    dict.erezhan,
92
2.54k
                    dict.ani,
93
2.54k
                    dict.parkhar,
94
2.54k
                    dict.vanat,
95
2.54k
                    dict.aramazd,
96
2.54k
                    dict.mani,
97
2.54k
                    dict.asak,
98
2.54k
                    dict.masis,
99
2.54k
                    dict.anahit,
100
2.54k
                    dict.aragats,
101
2.54k
                    dict.gorgor,
102
2.54k
                    dict.kordvik,
103
2.54k
                    dict.tsmak,
104
2.54k
                    dict.lusnak,
105
2.54k
                    dict.tsron,
106
2.54k
                    dict.npat,
107
2.54k
                    dict.vahagn,
108
2.54k
                    dict.sim,
109
2.54k
                    dict.varag,
110
2.54k
                    dict.giseravar,
111
2.54k
                ];
112
2.54k
                match self.day_name() {
113
2.54k
                    Some(d) => fmt_string(days[d as usize - 1], opt),
114
0
                    None => fmt_string("", opt),
115
                }
116
            }
117
            (TextContent::DayOfWeekName, Some(_)) => {
118
3.58k
                self.convert::<Weekday>().fmt_text(t, lang, opt)
119
            }
120
            (TextContent::HalfDayName | TextContent::HalfDayAbbrev, Some(_)) => {
121
0
                self.convert::<TimeOfDay>().fmt_text(t, lang, opt)
122
            }
123
2.56k
            (TextContent::EraName, Some(dict)) => {
124
2.56k
                if self.to_common_date().year < 0 {
125
1.26k
                    fmt_string(dict.before_epoch_full, opt)
126
                } else {
127
1.29k
                    fmt_string(dict.after_epoch_full, opt)
128
                }
129
            }
130
1.02k
            (TextContent::EraAbbreviation, Some(dict)) => {
131
1.02k
                if self.to_common_date().year < 0 {
132
518
                    fmt_string(dict.before_epoch_abr, opt)
133
                } else {
134
506
                    fmt_string(dict.after_epoch_abr, opt)
135
                }
136
            }
137
0
            (_, _) => fmt_string("", opt),
138
        }
139
13.2k
    }
140
}
141
142
impl PresetDisplay for Armenian {
143
2.56k
    fn long_date(&self) -> String {
144
2.56k
        let p = match self.complementary() {
145
2.54k
            None => LONG_DAY_OF_MONTH,
146
18
            Some(_) => LONG_DATE,
147
        };
148
2.56k
        self.preset_str(Language::EN, p)
149
2.56k
    }
150
}
151
152
impl fmt::Display for Armenian {
153
2.56k
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154
2.56k
        write!(f, "{}", self.long_date())
155
2.56k
    }
156
}
157
158
impl DisplayMomentItem for Armenian {}
159
160
#[cfg(test)]
161
mod tests {
162
    use super::*;
163
164
    #[test]
165
1
    fn expected_languages() {
166
1
        assert!(Armenian::supported_lang(Language::EN));
167
1
    }
168
}