PaulStoffregen / Time

Time library for Arduino
http://playground.arduino.cc/code/time
1.24k stars 663 forks source link

adjustTime increments a leap year when it shouldn't. #169

Open aord opened 2 years ago

aord commented 2 years ago

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

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

pefferie commented 2 months ago

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