• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cstdint>
19 
20 #include "iosfwd"
21 #include "locid.h"
22 #include "unicode/calendar.h"
23 #include "unicode/ucal.h"
24 #include "utypes.h"
25 
26 namespace OHOS {
27 namespace Global {
28 namespace I18n {
29 enum CalendarType {
30     BUDDHIST,
31     CHINESE,
32     COPTIC,
33     ETHIOPIC,
34     HEBREW,
35     GREGORY,
36     INDIAN,
37     ISLAMIC_CIVIL,
38     ISLAMIC_TBLA,
39     ISLAMIC_UMALQURA,
40     JAPANESE,
41     PERSIAN,
42     UNDEFINED
43 };
44 
45 class I18nCalendar {
46 public:
47     explicit I18nCalendar(std::string localeTag);
48     I18nCalendar(std::string localeTag, CalendarType type);
49     virtual ~I18nCalendar();
50     void SetTime(double value);
51     void Set(int32_t year, int32_t month, int32_t date);
52     void Set(UCalendarDateFields field, int32_t value);
53     std::string GetTimeZone(void);
54     void SetTimeZone(std::string timezoneId);
55     int32_t Get(UCalendarDateFields field) const;
56     void Add(UCalendarDateFields field, int32_t amount);
57     void SetMinimalDaysInFirstWeek(int32_t value);
58     void SetFirstDayOfWeek(int32_t value);
59     UDate GetTimeInMillis(void);
60     int32_t GetMinimalDaysInFirstWeek(void);
61     int32_t GetFirstDayOfWeek(void);
62     bool IsWeekend(int64_t date, UErrorCode &status);
63     bool IsWeekend(void);
64     std::string GetDisplayName(std::string &displayLocaleTag);
65 private:
66     icu::Calendar *calendar_;
67     void InitCalendar(const icu::Locale &locale, CalendarType type);
68     void InitCalendar2(const icu::Locale &locale, CalendarType type, UErrorCode &status);
69 };
70 } // namespace I18n
71 } // namespace Global
72 } // namespace OHOS
73 #endif