Clean up and remove references to 86401 notation.

This commit is contained in:
Laurence Withers 2006-12-15 22:28:22 +00:00
parent 298775a047
commit 1fc5324e73
5 changed files with 9 additions and 35 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -11,12 +11,7 @@ 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;

View File

@ -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;

View File

@ -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 {