diff --git a/src/libiso8601/leap.c b/src/libiso8601/100_leap.c similarity index 78% rename from src/libiso8601/leap.c rename to src/libiso8601/100_leap.c index 4893473..cf2a900 100644 --- a/src/libiso8601/leap.c +++ b/src/libiso8601/100_leap.c @@ -1,4 +1,4 @@ -/* libiso8601/src/libiso8601/leap.c +/* libiso8601/src/libiso8601/100_leap.c * * (c)2006, Laurence Withers, . * Released under the GNU GPLv2. See file COPYING or @@ -46,27 +46,6 @@ int iso8601_seconds_leap(const struct iso8601_date* date) -int iso8601_valid_leap(const struct iso8601_date* date) -{ - int num_ly = 0, i = 0; - - if(date->nsec < 0 || date->nsec >= BILLION) return 0; - - switch(date->sec) { - case 0 ... 86399: - return 1; - - case 86400: /* 23:59:60 */ - num_ly = sizeof(leap_second_days) / sizeof(int); - for(i = 0; i < num_ly; ++i) if(leap_second_days[i] == date->day) return 1; - return 0; - } - - return 0; -} - - - static int _leap_elapsed_day(int sday, int eday) { int spos, epos; diff --git a/src/libiso8601/200_parser.c b/src/libiso8601/200_parser.c index 7a51f1c..26b3caa 100644 --- a/src/libiso8601/200_parser.c +++ b/src/libiso8601/200_parser.c @@ -648,17 +648,17 @@ done: } - // correct for timezone offset (note trickery to end up at 23:59:60 iff a leap second was - // requested) + /* correct for timezone offset (note trickery to end up at 23:59:60 iff a leap second was + * requested), and ensure that any leap second requested was a valid leap second. */ if(details) details->tz_sec = tz_sec; if(tz_sec && earliest) iso8601_add_seconds(earliest, - leap_sec_req - tz_sec); if(tz_sec && latest) iso8601_add_seconds(latest, - leap_sec_req - tz_sec); - - // check that, if a leap second was requested, it was a valid leap second if(leap_sec_req) { ERROR_IF(earliest && earliest->sec != 86400); ERROR_IF(latest && latest->sec != 86400); } + ERROR_IF(earliest && iso8601_invalid(earliest)); + ERROR_IF(latest && iso8601_invalid(latest)); return 0; #undef ERROR_IF @@ -667,6 +667,27 @@ done: +int iso8601_invalid(const struct iso8601_date* date) +{ + int num_ly = 0, i = 0; + + if(date->nsec < 0 || date->nsec >= BILLION) return 0; + + switch(date->sec) { + case 0 ... 86399: + return 1; + + case 86400: /* 23:59:60 */ + num_ly = sizeof(leap_second_days) / sizeof(int); + for(i = 0; i < num_ly; ++i) if(leap_second_days[i] == date->day) return 1; + return 0; + } + + return 0; +} + + + /* options for text editors kate: replace-trailing-space-save true; space-indent true; tab-width 4; vim: expandtab:ts=4:sw=4 diff --git a/src/libiso8601/200_parser.h b/src/libiso8601/200_parser.h index bd5c762..e070b63 100644 --- a/src/libiso8601/200_parser.h +++ b/src/libiso8601/200_parser.h @@ -45,8 +45,12 @@ int iso8601_parse(const char* str, struct iso8601_date* earliest, struct iso8601 \retval -1 if not valid. \retval 0 if valid. +Checks the details of \a date to ensure that they are sensible. This involves checking that \a sec +is in the range 0 to 86399 (or 86400 if there is a leap second), and that \a nsec is in the range 0 +to 999999999. + */ -int iso8601_valid(const struct iso8601_date* date); +int iso8601_invalid(const struct iso8601_date* date); diff --git a/src/libiso8601/400_functions.h b/src/libiso8601/400_functions.h index d1ca921..9e6b327 100644 --- a/src/libiso8601/400_functions.h +++ b/src/libiso8601/400_functions.h @@ -38,7 +38,6 @@ void iso8601_add_nanoseconds(struct iso8601_date* date, long nano); /* leap.c */ int iso8601_seconds_leap(const struct iso8601_date* date); -int iso8601_valid_leap(const struct iso8601_date* date); int iso8601_leap_elapsed(const struct iso8601_date* start, const struct iso8601_date* end); /* options for text editors