aboutsummaryrefslogtreecommitdiff
path: root/contrib/ntp/libntp/ymd2yd.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ntp/libntp/ymd2yd.c')
-rw-r--r--contrib/ntp/libntp/ymd2yd.c39
1 files changed, 14 insertions, 25 deletions
diff --git a/contrib/ntp/libntp/ymd2yd.c b/contrib/ntp/libntp/ymd2yd.c
index 796ce40948bd..c6b3a0cad7dc 100644
--- a/contrib/ntp/libntp/ymd2yd.c
+++ b/contrib/ntp/libntp/ymd2yd.c
@@ -1,37 +1,26 @@
/*
* ymd2yd - compute the date in the year from y/m/d
+ *
+ * A thin wrapper around a more general calendar function.
*/
-#include "ntp_fp.h"
-#include "ntp_unixtime.h"
+#include <config.h>
#include "ntp_stdlib.h"
-
-/*
- * Tables to compute the day of year from yyyymmdd timecode.
- * Viva la leap.
- */
-static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
-static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
+#include "ntp_calendar.h"
int
ymd2yd(
int y,
int m,
- int d
- )
+ int d)
{
- int i, *t;
-
- if (m < 1 || m > 12 || d < 1)
- return (-1);
-
- if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0))
- t = day2tab; /* leap year */
- else
- t = day1tab; /* not a leap year */
- if (d > t[m - 1])
- return (-1);
- for (i = 0; i < m - 1; i++)
- d += t[i];
- return d;
+ /*
+ * convert y/m/d to elapsed calendar units, convert that to
+ * elapsed days since the start of the given year and convert
+ * back to unity-based day in year.
+ *
+ * This does no further error checking, since the underlying
+ * function is assumed to work out how to handle the data.
+ */
+ return ntpcal_edate_to_yeardays(y-1, m-1, d-1) + 1;
}