1 /* 2 * Copyright (c) 2023 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 16 #ifndef OHOS_GLOBAL_HOLIDAY_MANAGER_H 17 #define OHOS_GLOBAL_HOLIDAY_MANAGER_H 18 19 #include <string> 20 #include <vector> 21 #include "map" 22 23 namespace OHOS { 24 namespace Global { 25 namespace I18n { 26 struct HolidayLocalName { 27 // Holiday locale name language id 28 std::string language = ""; 29 30 // Holiday local name 31 std::string name = ""; 32 }; 33 34 struct HolidayInfoItem { 35 // Holiday base name 36 std::string baseName; 37 38 // Holiday start year 39 int32_t year = 0; 40 41 // Holiday start month 42 int32_t month = 0; 43 44 // Holiday start day 45 int32_t day = 0; 46 47 // Holiday local name array 48 std::vector<HolidayLocalName> localNames; 49 }; 50 51 class HolidayManager { 52 public: 53 HolidayManager(const char* path); 54 ~HolidayManager(); 55 bool IsHoliday(); 56 bool IsHoliday(int32_t year, int32_t month, int32_t day); 57 std::vector<HolidayInfoItem> GetHolidayInfoItemArray(int32_t year); 58 std::vector<HolidayInfoItem> GetHolidayInfoItemArray(); 59 void SetHolidayData(std::map<std::string, std::vector<HolidayInfoItem>> holidayDataMap); 60 61 private: 62 std::string ValidateHolidayFilePath(const char* path); 63 std::vector<HolidayInfoItem> ReadHolidayFile(const char* path); 64 void ParseFileLine(const std::string &line, HolidayInfoItem *holidayItem); 65 std::string GetLanguageFromPath(const char* path); 66 static std::string& Trim(std::string &str); 67 std::string Format(int32_t year, int32_t month, int32_t day); 68 std::map<std::string, std::vector<HolidayInfoItem>> holidayItemMap; 69 static const char* ITEM_BEGIN_TAG; 70 static const char* ITEM_END_TAG; 71 static const char* ITEM_DTSTART_TAG; 72 static const char* ITEM_DTEND_TAG; 73 static const char* ITEM_SUMMARY_TAG; 74 static const char* ITEM_RESOURCES_TAG; 75 static const int32_t MONTH_GREATER_ONE = 1; // 1 is real month greater than display 76 static const int32_t YEAR_START = 1900; // 1900 is where tm_year start 77 }; 78 } // namespace I18n 79 } // namespace Global 80 } // namespace OHOS 81 #endif