Fix bugs, finish parser

This commit is contained in:
Laurence Withers 2006-10-16 00:33:01 +01:00
parent 09fd37b4f5
commit 6919b25e84
3 changed files with 8 additions and 3 deletions

View File

@ -21,6 +21,10 @@ void iso8601_add_seconds(struct iso8601_date* date, long seconds)
qr = ldiv(seconds + date->sec, 86400); qr = ldiv(seconds + date->sec, 86400);
date->day += qr.quot; date->day += qr.quot;
date->sec = qr.rem; date->sec = qr.rem;
if(date->sec < 0) {
--date->day;
date->sec += 86400;
}
} }

View File

@ -97,6 +97,7 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601
if(details) details->extended = 1; if(details) details->extended = 1;
break; break;
case 0:
case 'T': case 'T':
switch(dig) { switch(dig) {
case 4: case 4:
@ -625,8 +626,8 @@ done:
} }
if(details) details->tz_sec = tz_sec; if(details) details->tz_sec = tz_sec;
if(earliest) iso8601_add_seconds(earliest, -tz_sec); if(tz_sec && earliest) iso8601_add_seconds(earliest, -tz_sec);
if(latest) iso8601_add_seconds(latest, -tz_sec); if(tz_sec && latest) iso8601_add_seconds(latest, -tz_sec);
return 0; return 0;
} }

View File

@ -28,7 +28,7 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date,
// adjust output for timezone // adjust output for timezone
dttz = *date; dttz = *date;
iso8601_add_seconds(&dttz, details->tz_sec); if(details->tz_sec) iso8601_add_seconds(&dttz, details->tz_sec);
// determine whether or not to force extended output // determine whether or not to force extended output
iso8601_to_cal(&y, &m, &d, &dttz); iso8601_to_cal(&y, &m, &d, &dttz);