Debian Codegraph @

intl/components/src/calendar/ICU4XChineseBasedCalendar.h

raw
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 http://mozilla.org/MPL/2.0/. */
4 #ifndef intl_components_calendar_ICU4XChineseBasedCalendar_h_
5 #define intl_components_calendar_ICU4XChineseBasedCalendar_h_
6
7 #include "mozilla/intl/calendar/ICU4XCalendar.h"
8
9 #include <stdint.h>
10 #include <string_view>
11
12 namespace mozilla::intl::calendar {
13
14 /**
15 * Abstract base class for Chinese-based calendars.
16 *
17 * Overrides the same methods as icu::ChineseCalendar to ensure compatible
18 * behavior even when using ICU4X as the underlying calendar implementation.
19 */
20 class ICU4XChineseBasedCalendar : public ICU4XCalendar {
21 protected:
22 ICU4XChineseBasedCalendar(capi::ICU4XAnyCalendarKind kind,
23 const icu::Locale& locale, UErrorCode& success);
24 ICU4XChineseBasedCalendar(capi::ICU4XAnyCalendarKind kind,
25 const icu::TimeZone& timeZone,
26 const icu::Locale& locale, UErrorCode& success);
27 ICU4XChineseBasedCalendar(const ICU4XChineseBasedCalendar& other);
28
29 public:
30 ICU4XChineseBasedCalendar() = delete;
31 virtual ~ICU4XChineseBasedCalendar();
32
33 protected:
34 bool hasLeapMonths() const override;
35 bool hasMonthCode(MonthCode monthCode) const override;
36 bool requiresFallbackForExtendedYear(int32_t year) const override;
37 bool requiresFallbackForGregorianYear(int32_t year) const override;
38
39 /**
40 * Difference to the related Gregorian year.
41 */
42 virtual int32_t relatedYearDifference() const = 0;
43
44 static constexpr int32_t chineseRelatedYearDiff = -2637;
45
46 public:
47 bool inTemporalLeapYear(UErrorCode& status) const override;
48 int32_t getRelatedYear(UErrorCode& status) const override;
49 void setRelatedYear(int32_t year) override;
50
51 protected:
52 void handleComputeFields(int32_t julianDay, UErrorCode& status) override;
53 int32_t handleGetLimit(UCalendarDateFields field,
54 ELimitType limitType) const override;
55 const icu::UFieldResolutionTable* getFieldResolutionTable() const override;
56
57 private:
58 static const icu::UFieldResolutionTable CHINESE_DATE_PRECEDENCE[];
59 };
60
61 } // namespace mozilla::intl::calendar
62
63 #endif