Use dynamic table for leap second days

This commit is contained in:
Laurence Withers 2009-01-03 19:08:21 +00:00
parent 849744bb07
commit 2c016208f2
1 changed files with 10 additions and 7 deletions

View File

@ -7,7 +7,7 @@
static int leap_second_days[] = {
static int leap_second_days_table[] = {
720439, /* 1972-06-30 */
720623, /* 1972-12-31 */
720988, /* 1973-12-31 */
@ -36,12 +36,15 @@ static int leap_second_days[] = {
static int* leap_second_days = leap_second_days_table;
static int leap_second_days_num = sizeof(leap_second_days_table) / sizeof(int);
int iso8601_seconds_leap(const struct iso8601_date* date)
{
int num_ly = 0, i = 0;
num_ly = sizeof(leap_second_days) / sizeof(int);
for(i = 0; i < num_ly; ++i) if(leap_second_days[i] == date->day) return 86401;
int i;
for(i = 0; i < leap_second_days_num; ++i) if(leap_second_days[i] == date->day) return 86401;
return 86400;
}
@ -51,10 +54,10 @@ static int _leap_elapsed_day(int sday, int eday)
{
int spos, epos;
for(spos = 0; (unsigned)spos < sizeof(leap_second_days) / sizeof(int); ++spos) {
for(spos = 0; spos < leap_second_days_num; ++spos) {
if(sday <= leap_second_days[spos]) break;
}
for(epos = 0; (unsigned)epos < sizeof(leap_second_days) / sizeof(int); ++epos) {
for(epos = 0; epos < leap_second_days_num; ++epos) {
if(eday <= leap_second_days[epos]) break;
}