• 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 
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 
59     void OnTitleBuilding() override;
60 
61     void OnColumnsBuilding() override;
62 
63     std::string GetSelectedObject(bool isColumnChange,
64         const std::string& changeColumnTag, int32_t status = -1) const override;
65 
66     void OnDataLinking(const std::string& tag, bool isAdd, uint32_t index,
67         std::vector<std::string>& resultTags) override;
68 
69     void OnSelectedSaving() override;
70 
71     void OnColumnsCreating() override;
72 
73 protected:
74     PickerTime GetCurrentTime() const;
75 
76     void HandleHour24Change(bool isAdd, uint32_t index, std::vector<std::string>& resultTags);
77 
78     void HandleHour12Change(bool isAdd, uint32_t index, std::vector<std::string>& resultTags);
79 
80     bool IsAmHour(uint32_t hourOf24) const;
81 
82     uint32_t GetAmPmHour(uint32_t hourOf24) const;
83 
84     uint32_t GetHourFromAmPm(bool isAm, uint32_t amPmhour) const;
85 
86     std::string GetAmFormatString() const;
87 
88     std::string GetPmFormatString() const;
89 
90     void HandleHourColumnBuilding();
91 
92     std::string AddZeroPrefix(const std::string& value) const;
93 
94     std::string GetHourFormatString(uint32_t hour) const;
95 
96     std::string GetMinuteFormatString(uint32_t minute) const;
97 
98     std::string GetSecondFormatString(uint32_t second) const;
99 
100 private:
101     PickerTime selectedTime_ = PickerTime::Current();
102     bool hasSecond_ = false;
103     // true, use 24 hours style; false, use 12 hours style.
104     bool hour24_ = !Localization::GetInstance()->IsAmPmHour();
105     std::vector<std::string> vecAmPm_;
106 };
107 
108 } // namespace OHOS::Ace
109 
110 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_TIME_COMPONENT_H
111