From 8e71fdd3ae15c837243b8a86ea7388864aff0033 Mon Sep 17 00:00:00 2001 From: fengyang Date: Thu, 10 Oct 2024 21:52:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=93=9D=E9=BB=84=E5=B7=AE=E5=BC=82=E6=95=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- services/packageusage/src/bundle_active_calendar.cpp | 6 +++--- utils/src/bundle_active_util.cpp | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/services/packageusage/src/bundle_active_calendar.cpp b/services/packageusage/src/bundle_active_calendar.cpp index 7c34eaa..5653b57 100644 --- a/services/packageusage/src/bundle_active_calendar.cpp +++ b/services/packageusage/src/bundle_active_calendar.cpp @@ -47,7 +47,7 @@ void BundleActiveCalendar::TruncateToWeek() time_ -= time_ % weekMilliseconds_; return; } - int64_t weekStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_DAILY); + int64_t weekStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_WEEKLY); if (weekStartTime == 0) { return; } @@ -60,7 +60,7 @@ void BundleActiveCalendar::TruncateToMonth() time_ -= time_ % monthMilliseconds_; return; } - int64_t monthStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_DAILY); + int64_t monthStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_MONTHLY); if (monthStartTime == 0) { return; } @@ -73,7 +73,7 @@ void BundleActiveCalendar::TruncateToYear() time_ -= time_ % yearMilliseconds_; return; } - int64_t yearStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_DAILY); + int64_t yearStartTime = BundleActiveUtil::GetIntervalTypeStartTime(time_, BundleActiveUtil::PERIOD_YEARLY); if (yearStartTime == 0) { return; } diff --git a/utils/src/bundle_active_util.cpp b/utils/src/bundle_active_util.cpp index 80f61c4..a92f91f 100644 --- a/utils/src/bundle_active_util.cpp +++ b/utils/src/bundle_active_util.cpp @@ -29,6 +29,7 @@ const int64_t MIN_OF_MIDNIGHT = 0; const int64_t SECOND_TO_MIDNIGHT = 0; const int64_t STATR_DAY_OF_MON = 1; const int64_t STATR_MON_OF_YEAR = 0; +const int64_t ERROR_TIME = 0; std::string BundleActiveUtil::GetBundleUsageKey(const std::string &bundleName, const int32_t uid) { return bundleName + std::to_string(uid); @@ -41,8 +42,14 @@ int64_t BundleActiveUtil::GetFFRTDelayTime(const int64_t& delayTime) int64_t BundleActiveUtil::GetIntervalTypeStartTime(const int64_t& timeStamp, const int32_t& intervalType) { + if (timeStamp <= 0) { + return ERROR_TIME; + } time_t time = timeStamp / MILLISECOND_TO_SECOND; std::tm* tm_time = std::localtime(&time); + if (tm_time == nullptr) { + return ERROR_TIME; + } tm_time->tm_hour = HOUR_OF_MIDNIGHT; tm_time->tm_min = MIN_OF_MIDNIGHT; tm_time->tm_sec = SECOND_TO_MIDNIGHT; -- Gitee