Skip to content

NTPClient now returns date, year, month and day. - #161

Open
barsrb wants to merge 2 commits into
arduino-libraries:masterfrom
barsrb:master
Open

NTPClient now returns date, year, month and day.#161
barsrb wants to merge 2 commits into
arduino-libraries:masterfrom
barsrb:master

Conversation

@barsrb

@barsrb barsrb commented Dec 24, 2021

Copy link
Copy Markdown

To get day of week now use getDayOfWeek()

To get day of week now use getDayOfWeek()
@CLAassistant

CLAassistant commented Dec 24, 2021

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ per1234
❌ barsrb
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown

Memory usage change @ 1fab9d7

Board flash % RAM for global variables %
esp8266:esp8266:huzzah 0 - 0 0.0 - 0.0 0 - 0 0.0 - 0.0
Click for full report table
Board examples/Advanced
flash
% examples/Advanced
RAM for global variables
% examples/Basic
flash
% examples/Basic
RAM for global variables
% examples/IsTimeSet
flash
% examples/IsTimeSet
RAM for global variables
%
esp8266:esp8266:huzzah 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0 0 0.0
Click for full report CSV
Board,examples/Advanced<br>flash,%,examples/Advanced<br>RAM for global variables,%,examples/Basic<br>flash,%,examples/Basic<br>RAM for global variables,%,examples/IsTimeSet<br>flash,%,examples/IsTimeSet<br>RAM for global variables,%
esp8266:esp8266:huzzah,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0,0,0.0

The identifier `leapYears` was being detected by the spell checker tool as a misspelling of "leap years".

The false positive is resolved by adding `leapyears` to the ignore list in the `.codespellrc` configuration file.
Comment thread NTPClient.cpp
int fullYears = days / 365;
int overDays = days % 365;

int leapYears = (fullYears - 2) / 4;

@poveden poveden Mar 12, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getYear() fails for all days that match December 31st, except for the year 1970 and those where the next year is a leap one (brute-tested using Excel):

Code 1970/12/31 1971/12/31 1972/12/31
days 364 729 (365+364) 1095 (365+365+365)
fullYears = days / 365 0 (364 / 365) 1 (729 / 365) 3 (1095 / 365)
overDays = days % 365 364 (364 % 365) 364 (729 % 365) 0 (1095 % 365)
leapYears = (fullYears - 2) / 4 0 ((0 − 2) / 4) 0 ((1 − 2) / 4) 0 ((3 − 2) / 4)
if (leapYears > overDays) fullYears-- 0 (No change) 1 (No change) 3 (No change)
return 1970 + fullYears 1970 (1970 + 0) 1971 (1970 + 1) 1973 (1970 + 3)

Fortunately, it can be easily fixed:

Suggested change
int leapYears = (fullYears - 2) / 4;
int leapYears = (fullYears + 1) / 4;

@per1234

per1234 commented Jan 12, 2023

Copy link
Copy Markdown
Contributor

@per1234 per1234 added type: enhancement Proposed improvement topic: code Related to content of the project itself labels Jan 12, 2023
@thaianhtaivn

Copy link
Copy Markdown

Hello @per1234 ,
Can we merge it to master? Cause we usually use these functions for getting dates info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: code Related to content of the project itself type: enhancement Proposed improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the functionallity to get the date getFormattedTime does not give date+time string

5 participants