Add iso8601_cmp(), comparison function for qsort()

This commit is contained in:
Laurence Withers 2009-04-06 14:58:05 +00:00
parent d09e55e8ae
commit 1d9447dcd2
2 changed files with 26 additions and 0 deletions

View File

@ -38,6 +38,19 @@ int iso8601_eq(const struct iso8601_date* d1, const struct iso8601_date* d2)
int iso8601_cmp(const struct iso8601_date* d1, const struct iso8601_date* d2)
{
if(d1->day < d2->day) return -1;
if(d1->day > d2->day) return 1;
if(d1->sec < d2->sec) return -1;
if(d1->sec > d2->sec) return 1;
if(d1->nsec < d2->nsec) return -1;
if(d1->nsec > d2->nsec) return 1;
return 0;
}
void iso8601_add_elapsed(struct iso8601_date* date, const struct iso8601_elapsed* per) void iso8601_add_elapsed(struct iso8601_date* date, const struct iso8601_elapsed* per)
{ {
div_t qr; div_t qr;

View File

@ -53,6 +53,19 @@ int iso8601_eq(const struct iso8601_date* d1, const struct iso8601_date* d2);
/*! \brief Comparison (for qsort et al.).
\param d1 First date to compare.
\param d2 Second date to compare.
\retval -1 if \a d1 &lt; \a d2
\retval 0 if \a d1 == \a d2
\retval 1 if \a d1 &gt; \a d2
*/
int iso8601_cmp(const struct iso8601_date* d1, const struct iso8601_date* d2);
/*! \brief Add a period to a date. /*! \brief Add a period to a date.
\param[in,out] date Date to modify. \param[in,out] date Date to modify.