1 /* 2 * Copyright (c) 2022 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 "bundle_active_calendar.h" 17 #include "bundle_active_period_stats.h" 18 19 namespace OHOS { 20 namespace DeviceUsageStats { BundleActiveCalendar(const int64_t timeStamp)21BundleActiveCalendar::BundleActiveCalendar(const int64_t timeStamp) 22 { 23 time_ = timeStamp; 24 dayMilliseconds_ = ONE_DAY_TIME; 25 weekMilliseconds_ = ONE_WEEK_TIME; 26 monthMilliseconds_ = ONE_MONTH_TIME; 27 yearMilliseconds_ = ONE_YEAR_TIME; 28 } 29 TruncateToDay()30void BundleActiveCalendar::TruncateToDay() 31 { 32 time_ -= time_ % dayMilliseconds_; 33 } 34 TruncateToWeek()35void BundleActiveCalendar::TruncateToWeek() 36 { 37 time_ -= time_ % weekMilliseconds_; 38 } 39 TruncateToMonth()40void BundleActiveCalendar::TruncateToMonth() 41 { 42 time_ -= time_ % monthMilliseconds_; 43 } 44 TruncateToYear()45void BundleActiveCalendar::TruncateToYear() 46 { 47 time_ -= time_ % yearMilliseconds_; 48 } 49 IncreaseDays(const int64_t val)50void BundleActiveCalendar::IncreaseDays(const int64_t val) 51 { 52 time_ += val * dayMilliseconds_; 53 } 54 IncreaseWeeks(const int64_t val)55void BundleActiveCalendar::IncreaseWeeks(const int64_t val) 56 { 57 time_ += val* weekMilliseconds_; 58 } 59 IncreaseMonths(const int64_t val)60void BundleActiveCalendar::IncreaseMonths(const int64_t val) 61 { 62 time_ += val * monthMilliseconds_; 63 } 64 IncreaseYears(const int64_t val)65void BundleActiveCalendar::IncreaseYears(const int64_t val) 66 { 67 time_ += val * yearMilliseconds_; 68 } 69 SetMilliseconds(const int64_t timeStamp)70void BundleActiveCalendar::SetMilliseconds(const int64_t timeStamp) 71 { 72 time_ = timeStamp; 73 } 74 GetMilliseconds()75int64_t BundleActiveCalendar::GetMilliseconds() 76 { 77 return time_; 78 } 79 ChangeToDebug()80void BundleActiveCalendar::ChangeToDebug() 81 { 82 dayMilliseconds_ = ONE_DAY_TIME_DEBUG; 83 weekMilliseconds_ = ONE_WEEK_TIME_DEBUG; 84 monthMilliseconds_ = ONE_MONTH_TIME_DEBUG; 85 yearMilliseconds_ = ONE_YEAR_TIME_DEBUG; 86 } 87 TruncateTo(int32_t intervalType)88void BundleActiveCalendar::TruncateTo(int32_t intervalType) 89 { 90 switch (intervalType) { 91 case BundleActivePeriodStats::PERIOD_DAILY: 92 TruncateToDay(); 93 break; 94 case BundleActivePeriodStats::PERIOD_WEEKLY: 95 TruncateToWeek(); 96 break; 97 case BundleActivePeriodStats::PERIOD_MONTHLY: 98 TruncateToMonth(); 99 break; 100 case BundleActivePeriodStats::PERIOD_YEARLY: 101 TruncateToYear(); 102 break; 103 default: 104 break; 105 } 106 } 107 } // namespace DeviceUsageStats 108 } // namespace OHOS 109 110