!184 修改rtc_base.c时钟转换算法问题及rtc_base.h无效逻辑判断

Merge pull request !184 from 贾子扬/OpenHarmony-2.2-Beta2
This commit is contained in:
openharmony_ci
2021-08-20 07:12:17 +00:00
committed by Gitee
2 changed files with 8 additions and 9 deletions
+4 -4
View File
@@ -44,10 +44,10 @@ extern "C" {
#define IS_INVALID_YEAR(year) ((year) < RTC_BEGIN_YEAR)
#define IS_INVALID_MONTH(m) (((m) < RTC_JANUARY) || ((m) > RTC_MAX_MONTH))
#define IS_INVALID_WEEKDAY(wd) (((wd) < 1) || ((wd) > RTC_MAX_WEEKDAY))
#define IS_INVALID_HOUR(hour) (((hour) < 0) || ((hour) >= RTC_MAX_HOUR))
#define IS_INVALID_MIN(min) (((min) < 0) || ((min) >= RTC_MAX_MINUTE))
#define IS_INVALID_SECOND(s) (((s) < 0) || ((s) >= RTC_MAX_SECOND))
#define IS_INVALID_MS(ms) (((ms) < 0) || ((ms) >= RTC_MAX_MS))
#define IS_INVALID_HOUR(hour) ((hour) >= RTC_MAX_HOUR)
#define IS_INVALID_MIN(min) ((min) >= RTC_MAX_MINUTE)
#define IS_INVALID_SECOND(s) ((s) >= RTC_MAX_SECOND)
#define IS_INVALID_MS(ms) ((ms) >= RTC_MAX_MS)
enum RtcMonth {
RTC_JANUARY = 1,
+4 -5
View File
@@ -98,14 +98,14 @@ uint64_t RtcTimeToTimestamp(const struct RtcTime *time)
seconds = ((uint64_t)time->hour * RTC_MAX_MINUTE + time->minute) * RTC_MAX_SECOND + time->second;
days = time->day - RTC_UNIT_DIFF;
month = time->month - RTC_UNIT_DIFF;
month = time->month;
year = time->year;
while (--month >= 0) {
for (month--; month >= RTC_JANUARY; month--) {
days += RtcGetMonthDays(IS_LEAP_YEAR(time->year), month);
}
while (--year >= RTC_BEGIN_YEAR) {
for (year--; year >= RTC_BEGIN_YEAR; year--) {
days += RTC_YEAR_DAYS(year);
}
@@ -129,7 +129,7 @@ void TimestampToRtcTime(struct RtcTime *time, const uint64_t seconds)
time->year++;
}
time->month = 0;
time->month = RTC_JANUARY;
while (days >= RtcGetMonthDays(IS_LEAP_YEAR(time->year), time->month)) {
days -= RtcGetMonthDays(IS_LEAP_YEAR(time->year), time->month);
time->month++;
@@ -140,7 +140,6 @@ void TimestampToRtcTime(struct RtcTime *time, const uint64_t seconds)
time->minute = (daySeconds % RTC_HOUR_SECONDS) / RTC_MAX_MINUTE;
time->hour = daySeconds / RTC_HOUR_SECONDS;
time->month += RTC_UNIT_DIFF;
time->day += RTC_UNIT_DIFF;
time->weekday = RtcGetWeekDay(time);
PLAT_LOGV("TimestampToRtc:year-month-day weekday hour:min:second ms %04u-%02u-%02u %u %02u:%02u:%02u .%03u",