From a8f9be7907fb1ab27a5962ec9eb0ff6570b8d5d8 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Thu, 15 Mar 2018 16:05:07 -0700 Subject: [PATCH 1/5] Add issue template --- docs/issue_template.md | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 docs/issue_template.md diff --git a/docs/issue_template.md b/docs/issue_template.md new file mode 100644 index 0000000..0610992 --- /dev/null +++ b/docs/issue_template.md @@ -0,0 +1,64 @@ +Please use this form only to report code defects or bugs. + +For any question, even questions directly pertaining to this code, post your question on the forums related to the board you are using. + +Arduino: forum.arduino.cc +Teensy: forum.pjrc.com +ESP8266: www.esp8266.com +ESP32: www.esp32.com +Adafruit Feather/Metro/Trinket: forums.adafruit.com +Particle Photon: community.particle.io + +If you are experiencing trouble but not certain of the cause, or need help using this code, ask on the appropriate forum. This is not the place to ask for support or help, even directly related to this code. Only use this form you are certain you have discovered a defect in this code! + +Please verify the problem occurs when using the very latest version, using the newest version of Arduino and any other related software. + + +----------------------------- Remove above ----------------------------- + + + +### Description + +Describe your problem. + + + +### Steps To Reproduce Problem + +Please give detailed instructions needed for anyone to attempt to reproduce the problem. + + + +### Hardware & Software + +Board +Shields / modules used +Arduino IDE version +Teensyduino version (if using Teensy) +Version info & package name (from Tools > Boards > Board Manager) +Operating system & version +Any other software or hardware? + + +### Arduino Sketch + +```cpp +// Change the code below by your sketch (please try to give the smallest code which demonstrates the problem) +#include + +// libraries: give links/details so anyone can compile your code for the same result + +void setup() { +} + +void loop() { +} +``` + + +### Errors or Incorrect Output + +If you see any errors or incorrect output, please show it here. Please use copy & paste to give an exact copy of the message. Details matter, so please show (not merely describe) the actual message or error exactly as it appears. + + From f72db9a62a338d438861540609fb3c4de0d3bbb3 Mon Sep 17 00:00:00 2001 From: James Myatt Date: Wed, 5 Dec 2018 15:23:59 +0000 Subject: [PATCH 2/5] Optimise breakTime, use time_t appropriately and avoid signed/unsigned comparisons --- Time.cpp | 80 +++++++++++++++++++++++--------------------------------- 1 file changed, 33 insertions(+), 47 deletions(-) diff --git a/Time.cpp b/Time.cpp index 3aaf233..fe6944c 100644 --- a/Time.cpp +++ b/Time.cpp @@ -116,7 +116,7 @@ int day(time_t t) { // the day for the given time (0-6) } int weekday() { // Sunday is day 1 - return weekday(now()); + return weekday(now()); } int weekday(time_t t) { @@ -148,26 +148,24 @@ int year(time_t t) { // the year for the given time // leap year calulator expects year argument as years offset from 1970 #define LEAP_YEAR(Y) ( ((1970+(Y))>0) && !((1970+(Y))%4) && ( ((1970+(Y))%100) || !((1970+(Y))%400) ) ) +#define daysInYear(year) ((time_t) (LEAP_YEAR(year) ? 366 : 365)) -static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0 - -void breakTime(time_t timeInput, tmElements_t &tm){ +static const uint8_t monthDays[]={31,28,31,30,31,30,31,31,30,31,30,31}; // API starts months from 1, this array starts from 0 + +void breakTime(time_t time, tmElements_t &tm){ // break the given time_t into time components // this is a more compact version of the C library localtime function // note that year is offset from 1970 !!! - uint8_t year; - uint8_t month, monthLength; - uint32_t time; - unsigned long days; + uint8_t period; + time_t length; - time = (uint32_t)timeInput; tm.Second = time % 60; time /= 60; // now it is minutes tm.Minute = time % 60; time /= 60; // now it is hours tm.Hour = time % 24; - time /= 24; // now it is days + time /= 24; // now it is days since 1 Jan 1970 // if the number of days since epoch matches cacheTime, then can take date // elements from cacheElements and avoid expensive calculation. @@ -183,38 +181,26 @@ void breakTime(time_t timeInput, tmElements_t &tm){ tm.Wday = DAYS_TO_WDAY(time); - year = 0; - days = 0; - while((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) { - year++; + period = 0; + while (time >= (length = daysInYear(period))) + { + time -= length; + period++; } - tm.Year = year; // year is offset from 1970 - - days -= LEAP_YEAR(year) ? 366 : 365; - time -= days; // now it is days in this year, starting at 0 - - days=0; - month=0; - monthLength=0; - for (month=0; month<12; month++) { - if (month==1) { // february - if (LEAP_YEAR(year)) { - monthLength=29; - } else { - monthLength=28; - } - } else { - monthLength = monthDays[month]; - } - - if (time >= monthLength) { - time -= monthLength; - } else { - break; - } + tm.Year = period; // year is offset from 1970 + // time is now days since 1 Jan of the year + + bool leap_year = LEAP_YEAR(period); + period = 0; + while (period < 12 && time >= (length = monthDays[period] + (leap_year && period==1))) + { + time -= length; + period++; } - tm.Month = month + 1; // jan is month 1 - tm.Day = time + 1; // day of month + tm.Month = period + 1; // jan is month 1 + // time is now days since the 1st day of the month + + tm.Day = time + 1; // day of month } time_t makeTime(const tmElements_t &tm){ @@ -226,7 +212,7 @@ time_t makeTime(const tmElements_t &tm){ uint32_t seconds; // seconds from 1970 till 1 jan 00:00:00 of the given year - seconds= tm.Year*(SECS_PER_DAY * 365); + seconds = SECS_PER_DAY * (365 * tm.Year); for (i = 0; i < tm.Year; i++) { if (LEAP_YEAR(i)) { seconds += SECS_PER_DAY; // add extra days for leap years @@ -250,9 +236,9 @@ time_t makeTime(const tmElements_t &tm){ /*=====================================================*/ /* Low level system time functions */ -static uint32_t sysTime = 0; +static time_t sysTime = 0; static uint32_t prevMillis = 0; -static uint32_t nextSyncTime = 0; +static time_t nextSyncTime = 0; static timeStatus_t Status = timeNotSet; getExternalTime getTimePtr; // pointer to external sync function @@ -284,7 +270,7 @@ time_t now() { } } } - return (time_t)sysTime; + return sysTime; } void setTime(time_t t) { @@ -293,8 +279,8 @@ void setTime(time_t t) { sysUnsyncedTime = t; // store the time of the first call to set a valid Time #endif - sysTime = (uint32_t)t; - nextSyncTime = (uint32_t)t + syncInterval; + sysTime = t; + nextSyncTime = t + (time_t) syncInterval; Status = timeSet; prevMillis = millis(); // restart counting from now (thanks to Korman for this fix) } @@ -327,7 +313,7 @@ timeStatus_t timeStatus() { return Status; } -void setSyncProvider( getExternalTime getTimeFunction){ +void setSyncProvider(getExternalTime getTimeFunction){ getTimePtr = getTimeFunction; nextSyncTime = sysTime; now(); // this will sync the clock From 8ac0830c1e6f3cd627582f0085aa171161f6bbc2 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 27 Jan 2019 17:07:44 -0800 Subject: [PATCH 3/5] Don't define strcpy_P if already defined --- DateStrings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/DateStrings.cpp b/DateStrings.cpp index 3eccff3..b82f6bc 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -17,8 +17,10 @@ #define PGM_P const char * #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) #define pgm_read_word(addr) (*(const unsigned char **)(addr)) +#ifndef strcpy_P #define strcpy_P(dest, src) strcpy((dest), (src)) #endif +#endif #include // for strcpy_P or strcpy #include "TimeLib.h" From 50a56f266b6565adb8ecc38a4c20ee634cacfe19 Mon Sep 17 00:00:00 2001 From: "DESKTOP-MK92NDD\\huyat" Date: Mon, 28 Jan 2019 10:47:34 +0700 Subject: [PATCH 4/5] Fix error grammar --- Readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index 795d26e..ee44912 100644 --- a/Readme.md +++ b/Readme.md @@ -90,10 +90,10 @@ illustrating how the library can be used with various time sources: if it is running and connected to the Arduino serial port. - `TimeSerialDateStrings.pde` adds day and month name strings to the sketch above - Short (3 character) and long strings are available to print the days of + Short (3 characters) and long strings are available to print the days of the week and names of the months. -- `TimeRTC` uses a DS1307 real time clock to provide time synchronization. +- `TimeRTC` uses a DS1307 real-time clock to provide time synchronization. A basic RTC library named DS1307RTC is included in the download. To run this sketch the DS1307RTC library must be installed. From 8866e7f48a05ca8b6b1f2d15d835d3321969131f Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Fri, 1 Mar 2019 23:46:41 +0100 Subject: [PATCH 5/5] Update microTime.cpp --- microTime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microTime.cpp b/microTime.cpp index 32f08b7..00e806e 100644 --- a/microTime.cpp +++ b/microTime.cpp @@ -253,7 +253,7 @@ time_t makeTime(const tmElements_t &tm){ /* Low level system time functions */ static time_t sysTime = 0; -static uint32_t prevMillis = 0; +static uint32_t prevMicros = 0; static time_t nextSyncTime = 0; static timeStatus_t Status = timeNotSet;