File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ntp / libntp / ymd2yd.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue May 29 12:08:38 2012 UTC (12 years ago) by misho
Branches: ntp, MAIN
CVS tags: v4_2_6p5p0, v4_2_6p5, HEAD
ntp 4.2.6p5

    1: /*
    2:  * ymd2yd - compute the date in the year from y/m/d
    3:  */
    4: 
    5: #include "ntp_fp.h"
    6: #include "ntp_unixtime.h"
    7: #include "ntp_stdlib.h"
    8: 
    9: /*
   10:  * Tables to compute the day of year from yyyymmdd timecode.
   11:  * Viva la leap.
   12:  */
   13: static int day1tab[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   14: static int day2tab[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
   15: 
   16: int
   17: ymd2yd(
   18: 	int y,
   19: 	int m,
   20: 	int d
   21: 	)
   22: {
   23: 	int i, *t;
   24: 
   25: 	if (m < 1 || m > 12 || d < 1)
   26: 		return (-1);
   27: 
   28: 	if (((y%4 == 0) && (y%100 != 0)) || (y%400 == 0))
   29: 		t = day2tab;	/* leap year */
   30: 	else
   31: 		t = day1tab;	/* not a leap year */
   32: 	if (d > t[m - 1])
   33: 		return (-1);
   34: 	for (i = 0; i < m - 1; i++)
   35: 		d += t[i];
   36: 	return d;
   37: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>