pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: builtin_functions.c,v 1.526 2004/01/30 19:45:42 grubba Exp $ + || $Id: builtin_functions.c,v 1.527 2004/02/02 19:11:13 grubba Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.526 2004/01/30 19:45:42 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.527 2004/02/02 19:11:13 grubba Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"   #include "constants.h"   #include "mapping.h"   #include "stralloc.h"
pike.git/src/builtin_functions.c:4370:   #endif      #ifdef HAVE_GMTIME   /* Returns the approximate difference in seconds between the    * two struct tm's.    *    * NOTE: No checks for out of range are performed.    */   static time_t my_tm_diff(const struct tm *t1, const struct tm *t2)   { -  return (t1->tm_year - t2->tm_year) * 31557600 + -  (t1->tm_mon - t2->tm_mon) * 2629800 + +  time_t base = (t1->tm_year - t2->tm_year) * 31557600 +    (t1->tm_mday - t2->tm_mday) * 86400 +    (t1->tm_hour - t2->tm_hour) * 3600 +    (t1->tm_min - t2->tm_min) * 60 +    (t1->tm_sec - t2->tm_sec); -  +  if (t1->tm_mon == t2->tm_mon) return base; +  +  base += (t1->tm_mon - t2->tm_mon) * 30 * 86400; +  if (t1->tm_mon < 8) { +  base += (t1->tm_mon/2)*86400; +  } else { +  base += ((t1->tm_mon+1)/2)*86400;    } -  +  if (t1->tm_mon > 2) { +  /* Adjust for February. */ +  base -= 2*86400; +  base += !(t1->tm_year&3)*86400; /* Not year 2400 or 1600 safe. */ +  } +  if (t2->tm_mon < 8) { +  base -= (t2->tm_mon/2)*86400; +  } else { +  base -= ((t2->tm_mon+1)/2)*86400; +  } +  if (t2->tm_mon > 2) { +  /* Adjust for February. */ +  base += 2*86400; +  base -= !(t2->tm_year&3)*86400; /* Not year 2400 or 1600 safe. */ +  } +  return base; + }      /* Inverse operation of gmtime().    */   static time_t my_timegm(struct tm *target_tm)   {    time_t current_ts = 0;    time_t diff_ts;    struct tm *current_tm;    int loop_cnt = 0;