Branch: Tag:

2004-02-02

2004-02-02 19:11:13 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Some my_tm_diff() related fixes.

Rev: src/builtin_functions.c:1.527

2:   || 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"
4377: Inside #if defined(HAVE_GMTIME)
   */   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().    */