Skip to content

Use time_t instead of uint32_t to avoid year 2038 problem. #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/STM32RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions src/STM32RTC.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down