PaulStoffregen/Time

adjustTime increments a leap year when it shouldn't.

aord opened this issue · 1 comments

aord commented

adjustTime increments a leap year when it shouldn't. Leap year occur on 2020 and 2024.

Adding 12 hours to the date time 28/4/2022, hour=23.
Gives 29/4/2022 hour=11.
Should be 1/5/2022 hour=11.

Tested Using Arduino UNO (clone)
Also tested with same result on a WeMos D1R1 board.

//Code copied and adjusted from TimeGPS example
#include <TimeLib.h>

void setup()
{
Serial.begin(9600);

int Year = 2022;
byte Month = 4;
byte Day = 28;
byte Hour = 23;
byte Minute = 59;
byte Second = 58;

const int offset = 12;

setTime(Hour, Minute, Second, Day, Month, Year);
adjustTime(offset * SECS_PER_HOUR);

Serial.print(day());
Serial.print(" ");
Serial.print(month());
Serial.print(" ");
Serial.print(year());
Serial.println();
}

Result: 29 4 2022
2022 is not a leap year result should be 1 5 2022

4 is the month of April. There's always 30 days in April, every year