19596a2c1Sopenharmony_ci/*
29596a2c1Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd.
39596a2c1Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
49596a2c1Sopenharmony_ci * you may not use this file except in compliance with the License.
59596a2c1Sopenharmony_ci * You may obtain a copy of the License at
69596a2c1Sopenharmony_ci *
79596a2c1Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
89596a2c1Sopenharmony_ci *
99596a2c1Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
109596a2c1Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
119596a2c1Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
129596a2c1Sopenharmony_ci * See the License for the specific language governing permissions and
139596a2c1Sopenharmony_ci * limitations under the License.
149596a2c1Sopenharmony_ci */
159596a2c1Sopenharmony_ci#ifndef OHOS_GLOBAL_I18N_LUNAR_CALENDAR_H
169596a2c1Sopenharmony_ci#define OHOS_GLOBAL_I18N_LUNAR_CALENDAR_H
179596a2c1Sopenharmony_ci
189596a2c1Sopenharmony_ci#include <string>
199596a2c1Sopenharmony_ci#include <unordered_map>
209596a2c1Sopenharmony_ci#include <vector>
219596a2c1Sopenharmony_ci
229596a2c1Sopenharmony_ci#include "unicode/calendar.h"
239596a2c1Sopenharmony_ci#include "unicode/ucal.h"
249596a2c1Sopenharmony_ci#include "unicode/utypes.h"
259596a2c1Sopenharmony_ci
269596a2c1Sopenharmony_cinamespace OHOS {
279596a2c1Sopenharmony_cinamespace Global {
289596a2c1Sopenharmony_cinamespace I18n {
299596a2c1Sopenharmony_ciclass LunarCalendar {
309596a2c1Sopenharmony_cipublic:
319596a2c1Sopenharmony_ci    LunarCalendar();
329596a2c1Sopenharmony_ci    ~LunarCalendar();
339596a2c1Sopenharmony_ci    bool SetGregorianDate(int32_t year, int32_t month, int32_t day);
349596a2c1Sopenharmony_ci    int32_t GetLunarYear();
359596a2c1Sopenharmony_ci    int32_t GetLunarMonth();
369596a2c1Sopenharmony_ci    int32_t GetLunarDay();
379596a2c1Sopenharmony_ci    bool IsLeapMonth();
389596a2c1Sopenharmony_ci
399596a2c1Sopenharmony_ciprivate:
409596a2c1Sopenharmony_ci    bool VerifyDate(int32_t year, int32_t month, int32_t day);
419596a2c1Sopenharmony_ci    void ConvertDate(int32_t& year, int32_t& month, int32_t& day);
429596a2c1Sopenharmony_ci    void CalcDaysFromBaseDate();
439596a2c1Sopenharmony_ci    void SolorDateToLunarDate();
449596a2c1Sopenharmony_ci    void AdjustLeapMonth(int32_t& i, int32_t tempDaysCounts, int32_t leapMonth);
459596a2c1Sopenharmony_ci    int32_t GetDaysPerLunarYear(int32_t lunarYear);
469596a2c1Sopenharmony_ci    bool IsGregorianLeapYear(int32_t year);
479596a2c1Sopenharmony_ci    static std::unordered_map<int32_t, int32_t> daysOfMonth;
489596a2c1Sopenharmony_ci    static std::unordered_map<int32_t, int32_t> accDaysOfMonth;
499596a2c1Sopenharmony_ci    static std::vector<uint32_t> lunarDateInfo;
509596a2c1Sopenharmony_ci    static const int32_t VALID_START_YEAR = 1900;
519596a2c1Sopenharmony_ci    static const int32_t VALID_END_YEAR = 2100;
529596a2c1Sopenharmony_ci    static const int32_t VALID_START_MONTH = 1;
539596a2c1Sopenharmony_ci    static const int32_t VALID_END_MONTH = 12;
549596a2c1Sopenharmony_ci    static const int32_t VALID_START_DAY = 1;
559596a2c1Sopenharmony_ci    static const int32_t MONTH_FEB = 2;
569596a2c1Sopenharmony_ci    static const int32_t START_YEAR = 1900;
579596a2c1Sopenharmony_ci    static const int32_t END_YEAR = 2100;
589596a2c1Sopenharmony_ci    static const int32_t DAYS_OF_YEAR = 365;
599596a2c1Sopenharmony_ci    static const int32_t YEAR_ERA = 100;
609596a2c1Sopenharmony_ci    static const int32_t FREQ_LEAP_YEAR = 4;
619596a2c1Sopenharmony_ci    static const int32_t DAYS_FROM_SOLAR_TO_LUNAR = 30;
629596a2c1Sopenharmony_ci    static const int32_t BASE_DAYS_PER_LUNAR_YEAR = 348;
639596a2c1Sopenharmony_ci    static const int32_t DAYS_IN_BIG_MONTH = 30;
649596a2c1Sopenharmony_ci    static const int32_t DAYS_IN_SMALL_MONTH = 29;
659596a2c1Sopenharmony_ci
669596a2c1Sopenharmony_ci    int32_t solorYear = -1;
679596a2c1Sopenharmony_ci    int32_t solorMonth = -1;
689596a2c1Sopenharmony_ci    int32_t solorDay = -1;
699596a2c1Sopenharmony_ci    int32_t lunarYear = -1;
709596a2c1Sopenharmony_ci    int32_t lunarMonth = -1;
719596a2c1Sopenharmony_ci    int32_t lunarDay = -1;
729596a2c1Sopenharmony_ci    int32_t daysCounts = 0;
739596a2c1Sopenharmony_ci    bool isLeapMonth = false;
749596a2c1Sopenharmony_ci    bool isGregorianLeapYear = false;
759596a2c1Sopenharmony_ci    bool isValidDate = false;
769596a2c1Sopenharmony_ci    icu::Calendar* calendar_;
779596a2c1Sopenharmony_ci};
789596a2c1Sopenharmony_ci} // namespace I18n
799596a2c1Sopenharmony_ci} // namespace Global
809596a2c1Sopenharmony_ci} // namespace OHOS
819596a2c1Sopenharmony_ci#endif