diff --git a/src/libiso8601/400_manip.c b/src/libiso8601/400_manip.c index f766b18..c6ce9a8 100644 --- a/src/libiso8601/400_manip.c +++ b/src/libiso8601/400_manip.c @@ -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) { div_t qr; diff --git a/src/libiso8601/400_manip.h b/src/libiso8601/400_manip.h index c8d69dc..dd80360 100644 --- a/src/libiso8601/400_manip.h +++ b/src/libiso8601/400_manip.h @@ -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 < \a d2 +\retval 0 if \a d1 == \a d2 +\retval 1 if \a d1 > \a d2 + +*/ +int iso8601_cmp(const struct iso8601_date* d1, const struct iso8601_date* d2); + + + /*! \brief Add a period to a date. \param[in,out] date Date to modify.