Skip to content
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

fix leap year calculation bug in makeTime() #742

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

A-Dunstan
Copy link
Contributor

@A-Dunstan A-Dunstan commented May 10, 2024

makeTime() has a bug when checking if the specified year is a leap year, caused by failing to subtract 70 from the DateTimeFields.year.

This function will demonstrate:

void printDateTime() {
  uint32_t now;
  DateTimeFields dt;
  // uncomment to test current time:
//  now = rtc_get();
  // otherwise use this time to demonstrate the bug in makeTime()
  now = 1715350435; // 2024-05-10 14:13:55
  breakTime(now, dt);
  now = makeTime(dt);

  Serial.printf("%04u-%02u-%02u %02u:%02u:%02u", dt.year+1900, dt.mon+1, dt.mday, dt.hour, dt.min, dt.sec);
  Serial.printf(" -> %u -> ", now);
  breakTime(now, dt);
  Serial.printf("%04u-%02u-%02u %02u:%02u:%02u", dt.year+1900, dt.mon+1, dt.mday, dt.hour, dt.min, dt.sec);
  Serial.println();
}

Output from current code:

2024-05-10 14:13:55 -> 1715264035 -> 2024-05-09 14:13:55

Expected output (after applying PR):

2024-05-10 14:13:55 -> 1715350435 -> 2024-05-10 14:13:55

@skunktrading
Copy link

See #637 and #638 for the same fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants