PaulStoffregen / Time

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

Day value gets changed by 10 days when using makeTime #153

Open DaleSchultz opened 4 years ago

DaleSchultz commented 4 years ago

111 # Description

The day value gets corrupted by makeTime

Steps To Reproduce Problem

convert a time element structure to a time and inspect the day value. It changed.

Hardware & Software

LoLin ESP8266 Arduino IDE version 1.8.13 Version info & package name (from Tools > Boards > Board Manager) 1.6.0

Arduino Sketch

#include <TimeLib.h>
void setup() {
  Serial.begin(115200);
  delay(1000);
   tmElements_t start;

  start.Year = 2020-1970;
  Serial.print("year ");    Serial.println(start.Year);
  start.Month = 11;
  start.Day = 2;
  Serial.print("day ");    Serial.println(start.Day);  // prints 2 - correct

  time_t startdate = makeTime(start);

  Serial.print("converted day ");    Serial.println(day(startdate));         // prints 12 - incorrect
  Serial.print("month ");   Serial.println(month(startdate));  // prints 11 as expected
  Serial.print("year ");    Serial.println(year(startdate));  // prints 2020 as expected

}
void loop() {
  }

Errors or Incorrect Output

09:27:13.596 -> year 50 09:27:13.596 -> day 2 09:27:13.596 -> converted day 12 09:27:13.596 -> month 11 09:27:13.596 -> year 2020