-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NTPClient now returns date, year, month and day. #161
base: master
Are you sure you want to change the base?
Conversation
To get day of week now use getDayOfWeek()
Memory usage change @ 1fab9d7
Click for full report table
Click for full report CSV
|
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.
int fullYears = days / 365; | ||
int overDays = days % 365; | ||
|
||
int leapYears = (fullYears - 2) / 4; |
There was a problem hiding this comment.
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) |
Fortunately, it can be easily fixed:
int leapYears = (fullYears - 2) / 4; | |
int leapYears = (fullYears + 1) / 4; |
Hello @per1234 , |
To get day of week now use getDayOfWeek()