Skip to content

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

@aord

Description

@aord

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions