Current Path : /usr/src/contrib/ntp/libntp/ |
FreeBSD hs32.drive.ne.jp 9.1-RELEASE FreeBSD 9.1-RELEASE #1: Wed Jan 14 12:18:08 JST 2015 root@hs32.drive.ne.jp:/sys/amd64/compile/hs32 amd64 |
Current File : //usr/src/contrib/ntp/libntp/ymd2yd.c |
/* * 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; }