summaryrefslogtreecommitdiffstats
path: root/contrib/ntp/libntp/ymd2yd.c
diff options
context:
space:
mode:
authorroberto <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
committerroberto <roberto@FreeBSD.org>1999-12-09 13:01:21 +0000
commitef64b99e8412f2273dd2e8b3291c2f78ffc4667f (patch)
treefc0cfa1aab0ff6b228f511b410733ef4f35d1ead /contrib/ntp/libntp/ymd2yd.c
downloadFreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.zip
FreeBSD-src-ef64b99e8412f2273dd2e8b3291c2f78ffc4667f.tar.gz
Virgin import of ntpd 4.0.98f
Diffstat (limited to 'contrib/ntp/libntp/ymd2yd.c')
-rw-r--r--contrib/ntp/libntp/ymd2yd.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/contrib/ntp/libntp/ymd2yd.c b/contrib/ntp/libntp/ymd2yd.c
new file mode 100644
index 0000000..796ce40
--- /dev/null
+++ b/contrib/ntp/libntp/ymd2yd.c
@@ -0,0 +1,37 @@
+/*
+ * ymd2yd - compute the date in the year from y/m/d
+ */
+
+#include "ntp_fp.h"
+#include "ntp_unixtime.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};
+
+int
+ymd2yd(
+ int y,
+ int m,
+ 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;
+}
OpenPOWER on IntegriCloud