home *** CD-ROM | disk | FTP | other *** search
- /*
- * datecomp.c
- * contains: datecomp()
- *
- */
-
- #include <stdio.h>
- #include "gfuncts.h"
-
- /*
- * int
- * datecomp(t1,t2,diff)
- *
- * ARGUMENT
- * (struct TIMEDATE *) t1 - pointer to first date/time struct
- * (struct TIMEDATE *) t2 - pointer to second to compare with
- * (int) diff - return days between (1)
- * or minutes between (2)
- *
- * DESCRIPTION
- * Subtract t1 - t2. Working on basis of day of year, determine the
- * difference between the two in terms of days or minutes.
- *
- * RETURNS
- *
- * 0 if dates are same,
- * +n if t1 > t2
- * -n if t1 < t2
- *
- * AUTHOR
- * Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- */
- int GF_CONV datecomp(t1,t2,diff)
- struct TIMEDATE *t1,*t2;
- int diff;
- {
- int GF_CONV dayofyr();
- int minutes1,minutes2,dayofyr1,dayofyr2;
- struct TIMEDATE tmp,stmp;
-
- if(diff==1) {
- dayofyr1=dayofyr(t1->month,t1->day,t1->year);
- dayofyr2=dayofyr(t2->month,t2->day,t2->year);
- if(t1->year != t2->year) {
- stmp.month=1;
- stmp.day=1;
- tmp.month=12;
- tmp.day=31;
- if(t1->year>t2->year) { /* Bring t2 up to t1 */
- tmp.year=t2->year;
- dayofyr2 = datecomp(&tmp,t2,1);
- /* Days remaining in year */
- ++tmp.year;
- while(tmp.year < t1->year) {
- stmp.year=tmp.year;
- dayofyr2 += datecomp(&tmp,&stmp,1);
- ++tmp.year;
- }
- return(dayofyr2+dayofyr1);
- } else { /* Bring t1 up to t2 */
- tmp.year=t1->year;
- dayofyr1=datecomp(&tmp,t1,1);
- /* Days remaining in year */
- ++tmp.year;
- while(tmp.year < t2->year) {
- stmp.year=tmp.year;
- dayofyr1 += datecomp(&tmp,&stmp,1);
- ++tmp.year;
- }
- return((dayofyr2+dayofyr1) * -1);
- }
- }
- if(dayofyr1==dayofyr2)
- return(0);
- if(dayofyr1 > dayofyr2)
- return(dayofyr1 - dayofyr2);
- else
- return((dayofyr2 - dayofyr1) * -1);
- }
- if(diff==2) {
- minutes1=t1->hours * 60 + t1->minutes;
- minutes2=t2->hours * 60 + t2->minutes;
- if(minutes1==minutes2)
- return(0);
- if(minutes1>minutes2)
- return(minutes1-minutes2);
- else
- return((minutes2-minutes1) * -1);
- }
- return(0);
- }
-