arduino-libraries / RTCZero

RTC Library for SAMD21 based boards
http://arduino.cc/en/Reference/RTC
GNU Lesser General Public License v2.1
77 stars 78 forks source link

getEpoch should return time_t type #55

Closed jpmeijers closed 3 years ago

jpmeijers commented 4 years ago

https://github.com/arduino-libraries/RTCZero/blob/d8503ff7ef54c4e9366654c1b498ba088a8a7b3c/src/RTCZero.cpp#L373

This function should return a time_t type, not a uint32_t. Depending on the platform the time_t field might be bigger or smaller than 32 bits.

On the Arduino Zero / ATSAMD21 platform the time_t field is 8 bytes long, in other words 64 bits.

Run this sketch to see for yourself:

#include <time.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  //while(!Serial);
}

void loop() {
  // put your main code here, to run repeatedly:
  struct tm today = {0};
  today.tm_year = 119;
  today.tm_mon = 11;
  today.tm_mday = 9;
  today.tm_hour = 9;
  today.tm_min = 31;
  today.tm_sec = 12;

  time_t nowTs = mktime(&today);
  Serial.println(sizeof(nowTs));

  delay(1000);
}