• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_GLOBAL_I18N_HOLIDAY_MANAGER_H
16 #define OHOS_GLOBAL_I18N_HOLIDAY_MANAGER_H
17 
18 #include <vector>
19 #include "holiday_manager.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 
23 namespace OHOS {
24 namespace Global {
25 namespace I18n {
26 class HolidayManagerAddon {
27 public:
28     HolidayManagerAddon();
29     ~HolidayManagerAddon();
30     static void Destructor(napi_env env, void *nativeObject, void *hint);
31     static napi_value InitHolidayManager(napi_env env, napi_value exports);
32 
33 private:
34     static napi_value HolidayManagerConstructor(napi_env env, napi_callback_info info);
35     bool InitHolidayManagerContext(napi_env env, napi_callback_info info, const char* path);
36 
37     // process js function call
38     static napi_value IsHoliday(napi_env env, napi_callback_info info);
39     static napi_value GetHolidayInfoItemArray(napi_env env, napi_callback_info info);
40     static std::string GetString(napi_env &env, napi_value &value, int32_t &code);
41     static int32_t ValidateParamNumber(napi_env &env, napi_value &argv);
42     static std::vector<int> ValidateParamDate(napi_env &env, napi_value &argv);
43     static napi_value CreateHolidayItem(napi_env env, const HolidayInfoItem &holidayItem);
44     static napi_value HolidayLocalNameItem(napi_env env, const std::vector<HolidayLocalName> localNames);
45     static napi_value GetHolidayInfoItemResult(napi_env env, std::vector<HolidayInfoItem> itemList);
46     static int GetDateValue(napi_env env, napi_value value, const std::string method);
47 
48     static const int32_t MONTH_INCREASE_ONE = 1; // 1 is real month greater than display
49 
50     napi_env env_;
51     std::unique_ptr<HolidayManager> holidayManager_ = nullptr;
52 };
53 } // namespace I18n
54 } // namespace Global
55 } // namespace OHOS
56 #endif