Further WIP on tidy up

This commit is contained in:
Laurence Withers 2007-07-23 15:00:08 +00:00
parent f82859fa78
commit 603b067310
3 changed files with 74 additions and 22 deletions

View File

@ -669,21 +669,11 @@ 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;
return date->nsec < 0
|| date->nsec >= BILLION
|| date->sec < 0
|| date->sec >= iso8601_seconds_leap(date)
;
}

View File

@ -22,6 +22,9 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
int y, m, d, ret = 0, extended;
struct iso8601_date dttz;
double frac;
char* str_orig;
str_orig = str;
// use default details if none provided
if(!details) details = &_default_details;
@ -38,12 +41,12 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
case iso8601_prec_year:
if(y < 0) snprintf(str, amt, "%05d", y);
else snprintf(str, amt, "%04d", y);
return str;
return str_orig;
case iso8601_prec_month:
if(y < 0) snprintf(str, amt, "%05d-%02d", y, m);
else snprintf(str, amt, extended ? "%04d-%02d" : "%04d%02d", y, m);
return str;
return str_orig;
case iso8601_prec_day:
if(y < 0) ret = snprintf(str, amt, "%05d-%02d-%02d", y, m, d);
@ -61,7 +64,7 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
extended = y < 0 || y > 9999 || details->extended; // ISO year is different
if(y < 0) snprintf(str, amt, "%05d-W%02d", y, m);
else snprintf(str, amt, extended ? "%04d-W%02d" : "%04dW%02d", y, m);
return str;
return str_orig;
case iso8601_prec_wday:
iso8601_to_week(&y, &m, &d, &dttz);
@ -71,7 +74,7 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
break;
}
if(ret < 1 || ret >= amt) return str;
if(ret < 1 || ret >= amt) return str_orig;
str += ret;
amt -= ret;
@ -92,7 +95,7 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
switch(details->time_prec) {
case iso8601_prec_none:
return str;
return str_orig;
case iso8601_prec_hour:
ret = snprintf(str, amt, "T%02d", y);
@ -122,14 +125,14 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
break;
}
if(ret < 1 || ret >= amt) return str;
if(ret < 1 || ret >= amt) return str_orig;
str += ret;
amt -= ret;
if(details->tz_sec) {
if(!--amt) {
*str = 0;
return str;
return str_orig;
}
if(details->tz_sec < 0) {
*str++ = '-';
@ -152,6 +155,8 @@ char* iso8601_print(char* str, int amt, const struct iso8601_date* date,
*str++ = 'Z';
if(amt > 1) *str = 0;
}
return str_orig;
}

57
src/libiso8601/400_leap.h Normal file
View File

@ -0,0 +1,57 @@
/* libiso8601/src/libiso8601/400_leap.h
*
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
* Released under the GNU GPLv2. See file COPYING or
* http://www.gnu.org/copyleft/gpl.html for details.
*/
/*! \defgroup leap Leap second support.
A set of functions for explicitly dealing with leap seconds.
*/
/*!@{*/
/*! \brief Return number of seconds in day, taking leap seconds into account.
\param date The date to return the number of seconds for.
\retval 86399 day with a negative leap second.
\retval 86400 day with no leap second.
\retval 86401 day with one leap second.
Returns the duration of a day \a date, in seconds. This function takes leap seconds into account and
may be used to determine if a day contains a leap second or not.
\note There have not yet been any days requiring a negative leap second, so at present 86399 will
never be returned.
*/
int iso8601_seconds_leap(const struct iso8601_date* date);
/*! \brief Return number of leap seconds elapsed between two days.
\param start The start date.
\param end The end date.
\returns Number of leap seconds elapsed.
Computes the number of leap seconds that have elapsed between two days. Note that this is the sum of
such leap seconds, so it will be 0 if (for example) there is one positive leap second and one
negative leap second. The ordering of the dates is important; if \a start is after \a end, then the
value returned will be negative (for positive leap seconds).
*/
int iso8601_leap_elapsed(const struct iso8601_date* start, const struct iso8601_date* end);
/*!@}*/
/* options for text editors
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
vim: expandtab:ts=4:sw=4
*/