Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / ymd2yd.c
blob17357c6561f9f368c1ad78354b89d1574d8dd316
1 /* $NetBSD$ */
3 /*
4 * ymd2yd - compute the date in the year from y/m/d
5 */
7 #include "ntp_fp.h"
8 #include "ntp_unixtime.h"
9 #include "ntp_stdlib.h"
12 * Tables to compute the day of year from yyyymmdd timecode.
13 * Viva la leap.
15 static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
16 static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
18 int
19 ymd2yd(
20 int y,
21 int m,
22 int d
25 int i, *t;
27 if (m < 1 || m > 12 || d < 1)
28 return (-1);
30 if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0))
31 t = day2tab; /* leap year */
32 else
33 t = day1tab; /* not a leap year */
34 if (d > t[m - 1])
35 return (-1);
36 for (i = 0; i < m - 1; i++)
37 d += t[i];
38 return d;