From 1fc5324e7376e7528ffc57f975b19126d6f2ceee Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Fri, 15 Dec 2006 22:28:22 +0000 Subject: [PATCH] Clean up and remove references to 86401 notation. --- src/libiso8601/calc.c | 22 +++++----------------- src/libiso8601/leap.c | 5 +---- src/libiso8601/manip.c | 9 ++------- src/libiso8601/print.c | 6 ------ src/libiso8601/types.h | 2 +- 5 files changed, 9 insertions(+), 35 deletions(-) diff --git a/src/libiso8601/calc.c b/src/libiso8601/calc.c index 8e22a2f..577563d 100644 --- a/src/libiso8601/calc.c +++ b/src/libiso8601/calc.c @@ -11,9 +11,8 @@ * * This file contains calculation routines used internally in the library. Our date format is the * number of days elapsed since 0000-001 (so that date would be 0, -0001-365 would be -1, etc.). - * Time is represented as the number of seconds elapsed since midnight at the start of the day - * (so 0 is 00:00:00 and 86400 is 24:00:00, which we take to be infinitesimally before the start - * of the next day). + * Time is represented as the number of seconds elapsed since midnight at the start of the day. It + * is a value between 0 and 86399 (or 86400 for leap seconds). */ #define DAYS_IN_400_YEARS (146097) @@ -373,19 +372,12 @@ void iso8601_to_clocktime(int* hour, int* min, int* sec, const struct iso8601_da { div_t qr; - // two special cases: leap second and midnight - switch(date->sec) { - case 86400: + // special case: leap second + if(date->sec == 86400) { *hour = 23; *min = 59; *sec = 60; return; - - case 86401: - *hour = 24; - *min = 0; - *sec = 0; - return; } // normal case @@ -400,15 +392,11 @@ void iso8601_to_clocktime(int* hour, int* min, int* sec, const struct iso8601_da int iso8601_from_clocktime(struct iso8601_date* date, int hour, int min, int sec) { - // two special cases: leap second and midnight + // special case: leap second if(hour == 23 && min == 59 && sec == 60) { date->sec = 86400; return 0; } - if(hour == 24 && !min && !sec) { - date->sec = 86401; - return 0; - } // domain check if(hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 59) { diff --git a/src/libiso8601/leap.c b/src/libiso8601/leap.c index 18c08df..daa47da 100644 --- a/src/libiso8601/leap.c +++ b/src/libiso8601/leap.c @@ -30,7 +30,7 @@ static int leap_second_days[] = { 729023, // 19951231 729570, // 19970630 730119, // 19981231 - 732676 // 19991231 + 732676 // 20051231 }; @@ -60,9 +60,6 @@ int iso8601_valid_leap(const struct iso8601_date* date) 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; - - case 86401: /* 24:00:00 */ - return !date->nsec; } return 0; diff --git a/src/libiso8601/manip.c b/src/libiso8601/manip.c index 479e5da..cfcb524 100644 --- a/src/libiso8601/manip.c +++ b/src/libiso8601/manip.c @@ -11,13 +11,8 @@ void iso8601_add_seconds(struct iso8601_date* date, long seconds) { ldiv_t qr; - switch(date->sec) { - case 86400: - case 86401: - --date->sec; - break; - } - + // TODO: leap second support + qr = ldiv(seconds + date->sec, 86400); date->day += qr.quot; date->sec = qr.rem; diff --git a/src/libiso8601/print.c b/src/libiso8601/print.c index 8b5899f..02f1c9c 100644 --- a/src/libiso8601/print.c +++ b/src/libiso8601/print.c @@ -82,12 +82,6 @@ void iso8601_print(char* str, int amt, const struct iso8601_date* date, d = 60; break; - case 86401: - y = 24; - m = 0; - d = 0; - break; - default: y = dttz.sec / 3600; dttz.sec -= y * 3600; diff --git a/src/libiso8601/types.h b/src/libiso8601/types.h index 3b80717..3bfe496 100644 --- a/src/libiso8601/types.h +++ b/src/libiso8601/types.h @@ -10,7 +10,7 @@ struct iso8601_date { int32_t nsec; int32_t day; - int32_t sec; // special values: 86400 == leap second 23:59:60, 86401 == midnight 24:00:00 + int32_t sec; // special value: 86400 == leap second 23:59:60 }; enum iso8601_date_prec {