Skip to content

Commit ea2898b

Browse files
paulbearddotnamefpistm
authored andcommitted
Use time_t instead of uint32_t to avoid year 2038 problem.
1 parent 32b412b commit ea2898b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/STM32RTC.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ void STM32RTC::setAlarmDate(uint8_t day, uint8_t month, uint8_t year)
813813
* @param subSeconds: optional pointer to where to store subseconds of the epoch in ms
814814
* @retval epoch time in seconds
815815
*/
816-
uint32_t STM32RTC::getEpoch(uint32_t *subSeconds)
816+
time_t STM32RTC::getEpoch(uint32_t *subSeconds)
817817
{
818818
struct tm tm;
819819

@@ -844,7 +844,7 @@ uint32_t STM32RTC::getEpoch(uint32_t *subSeconds)
844844
* @brief get epoch time since 1st January 2000, 00:00:00
845845
* @retval epoch time in seconds
846846
*/
847-
uint32_t STM32RTC::getY2kEpoch(void)
847+
time_t STM32RTC::getY2kEpoch(void)
848848
{
849849
return (getEpoch() - EPOCH_TIME_OFF);
850850
}
@@ -855,7 +855,7 @@ uint32_t STM32RTC::getY2kEpoch(void)
855855
* @param Alarm_Match match enum
856856
* @param subSeconds subSeconds in ms
857857
*/
858-
void STM32RTC::setAlarmEpoch(uint32_t ts, Alarm_Match match, uint32_t subSeconds)
858+
void STM32RTC::setAlarmEpoch(time_t ts, Alarm_Match match, uint32_t subSeconds)
859859
{
860860
if (ts < EPOCH_TIME_OFF) {
861861
ts = EPOCH_TIME_OFF;
@@ -877,7 +877,7 @@ void STM32RTC::setAlarmEpoch(uint32_t ts, Alarm_Match match, uint32_t subSeconds
877877
* @param epoch time in seconds
878878
* @param subSeconds subSeconds in ms
879879
*/
880-
void STM32RTC::setEpoch(uint32_t ts, uint32_t subSeconds)
880+
void STM32RTC::setEpoch(time_t ts, uint32_t subSeconds)
881881
{
882882
if (ts < EPOCH_TIME_OFF) {
883883
ts = EPOCH_TIME_OFF;
@@ -908,7 +908,7 @@ void STM32RTC::setEpoch(uint32_t ts, uint32_t subSeconds)
908908
* @brief set RTC time from epoch time since 1st January 2000, 00:00:00
909909
* @param epoch time in seconds
910910
*/
911-
void STM32RTC::setY2kEpoch(uint32_t ts)
911+
void STM32RTC::setY2kEpoch(time_t ts)
912912
{
913913
setEpoch(ts + EPOCH_TIME_OFF);
914914
}

src/STM32RTC.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,11 @@ class STM32RTC {
189189

190190
/* Epoch Functions */
191191

192-
uint32_t getEpoch(uint32_t *subSeconds = nullptr);
193-
uint32_t getY2kEpoch(void);
194-
void setEpoch(uint32_t ts, uint32_t subSeconds = 0);
195-
void setY2kEpoch(uint32_t ts);
196-
void setAlarmEpoch(uint32_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0);
192+
time_t getEpoch(uint32_t *subSeconds = nullptr);
193+
time_t getY2kEpoch(void);
194+
void setEpoch(time_t ts, uint32_t subSeconds = 0);
195+
void setY2kEpoch(time_t ts);
196+
void setAlarmEpoch(time_t ts, Alarm_Match match = MATCH_DHHMMSS, uint32_t subSeconds = 0);
197197

198198
#if defined(STM32F1xx)
199199
void getPrediv(uint32_t *predivA, int16_t *dummy = nullptr);

0 commit comments

Comments
 (0)