1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef OHOS_GLOBAL_I18N_CALENDAR_H 16 #define OHOS_GLOBAL_I18N_CALENDAR_H 17 18 #include <cmath> 19 #include <cstdint> 20 21 #include "iosfwd" 22 #include "unicode/locid.h" 23 #include "unicode/calendar.h" 24 #include "unicode/ucal.h" 25 #include "unicode/utypes.h" 26 27 namespace OHOS { 28 namespace Global { 29 namespace I18n { 30 enum CalendarType { 31 BUDDHIST, 32 CHINESE, 33 COPTIC, 34 ETHIOPIC, 35 HEBREW, 36 GREGORY, 37 INDIAN, 38 ISLAMIC_CIVIL, 39 ISLAMIC_TBLA, 40 ISLAMIC_UMALQURA, 41 JAPANESE, 42 PERSIAN, 43 UNDEFINED 44 }; 45 46 class I18nCalendar { 47 public: 48 explicit I18nCalendar(std::string localeTag); 49 I18nCalendar(std::string localeTag, CalendarType type); 50 virtual ~I18nCalendar(); 51 void SetTime(double value); 52 void Set(int32_t year, int32_t month, int32_t date); 53 void Set(UCalendarDateFields field, int32_t value); 54 std::string GetTimeZone(void); 55 void SetTimeZone(std::string timezoneId); 56 int32_t Get(UCalendarDateFields field) const; 57 void Add(UCalendarDateFields field, int32_t amount); 58 void SetMinimalDaysInFirstWeek(int32_t value); 59 void SetFirstDayOfWeek(int32_t value); 60 UDate GetTimeInMillis(void); 61 int32_t GetMinimalDaysInFirstWeek(void); 62 int32_t GetFirstDayOfWeek(void); 63 bool IsWeekend(int64_t date, UErrorCode &status); 64 bool IsWeekend(void); 65 std::string GetDisplayName(std::string &displayLocaleTag); 66 int32_t CompareDays(UDate date); 67 68 private: 69 icu::Calendar *calendar_; 70 void InitCalendar(const icu::Locale &locale, CalendarType type); 71 void InitCalendar2(const icu::Locale &locale, CalendarType type, UErrorCode &status); 72 }; 73 } // namespace I18n 74 } // namespace Global 75 } // namespace OHOS 76 #endif