17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
507abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India * Common Development and Distribution License (the "License").
607abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
2207abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
277c478bd9Sstevel@tonic-gate /* All Rights Reserved */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate * pnpsplit splits interval into prime & nonprime portions
327c478bd9Sstevel@tonic-gate * ONLY ROUTINE THAT KNOWS ABOUT HOLIDAYS AND DEFN OF PRIME/NONPRIME
337c478bd9Sstevel@tonic-gate */
347c478bd9Sstevel@tonic-gate
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/param.h>
387c478bd9Sstevel@tonic-gate #include "acctdef.h"
397c478bd9Sstevel@tonic-gate #include <time.h>
407c478bd9Sstevel@tonic-gate #include <ctype.h>
417c478bd9Sstevel@tonic-gate
4207abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India /*
4307abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India * validate that hours and minutes of prime/non-prime read in
447c478bd9Sstevel@tonic-gate * from holidays file fall within proper boundaries.
4507abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India * Time is expected in the form and range of 0000-2400.
467c478bd9Sstevel@tonic-gate */
477c478bd9Sstevel@tonic-gate
487c478bd9Sstevel@tonic-gate static int thisyear = 1970; /* this is changed by holidays file */
497c478bd9Sstevel@tonic-gate static int holidays[NHOLIDAYS]; /* holidays file day-of-year table */
507c478bd9Sstevel@tonic-gate
5107abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India
527c478bd9Sstevel@tonic-gate static int day_tab[2][13] = {
537c478bd9Sstevel@tonic-gate {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
547c478bd9Sstevel@tonic-gate {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
557c478bd9Sstevel@tonic-gate };
567c478bd9Sstevel@tonic-gate
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate * prime(0) and nonprime(1) times during a day
597c478bd9Sstevel@tonic-gate * for BTL, prime time is 9AM to 5PM
607c478bd9Sstevel@tonic-gate */
617c478bd9Sstevel@tonic-gate static struct hours {
627c478bd9Sstevel@tonic-gate int h_sec; /* normally always zero */
637c478bd9Sstevel@tonic-gate int h_min; /* initialized from holidays file (time%100) */
647c478bd9Sstevel@tonic-gate int h_hour; /* initialized from holidays file (time/100) */
657c478bd9Sstevel@tonic-gate long h_type; /* prime/nonprime of previous period */
667c478bd9Sstevel@tonic-gate } h[4];
677c478bd9Sstevel@tonic-gate
68*8f56e6bbSToomas Soome /* the sec, min, hr of the day's end */
69*8f56e6bbSToomas Soome struct tm daysend = {
70*8f56e6bbSToomas Soome .tm_sec = 0,
71*8f56e6bbSToomas Soome .tm_min = 60,
72*8f56e6bbSToomas Soome .tm_hour = 23
73*8f56e6bbSToomas Soome };
74*8f56e6bbSToomas Soome
75*8f56e6bbSToomas Soome long tmsecs(struct tm *, struct tm *);
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate * split interval of length etime, starting at start into prime/nonprime
797c478bd9Sstevel@tonic-gate * values, return as result
807c478bd9Sstevel@tonic-gate * input values in seconds
817c478bd9Sstevel@tonic-gate */
82414388d7Ssl int
pnpsplit(long start,ulong_t etime,long result[2])83*8f56e6bbSToomas Soome pnpsplit(long start, ulong_t etime, long result[2])
847c478bd9Sstevel@tonic-gate {
85*8f56e6bbSToomas Soome struct tm cur, end, hours;
867c478bd9Sstevel@tonic-gate time_t tcur, tend;
877c478bd9Sstevel@tonic-gate long tmp;
88414388d7Ssl int sameday;
89*8f56e6bbSToomas Soome struct hours *hp;
907c478bd9Sstevel@tonic-gate
917c478bd9Sstevel@tonic-gate /* once holidays file is read, this is zero */
9207abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India if(thisyear && (checkhol() == 0)) {
937c478bd9Sstevel@tonic-gate return(0);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate tcur = start;
9607abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India tend = start + etime;
977c478bd9Sstevel@tonic-gate memcpy(&end, localtime(&tend), sizeof(end));
987c478bd9Sstevel@tonic-gate result[PRIME] = 0;
997c478bd9Sstevel@tonic-gate result[NONPRIME] = 0;
1007c478bd9Sstevel@tonic-gate
10107abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India while ( tcur < tend ) { /* one iteration per day or part thereof */
1027c478bd9Sstevel@tonic-gate memcpy(&cur, localtime(&tcur), sizeof(cur));
1037c478bd9Sstevel@tonic-gate sameday = cur.tm_yday == end.tm_yday;
1047c478bd9Sstevel@tonic-gate if (ssh(&cur)) { /* ssh:only NONPRIME */
1057c478bd9Sstevel@tonic-gate if (sameday) {
1067c478bd9Sstevel@tonic-gate result[NONPRIME] += tend-tcur;
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate break;
1097c478bd9Sstevel@tonic-gate } else {
110*8f56e6bbSToomas Soome tmp = tmsecs(&cur, &daysend);
1117c478bd9Sstevel@tonic-gate result[NONPRIME] += tmp;
1127c478bd9Sstevel@tonic-gate tcur += tmp;
1137c478bd9Sstevel@tonic-gate }
1147c478bd9Sstevel@tonic-gate } else { /* working day, PRIME or NONPRIME */
1157c478bd9Sstevel@tonic-gate for (hp = h; tmless(hp, &cur); hp++);
1167c478bd9Sstevel@tonic-gate for (; hp->h_sec >= 0; hp++) {
1177c478bd9Sstevel@tonic-gate if (sameday && tmless(&end, hp)) {
1187c478bd9Sstevel@tonic-gate /* WHCC mod, change from = to += 3/6/86 Paul */
1197c478bd9Sstevel@tonic-gate result[hp->h_type] += tend-tcur;
1207c478bd9Sstevel@tonic-gate tcur = tend;
1217c478bd9Sstevel@tonic-gate break; /* all done */
1227c478bd9Sstevel@tonic-gate } else { /* time to next PRIME /NONPRIME change */
123*8f56e6bbSToomas Soome hours.tm_sec = hp->h_sec;
124*8f56e6bbSToomas Soome hours.tm_min = hp->h_min;
125*8f56e6bbSToomas Soome hours.tm_hour = hp->h_hour;
126*8f56e6bbSToomas Soome tmp = tmsecs(&cur, &hours);
1277c478bd9Sstevel@tonic-gate result[hp->h_type] += tmp;
1287c478bd9Sstevel@tonic-gate tcur += tmp;
1297c478bd9Sstevel@tonic-gate cur.tm_sec = hp->h_sec;
1307c478bd9Sstevel@tonic-gate cur.tm_min = hp->h_min;
1317c478bd9Sstevel@tonic-gate cur.tm_hour = hp->h_hour;
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate }
1347c478bd9Sstevel@tonic-gate }
1357c478bd9Sstevel@tonic-gate }
1367c478bd9Sstevel@tonic-gate return(1);
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate /*
1407c478bd9Sstevel@tonic-gate * Starting day after Christmas, complain if holidays not yet updated.
1417c478bd9Sstevel@tonic-gate * This code is only executed once per program invocation.
1427c478bd9Sstevel@tonic-gate */
143414388d7Ssl int
checkhol(void)144*8f56e6bbSToomas Soome checkhol(void)
1457c478bd9Sstevel@tonic-gate {
146*8f56e6bbSToomas Soome struct tm *tp;
1477c478bd9Sstevel@tonic-gate time_t t;
1487c478bd9Sstevel@tonic-gate
1497c478bd9Sstevel@tonic-gate if(inithol() == 0) {
1507c478bd9Sstevel@tonic-gate fprintf(stderr, "pnpsplit: holidays table setup failed\n");
1517c478bd9Sstevel@tonic-gate thisyear = 0;
1527c478bd9Sstevel@tonic-gate holidays[0] = -1;
1537c478bd9Sstevel@tonic-gate return(0);
1547c478bd9Sstevel@tonic-gate }
1557c478bd9Sstevel@tonic-gate time(&t);
1567c478bd9Sstevel@tonic-gate tp = localtime(&t);
1577c478bd9Sstevel@tonic-gate tp->tm_year += 1900;
1587c478bd9Sstevel@tonic-gate if ((tp->tm_year == thisyear && tp->tm_yday > 359)
1597c478bd9Sstevel@tonic-gate || tp->tm_year > thisyear)
1607c478bd9Sstevel@tonic-gate fprintf(stderr,
1617c478bd9Sstevel@tonic-gate "***UPDATE %s WITH NEW HOLIDAYS***\n", HOLFILE);
1627c478bd9Sstevel@tonic-gate thisyear = 0; /* checkhol() will not be called again */
1637c478bd9Sstevel@tonic-gate return(1);
1647c478bd9Sstevel@tonic-gate }
1657c478bd9Sstevel@tonic-gate
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate * ssh returns 1 if Sat, Sun, or Holiday
1687c478bd9Sstevel@tonic-gate */
169414388d7Ssl int
ssh(struct tm * ltp)170*8f56e6bbSToomas Soome ssh(struct tm *ltp)
1717c478bd9Sstevel@tonic-gate {
172414388d7Ssl int i;
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate if (ltp->tm_wday == 0 || ltp->tm_wday == 6)
1757c478bd9Sstevel@tonic-gate return(1);
17655fea89dSDan Cross for (i = 0; holidays[i] >= 0; i++)
1777c478bd9Sstevel@tonic-gate if (ltp->tm_yday == holidays[i])
1787c478bd9Sstevel@tonic-gate return(1);
1797c478bd9Sstevel@tonic-gate return(0);
1807c478bd9Sstevel@tonic-gate }
1817c478bd9Sstevel@tonic-gate
1827c478bd9Sstevel@tonic-gate /*
1837c478bd9Sstevel@tonic-gate * inithol - read from an ascii file and initialize the "thisyear"
1847c478bd9Sstevel@tonic-gate * variable, the times that prime and non-prime start, and the
1857c478bd9Sstevel@tonic-gate * holidays array.
1867c478bd9Sstevel@tonic-gate */
187414388d7Ssl int
inithol(void)188*8f56e6bbSToomas Soome inithol(void)
1897c478bd9Sstevel@tonic-gate {
190*8f56e6bbSToomas Soome FILE *holptr;
191*8f56e6bbSToomas Soome char holbuf[128];
192*8f56e6bbSToomas Soome int line = 0,
1937c478bd9Sstevel@tonic-gate holindx = 0,
1947c478bd9Sstevel@tonic-gate errflag = 0;
1957c478bd9Sstevel@tonic-gate int pstart, npstart;
1967c478bd9Sstevel@tonic-gate int doy; /* day of the year */
1977c478bd9Sstevel@tonic-gate int month, day;
1987c478bd9Sstevel@tonic-gate char *c;
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate if((holptr=fopen(HOLFILE, "r")) == NULL) {
2017c478bd9Sstevel@tonic-gate perror(HOLFILE);
2027c478bd9Sstevel@tonic-gate fclose(holptr);
2037c478bd9Sstevel@tonic-gate return(0);
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate while(fgets(holbuf, sizeof(holbuf), holptr) != NULL) {
2067c478bd9Sstevel@tonic-gate /* skip over blank lines and comments */
2077c478bd9Sstevel@tonic-gate if (holbuf[0] == '*')
2087c478bd9Sstevel@tonic-gate continue;
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate for (c = holbuf; isspace(*c); c++)
2117c478bd9Sstevel@tonic-gate /* is a space */;
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate if (*c == '\0')
2147c478bd9Sstevel@tonic-gate continue;
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate else if(++line == 1) { /* format: year p-start np-start */
2177c478bd9Sstevel@tonic-gate if(sscanf(holbuf, "%4d %4d %4d",
2187c478bd9Sstevel@tonic-gate &thisyear, &pstart, &npstart) != 3) {
2197c478bd9Sstevel@tonic-gate fprintf(stderr,
2207c478bd9Sstevel@tonic-gate "%s: bad {yr ptime nptime} conversion\n",
2217c478bd9Sstevel@tonic-gate HOLFILE);
2227c478bd9Sstevel@tonic-gate errflag++;
2237c478bd9Sstevel@tonic-gate break;
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate /* validate year */
2277c478bd9Sstevel@tonic-gate if(thisyear < 1970 || thisyear > 2037) {
2287c478bd9Sstevel@tonic-gate fprintf(stderr, "pnpsplit: invalid year: %d\n",
2297c478bd9Sstevel@tonic-gate thisyear);
2307c478bd9Sstevel@tonic-gate errflag++;
2317c478bd9Sstevel@tonic-gate break;
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate /* validate prime/nonprime hours */
2357c478bd9Sstevel@tonic-gate if((! okay(pstart)) || (! okay(npstart))) {
2367c478bd9Sstevel@tonic-gate fprintf(stderr,
2377c478bd9Sstevel@tonic-gate "pnpsplit: invalid p/np hours\n");
2387c478bd9Sstevel@tonic-gate errflag++;
2397c478bd9Sstevel@tonic-gate break;
2407c478bd9Sstevel@tonic-gate }
2417c478bd9Sstevel@tonic-gate
2427c478bd9Sstevel@tonic-gate /* Set up start of prime time; 2400 == 0000 */
2437c478bd9Sstevel@tonic-gate h[0].h_sec = 0;
2447c478bd9Sstevel@tonic-gate h[0].h_min = pstart%100;
2457c478bd9Sstevel@tonic-gate h[0].h_hour = (pstart/100==24) ? 0 : pstart/100;
2467c478bd9Sstevel@tonic-gate h[0].h_type = NONPRIME;
2477c478bd9Sstevel@tonic-gate
24807abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India /* Set up start of non-prime time; 2400 == 2360 */
24907abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India if ((npstart/100) == 24) {
25007abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_sec = 0;
25107abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_min = 60;
25207abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_hour = 23;
25307abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India } else {
25407abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_sec = 0;
25507abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_min = npstart % 100;
25607abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_hour = npstart / 100;
25707abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India }
25807abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India
259ea13b005SYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[1].h_type = PRIME;
2607c478bd9Sstevel@tonic-gate
2617c478bd9Sstevel@tonic-gate /* This is the end of the day */
26207abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[2].h_sec = 0;
26307abedfbSYateesh Kumar Vusirika - Sun Microsystems - Bangalore India h[2].h_min = 60;
2647c478bd9Sstevel@tonic-gate h[2].h_hour = 23;
2657c478bd9Sstevel@tonic-gate h[2].h_type = NONPRIME;
2667c478bd9Sstevel@tonic-gate
2677c478bd9Sstevel@tonic-gate /* The end of the array */
2687c478bd9Sstevel@tonic-gate h[3].h_sec = -1;
2697c478bd9Sstevel@tonic-gate
2707c478bd9Sstevel@tonic-gate continue;
2717c478bd9Sstevel@tonic-gate }
2727c478bd9Sstevel@tonic-gate else if(holindx >= NHOLIDAYS) {
2737c478bd9Sstevel@tonic-gate fprintf(stderr, "pnpsplit: too many holidays, ");
2747c478bd9Sstevel@tonic-gate fprintf(stderr, "recompile with larger NHOLIDAYS\n");
2757c478bd9Sstevel@tonic-gate errflag++;
2767c478bd9Sstevel@tonic-gate break;
2777c478bd9Sstevel@tonic-gate }
2787c478bd9Sstevel@tonic-gate
2797c478bd9Sstevel@tonic-gate /* Fill up holidays array from holidays file */
2807c478bd9Sstevel@tonic-gate sscanf(holbuf, "%d/%d %*s %*s %*[^\n]\n", &month, &day);
2817c478bd9Sstevel@tonic-gate if (month < 0 || month > 12) {
2827c478bd9Sstevel@tonic-gate fprintf(stderr, "pnpsplit: invalid month %d\n", month);
2837c478bd9Sstevel@tonic-gate errflag++;
2847c478bd9Sstevel@tonic-gate break;
2857c478bd9Sstevel@tonic-gate }
2867c478bd9Sstevel@tonic-gate if (day < 0 || day > 31) {
2877c478bd9Sstevel@tonic-gate fprintf(stderr, "pnpsplit: invalid day %d\n", day);
2887c478bd9Sstevel@tonic-gate errflag++;
2897c478bd9Sstevel@tonic-gate break;
2907c478bd9Sstevel@tonic-gate }
29155fea89dSDan Cross doy = day_of_year(thisyear, month, day);
2927c478bd9Sstevel@tonic-gate holidays[holindx++] = (doy - 1);
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate fclose(holptr);
2957c478bd9Sstevel@tonic-gate if(!errflag && holindx < NHOLIDAYS) {
2967c478bd9Sstevel@tonic-gate holidays[holindx] = -1;
2977c478bd9Sstevel@tonic-gate return(1);
2987c478bd9Sstevel@tonic-gate }
2997c478bd9Sstevel@tonic-gate else
3007c478bd9Sstevel@tonic-gate return(0);
3017c478bd9Sstevel@tonic-gate }
3027c478bd9Sstevel@tonic-gate
3037c478bd9Sstevel@tonic-gate /*
3047c478bd9Sstevel@tonic-gate * tmsecs returns number of seconds from t1 to t2,
3057c478bd9Sstevel@tonic-gate * times expressed in localtime format.
3067c478bd9Sstevel@tonic-gate * assumed that t1 <= t2, and are in same day.
3077c478bd9Sstevel@tonic-gate */
3087c478bd9Sstevel@tonic-gate
3097c478bd9Sstevel@tonic-gate long
tmsecs(struct tm * t1,struct tm * t2)310*8f56e6bbSToomas Soome tmsecs(struct tm *t1, struct tm *t2)
3117c478bd9Sstevel@tonic-gate {
3127c478bd9Sstevel@tonic-gate return((t2->tm_sec - t1->tm_sec) +
3137c478bd9Sstevel@tonic-gate 60*(t2->tm_min - t1->tm_min) +
3147c478bd9Sstevel@tonic-gate 3600L*(t2->tm_hour - t1->tm_hour));
3157c478bd9Sstevel@tonic-gate }
3167c478bd9Sstevel@tonic-gate
3177c478bd9Sstevel@tonic-gate /*
3187c478bd9Sstevel@tonic-gate * return 1 if t1 earlier than t2 (times in localtime format)
3197c478bd9Sstevel@tonic-gate * assumed that t1 and t2 are in same day
3207c478bd9Sstevel@tonic-gate */
3217c478bd9Sstevel@tonic-gate
322414388d7Ssl int
tmless(struct tm * t1,struct tm * t2)323*8f56e6bbSToomas Soome tmless(struct tm *t1, struct tm *t2)
3247c478bd9Sstevel@tonic-gate {
3257c478bd9Sstevel@tonic-gate if (t1->tm_hour != t2->tm_hour)
3267c478bd9Sstevel@tonic-gate return(t1->tm_hour < t2->tm_hour);
3277c478bd9Sstevel@tonic-gate if (t1->tm_min != t2->tm_min)
3287c478bd9Sstevel@tonic-gate return(t1->tm_min < t2->tm_min);
3297c478bd9Sstevel@tonic-gate return(t1->tm_sec < t2->tm_sec);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate /* set day of year from month and day */
3337c478bd9Sstevel@tonic-gate
334414388d7Ssl int
day_of_year(int year,int month,int day)335*8f56e6bbSToomas Soome day_of_year(int year, int month, int day)
3367c478bd9Sstevel@tonic-gate {
3377c478bd9Sstevel@tonic-gate int i, leap;
3387c478bd9Sstevel@tonic-gate
3397c478bd9Sstevel@tonic-gate leap = year%4 == 0 && year%100 || year%400 == 0;
3407c478bd9Sstevel@tonic-gate for (i = 1; i < month; i++)
3417c478bd9Sstevel@tonic-gate day += day_tab[leap][i];
3427c478bd9Sstevel@tonic-gate return(day);
3437c478bd9Sstevel@tonic-gate }
344