1/* 2 * Copyright (c) 2020-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#include "components/ui_abstract_clock.h" 17 18namespace OHOS { 19void UIAbstractClock::SetTime24Hour(uint8_t hour, uint8_t minute, uint8_t second) 20{ 21 currentHour_ = hour % ONE_DAY_IN_HOUR; 22 currentMinute_ = minute % ONE_HOUR_IN_MINUTE; 23 currentSecond_ = second % ONE_MINUTE_IN_SECOND; 24 UpdateClock(false); 25} 26 27void UIAbstractClock::SetTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am) 28{ 29 SetTime24Hour((hour % HALF_DAY_IN_HOUR) + (am ? 0 : HALF_DAY_IN_HOUR), minute, second); 30} 31 32void UIAbstractClock::IncOneSecond() 33{ 34 currentSecond_++; 35 currentMinute_ += currentSecond_ / ONE_MINUTE_IN_SECOND; 36 currentSecond_ = currentSecond_ % ONE_MINUTE_IN_SECOND; 37 38 currentHour_ += currentMinute_ / ONE_HOUR_IN_MINUTE; 39 currentMinute_ = currentMinute_ % ONE_HOUR_IN_MINUTE; 40 currentHour_ = currentHour_ % ONE_DAY_IN_HOUR; 41 42 UpdateClock(false); 43 Invalidate(); 44} 45 46void UIAbstractClock::SetWorkMode(WorkMode newMode) 47{ 48 if (mode_ != newMode) { 49 mode_ = newMode; 50 Invalidate(); 51 } 52} 53 54void UIAbstractClock::UpdateClock(bool clockInit) 55{ 56 Invalidate(); 57} 58} // namespace OHOS 59