From 301be3c83b0db5ea97ee15d6f205dcc1c2786bd2 Mon Sep 17 00:00:00 2001 From: Paul Beard Date: Sat, 17 Dec 2022 19:03:32 +1300 Subject: [PATCH] Use time_t instead of uint32_t to avoid year 2038 problem. --- src/STM32RTC.cpp | 10 +++++----- src/STM32RTC.h | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/STM32RTC.cpp b/src/STM32RTC.cpp index 8f1f859..6727ab8 100644 --- a/src/STM32RTC.cpp +++ b/src/STM32RTC.cpp @@ -813,7 +813,7 @@ void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year) * @param subSeconds: optional pointer to where to store subseconds of the epoch in ms * @retval epoch time in seconds */ -uint32_t STM32RTC::getEpoch(uint32_t *subSeconds) +time_t STM32RTC::getEpoch(uint32_t *subSeconds) { struct tm tm; @@ -844,7 +844,7 @@ uint32_t STM32RTC::getEpoch(uint32_t *subSeconds) * @brief get epoch time since 1st January 2000, 00:00:00 * @retval epoch time in seconds */ -uint32_t STM32RTC::getY2kEpoch(void) +time_t STM32RTC::getY2kEpoch(void) { return (getEpoch() - EPOCH_TIME_OFF); } @@ -855,7 +855,7 @@ uint32_t STM32RTC::getY2kEpoch(void) * @param Alarm_Match match enum * @param subSeconds subSeconds in ms */ -void STM32RTC::setAlarmEpoch(uint32_t ts, Alarm_Match match, uint32_t subSeconds) +void STM32RTC::setAlarmEpoch(time_t ts, Alarm_Match match, uint32_t subSeconds) { if (ts < EPOCH_TIME_OFF) { ts = EPOCH_TIME_OFF; @@ -877,7 +877,7 @@ void STM32RTC::setAlarmEpoch(uint32_t ts, Alarm_Match match, uint32_t subSeconds * @param epoch time in seconds * @param subSeconds subSeconds in ms */ -void STM32RTC::setEpoch(uint32_t ts, uint32_t subSeconds) +void STM32RTC::setEpoch(time_t ts, uint32_t subSeconds) { if (ts < EPOCH_TIME_OFF) { ts = EPOCH_TIME_OFF; @@ -908,7 +908,7 @@ void STM32RTC::setEpoch(uint32_t ts, uint32_t subSeconds) * @brief set RTC time from epoch time since 1st January 2000, 00:00:00 * @param epoch time in seconds */ -void STM32RTC::setY2kEpoch(uint32_t ts) +void STM32RTC::setY2kEpoch(time_t ts) { setEpoch(ts + EPOCH_TIME_OFF); } diff --git a/src/STM32RTC.h b/src/STM32RTC.h index f5785a0..1adaa85 100644 --- a/src/STM32RTC.h +++ b/src/STM32RTC.h @@ -189,11 +189,11 @@ class STM32RTC { /* Epoch Functions */ - uint32_t getEpoch(uint32_t *subSeconds = nullptr); - uint32_t getY2kEpoch(void); - void setEpoch(uint32_t ts, uint32_t subSeconds = 0); - void setY2kEpoch(uint32_t ts); - void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0); + time_t getEpoch(uint32_t *subSeconds = nullptr); + time_t getY2kEpoch(void); + void setEpoch(time_t ts, uint32_t subSeconds = 0); + void setY2kEpoch(time_t ts); + void setAlarmEpoch(time_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0); #if defined(STM32F1xx) void getPrediv(uint32_t *predivA, int16_t *dummy = nullptr);