AcePerl

 view release on metacpan or  search on metacpan

acelib/timesubs.c  view on Meta::CPAN


  mdiff = ts2.tm_mon - ts1.tm_mon ;

  *diff = mdiff ;

  return TRUE ;
}

/**********************************************/

BOOL timeDiffYears (mytime_t t1, mytime_t t2, int *diff) 
/* NOTE: is always true, i.e. every date/time has a year */
{
  struct tm ts1, ts2;
  BOOL wantMonth1, wantDay1, wantHours1, wantMins1, wantSecs1;
  BOOL wantMonth2, wantDay2, wantHours2, wantMins2, wantSecs2;
  int yeardiff;

  timeStruct (&ts1, t1, &wantMonth1, &wantDay1, &wantHours1, &wantMins1, &wantSecs1) ;
  timeStruct (&ts2, t2, &wantMonth2, &wantDay2, &wantHours2, &wantMins2, &wantSecs2) ;

  yeardiff = ts2.tm_year - ts1.tm_year ;

  *diff = yeardiff ;

  return TRUE ;
}

/**********************************************/

/* compare two dates, returns boolean result of comparison depending on operator */
BOOL timeComparison (int      op,
		     mytime_t timeLeft, 
		     mytime_t timeRight)
/* op is the operator and is one of
   -1 = isLessThan
    0 = isEqual
    1 = isGreaterThan

   times can easily be compared, if they both specify the
   same level of detail, e.g.
        1996-03 < 1997-04        -> TRUE
     1998-06-07 = 1998-06-12     -> FALSE

   Complications occur, if the level of detail given varies in both dates :-

        1998-06 < 1998-07-09_09:51:23 -> TRUE
         the "lessthan" fact is decided on the months

           1990 = 1990-05-02   -> TRUE
     in case of equality the comparison asks if the lesser detailed date 
     is completely contained within the other, and the above 
     comparison evaluates TRUE, because May 2nd 1990 is in the year 1990

         1998-07 < 1998-07-09   -> FALSE
     because one date gives a specific day in July 1998, but as the
     first date misses the day, we can't decide whether it is earlier.
      
     Example: the movie City Hall was released on 1996-02-16.
        
       select m->Title, m->Released from m in class Movie where m->Released < `1996-02
       select m->Title, m->Released from m in class Movie where m->Released > `1996-02

     will BOTH EXnclude the movie 'City Hall', whereas
     
       select m->Title, m->Released from m in class Movie where m->Released < `1996-02-17
       select m->Title, m->Released from m in class Movie where m->Released <= `1996-02

     will both INclude 'City Hall'.
*/
/* mhmp 22.10.98
Ici, chaque date,  quel que soit son niveau de detail, est consideree
comme un intervalle.
1996-05  = [1996-05-01_00:00:00 , 1996-05-31_23:59:59] = INTER
date == 1996-05 <==> date appartient a INTER
date < 1996-05  <==> date < inf(INTER)

Appliquer cette regle aux dates "completees" (avec hms) est discutable.
Pour beaucoup,  1998-10-22_11:07 > 1998-10-22_11
surtout quand on vient de louper le train de 11h.
Cela sous-entend qu'il faudrait completer les dates
hms jusqu'a la seconde avec des zeros.
1998-10-22_11 -> 1998-10-22_11:00:00
*/
{
  int yearDiff, monthDiff, dayDiff, hourDiff, minDiff, secDiff;

  /*******************/
  /* year difference */
  timeDiffYears (timeLeft, timeRight, &yearDiff);
  
  if (yearDiff > 0)
    return (op < 0) ;

  if (yearDiff < 0)
    return (op > 0) ;

  /* yearDiff == 0 */
  /********************/
  /* month difference */
  if (!timeDiffMonths (timeLeft, timeRight, &monthDiff))
    /* can't decide on months */
    return (op == 0) ;

  if (monthDiff > 0)
    return (op < 0) ;

  if (monthDiff < 0) 
    return  (op > 0) ;

  /* monthDiff == 0 */
  /******************/
  /* day difference */
  if (!timeDiffDays (timeLeft, timeRight, &dayDiff))
    /* can't decide on days */
    return (op == 0) ;

  if (dayDiff > 0)
    return (op < 0) ;    

  if (dayDiff < 0)
    return  (op > 0) ;
	  
  /* dayDiff == 0 */
  /*******************/
  /* hour difference */
  if (!timeDiffHours (timeLeft, timeRight, &hourDiff))



( run in 1.348 second using v1.01-cache-2.11-cpan-5a3173703d6 )