From 32422e781c571ba723d455555c8eaf104cdc7528 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Thu, 22 Jul 2021 17:21:32 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=AD=A3rtc=5Fbase.c=E6=97=B6?= =?UTF-8?q?=E9=92=9F=E8=BD=AC=E6=8D=A2=E7=AE=97=E6=B3=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E5=8F=8Artc=5Fbase.h=E5=AD=98=E5=9C=A8=E7=9A=84=E6=97=A0?= =?UTF-8?q?=E6=95=88=E9=80=BB=E8=BE=91=E5=88=A4=E6=96=AD=C2=80=C2=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaziyang --- support/platform/include/rtc_base.h | 8 ++++---- support/platform/src/rtc_base.c | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/support/platform/include/rtc_base.h b/support/platform/include/rtc_base.h index ebc7b1fb0..d37fc94c1 100644 --- a/support/platform/include/rtc_base.h +++ b/support/platform/include/rtc_base.h @@ -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, diff --git a/support/platform/src/rtc_base.c b/support/platform/src/rtc_base.c index 5e671ac06..82d0039dd 100644 --- a/support/platform/src/rtc_base.c +++ b/support/platform/src/rtc_base.c @@ -95,17 +95,18 @@ uint64_t RtcTimeToTimestamp(const struct RtcTime *time) HDF_LOGE("RtcTimeToTimestamp: time invalid"); return 0; } - + + 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 +130,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 +141,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", -- Gitee From 715933c1495b6b5d936e463deb81d5f27ac81814 Mon Sep 17 00:00:00 2001 From: jiaziyang Date: Thu, 22 Jul 2021 21:06:04 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9rtc=5Fbase.c=E4=B8=AD?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C=E5=8F=8A=E5=85=B3=E9=94=AE=E5=AD=97=E7=9A=84?= =?UTF-8?q?=E5=87=B8=E6=98=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jiaziyang --- support/platform/src/rtc_base.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/support/platform/src/rtc_base.c b/support/platform/src/rtc_base.c index 82d0039dd..25be00507 100644 --- a/support/platform/src/rtc_base.c +++ b/support/platform/src/rtc_base.c @@ -95,18 +95,17 @@ uint64_t RtcTimeToTimestamp(const struct RtcTime *time) HDF_LOGE("RtcTimeToTimestamp: time invalid"); return 0; } - - + seconds = ((uint64_t)time->hour * RTC_MAX_MINUTE + time->minute) * RTC_MAX_SECOND + time->second; days = time->day - RTC_UNIT_DIFF; month = time->month; year = time->year; - for(month--; month >= RTC_JANUARY; month--) { + for (month--; month >= RTC_JANUARY; month--) { days += RtcGetMonthDays(IS_LEAP_YEAR(time->year), month); } - for(year--; year >= RTC_BEGIN_YEAR; year--) { + for (year--; year >= RTC_BEGIN_YEAR; year--) { days += RTC_YEAR_DAYS(year); } -- Gitee