Fix up elapsed manipulation
This commit is contained in:
parent
e59586b265
commit
ec6c9a41f7
|
@ -48,16 +48,22 @@ void iso8601_add_elapsed(struct iso8601_date* date, const struct iso8601_elapsed
|
||||||
leapcorrect = _leap_elapsed_day(date->day, date->day + qr.quot);
|
leapcorrect = _leap_elapsed_day(date->day, date->day + qr.quot);
|
||||||
date->day += qr.quot;
|
date->day += qr.quot;
|
||||||
date->sec += qr.rem - leapcorrect;
|
date->sec += qr.rem - leapcorrect;
|
||||||
if(date->sec < 0) {
|
|
||||||
--date->day;
|
|
||||||
date->sec += iso8601_seconds_leap(date);
|
|
||||||
}
|
|
||||||
|
|
||||||
date->nsec += per->nsec;
|
date->nsec += per->nsec;
|
||||||
if(date->nsec > BILLION) {
|
if(date->nsec > BILLION) {
|
||||||
++date->sec;
|
++date->sec;
|
||||||
date->nsec -= BILLION;
|
date->nsec -= BILLION;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(date->sec < 0) {
|
||||||
|
--date->day;
|
||||||
|
date->sec += iso8601_seconds_leap(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(date->sec >= iso8601_seconds_leap(date)) {
|
||||||
|
date->sec -= iso8601_seconds_leap(date);
|
||||||
|
++date->day;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,6 +79,7 @@ void iso8601_subtract_elapsed(struct iso8601_date* date, const struct iso8601_el
|
||||||
date->day -= qr.quot;
|
date->day -= qr.quot;
|
||||||
date->sec -= qr.rem - leapcorrect;
|
date->sec -= qr.rem - leapcorrect;
|
||||||
date->nsec -= per->nsec;
|
date->nsec -= per->nsec;
|
||||||
|
|
||||||
if(date->nsec < 0) {
|
if(date->nsec < 0) {
|
||||||
--date->sec;
|
--date->sec;
|
||||||
date->nsec += BILLION;
|
date->nsec += BILLION;
|
||||||
|
@ -82,6 +89,7 @@ void iso8601_subtract_elapsed(struct iso8601_date* date, const struct iso8601_el
|
||||||
--date->day;
|
--date->day;
|
||||||
date->sec += iso8601_seconds_leap(date);
|
date->sec += iso8601_seconds_leap(date);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(date->sec >= iso8601_seconds_leap(date)) {
|
if(date->sec >= iso8601_seconds_leap(date)) {
|
||||||
date->sec -= iso8601_seconds_leap(date);
|
date->sec -= iso8601_seconds_leap(date);
|
||||||
++date->day;
|
++date->day;
|
||||||
|
|
Loading…
Reference in New Issue