Fix up elapsed manipulation

This commit is contained in:
Laurence Withers 2007-07-29 11:57:13 +00:00
parent e59586b265
commit ec6c9a41f7
1 changed files with 12 additions and 4 deletions

View File

@ -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);
date->day += qr.quot;
date->sec += qr.rem - leapcorrect;
if(date->sec < 0) {
--date->day;
date->sec += iso8601_seconds_leap(date);
}
date->nsec += per->nsec;
if(date->nsec > BILLION) {
++date->sec;
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->sec -= qr.rem - leapcorrect;
date->nsec -= per->nsec;
if(date->nsec < 0) {
--date->sec;
date->nsec += BILLION;
@ -82,6 +89,7 @@ void iso8601_subtract_elapsed(struct iso8601_date* date, const struct iso8601_el
--date->day;
date->sec += iso8601_seconds_leap(date);
}
if(date->sec >= iso8601_seconds_leap(date)) {
date->sec -= iso8601_seconds_leap(date);
++date->day;