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.527 2004/02/02 19:11:13 grubba Exp $ + || $Id: builtin_functions.c,v 1.528 2004/02/02 20:45:19 grubba Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.527 2004/02/02 19:11:13 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.528 2004/02/02 20:45:19 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:4378: Inside #if defined(HAVE_GMTIME)
  static time_t my_tm_diff(const struct tm *t1, const struct tm *t2)   {    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 { +  if (t1->tm_mon < 7) {    base += ((t1->tm_mon+1)/2)*86400; -  +  } else { +  base += ((t1->tm_mon+2)/2)*86400;    } -  if (t1->tm_mon > 2) { +  if (t1->tm_mon > 1) {    /* 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 { +  if (t2->tm_mon < 7) {    base -= ((t2->tm_mon+1)/2)*86400; -  +  } else { +  base -= ((t2->tm_mon+2)/2)*86400;    } -  if (t2->tm_mon > 2) { +  if (t2->tm_mon > 1) {    /* 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)
pike.git/src/builtin_functions.c:4419: Inside #if defined(HAVE_GMTIME)
      /* Assume dst is one hour. */    target_tm->tm_hour -= target_tm->tm_isdst;       /* This loop seems stable, and usually converges in two passes.    * The loop counter is for paranoia reasons.    */    while((diff_ts = my_tm_diff(target_tm, current_tm = gmtime(&current_ts)))) {    current_ts += diff_ts;    loop_cnt++; +  fprintf(stderr, "Loop [%d]: %d, %d\n", loop_cnt, current_ts, diff_ts);    if (loop_cnt > 20) {    /* Infinite loop? */    return -1;    }    }    /* Check that the result tm looks like what we expect... */    if ((current_tm->tm_sec == target_tm->tm_sec) &&    (current_tm->tm_min == target_tm->tm_min)) {    /* Odds are that the rest of the fields are correct (1:3600). */    return current_ts;