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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_TIME_COMPONENT_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_TIME_COMPONENT_H 18 19 #include "base/i18n/localization.h" 20 #include "core/components/picker/picker_base_component.h" 21 22 namespace OHOS::Ace { 23 24 class ACE_EXPORT PickerTimeComponent : public PickerBaseComponent { 25 DECLARE_ACE_TYPE(PickerTimeComponent, PickerBaseComponent); 26 27 public: 28 PickerTimeComponent(); 29 30 ~PickerTimeComponent() override = default; 31 GetSelectedTime()32 const PickerTime& GetSelectedTime() const 33 { 34 return selectedTime_; 35 } SetSelectedTime(const PickerTime & value)36 void SetSelectedTime(const PickerTime& value) 37 { 38 selectedTime_ = value; 39 } 40 GetHasSecond()41 bool GetHasSecond() const 42 { 43 return hasSecond_; 44 } SetHasSecond(bool value)45 void SetHasSecond(bool value) 46 { 47 hasSecond_ = value; 48 } 49 GetHour24()50 bool GetHour24() const 51 { 52 return hour24_; 53 } SetHour24(bool value)54 void SetHour24(bool value) 55 { 56 hour24_ = value; 57 } 58 GetEnableCascade()59 bool GetEnableCascade() const 60 { 61 return isEnableCascade_; 62 } SetEnableCascade(bool value)63 void SetEnableCascade(bool value) 64 { 65 isEnableCascade_ = value; 66 } 67 68 void OnTitleBuilding() override; 69 70 void OnColumnsBuilding() override; 71 72 std::string GetSelectedObject(bool isColumnChange, 73 const std::string& changeColumnTag, int32_t status = -1) const override; 74 75 void OnDataLinking(const std::string& tag, bool isAdd, uint32_t index, 76 std::vector<std::string>& resultTags) override; 77 78 void OnSelectedSaving() override; 79 80 void OnColumnsCreating() override; 81 82 protected: 83 PickerTime GetCurrentTime() const; 84 85 void HandleHour24Change(bool isAdd, uint32_t index, std::vector<std::string>& resultTags); 86 87 void HandleHour12Change(bool isAdd, uint32_t index, std::vector<std::string>& resultTags); 88 89 bool IsAmHour(uint32_t hourOf24) const; 90 91 uint32_t GetAmPmHour(uint32_t hourOf24) const; 92 93 uint32_t GetHourFromAmPm(bool isAm, uint32_t amPmhour) const; 94 95 std::string GetAmFormatString() const; 96 97 std::string GetPmFormatString() const; 98 99 void HandleHourColumnBuilding(); 100 101 std::string AddZeroPrefix(const std::string& value) const; 102 103 std::string GetHourFormatString(uint32_t hour) const; 104 105 std::string GetMinuteFormatString(uint32_t minute) const; 106 107 std::string GetSecondFormatString(uint32_t second) const; 108 109 private: 110 PickerTime selectedTime_ = PickerTime::Current(); 111 bool hasSecond_ = false; 112 // true, use 24 hours style; false, use 12 hours style. 113 bool hour24_ = !Localization::GetInstance()->IsAmPmHour(); 114 bool isEnableCascade_ = false; 115 std::vector<std::string> vecAmPm_; 116 }; 117 118 } // namespace OHOS::Ace 119 120 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_TIME_COMPONENT_H 121