-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix bug in formatting timestamps with gmtime_r #293
Conversation
please format the commit message title better:
For example: You should also append JIRA ticket ID to the commit message trailer |
327904e
to
aabd2f6
Compare
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.
Is leapcount() still needed? It shoudn't be, as it's buggy, so it should be removed
aabd2f6
to
b2769a0
Compare
b2769a0
to
8f7461e
Compare
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.
LGTM
Some issues:
char *ctime_r(const time_t *timep, char *buf)
{
struct tm t, *tp;
tp = localtime_r(timep, &t);
return (tp == NULL) ? NULL : asctime_r(&t, buf);
}
int seconds, minutes, hours;
int days, month, year, isYearLeap;
days = *timep / (24 * 60 * 60);
seconds = *timep - (time_t)days * (24 * 60 * 60);
#if 0 /* insert it if `time_t` is signed */
if (seconds < 0) {
days--;
seconds += (24 * 60 * 60);
}
#endif
hours = seconds / (60 * 60);
seconds = seconds % (60 * 60);
minutes = seconds / 60;
seconds = seconds % 60;
res->tm_sec = seconds;
res->tm_min = minutes;
res->tm_hour = hours;
/* the rest of the code */ |
|
|
|
8f7461e
to
f391381
Compare
c0ffa7e
to
8eafb34
Compare
time: limit acceptable timestamp range in gmtime_r time: improve mktime and gmtime_r to work with negative timestamps JIRA: RTOS-609
8eafb34
to
c142ebf
Compare
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.
LGTM
Description
Timestamps that were far into the future (beyond about year 14000) were parsed incorrectly because the previous algorithm assumed too many leap years.
Related to phoenix-rtos/phoenix-rtos-project#801 - in one example time on RTC was set correctly to maximum timestamp minus the given number of seconds, but displayed incorrectly due to this bug.
Motivation and Context
Types of changes
How Has This Been Tested?
Checklist:
Special treatment