Branch: Tag:

2002-03-21

2002-03-21 13:41:46 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Timezone fixes in mktime().
Fixes [bug 2861 (#2861)].

Rev: src/builtin_functions.c:1.356

5:   \*/   /**/   #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.355 2002/01/04 14:28:22 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.356 2002/03/21 13:41:46 grubba Exp $");   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"
4106: Inside #if defined(HAVE_MKTIME)
   struct tm date;    struct svalue s;    struct svalue * r; -  int retval; +  int retval, raw;    if (args<1)    SIMPLE_TOO_FEW_ARGS_ERROR("mktime", 1);   
4149: Inside #if defined(HAVE_MKTIME)
   date.tm_isdst = -1;    }    - #if STRUCT_TM_HAS_GMTOFF + #ifdef STRUCT_TM_HAS_GMTOFF +  /* BSD-style */ +  date.tm_gmtoff = 0; + #else + #ifdef STRUCT_TM_HAS___TM_GMTOFF +  /* Linux-style */ +  date.__tm_gmtoff = 0; + #endif /* STRUCT_TM_HAS___TM_GMTOFF */ + #endif /* STRUCT_TM_HAS_GMTOFF */ +  +  raw = retval = mktime(&date); +     if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER))    { -  date.tm_gmtoff=-Pike_sp[7-args].u.integer; -  }else{ -  time_t tmp = 0; -  date.tm_gmtoff=localtime(&tmp)->tm_gmtoff; -  } -  retval=mktime(&date); +  /* Adjust for the timezone. */ + #ifdef STRUCT_TM_HAS_GMTOFF +  retval += Pike_sp[7-args].u.integer + date.tm_gmtoff;   #else -  + #ifdef STRUCT_TM_HAS___TM_GMTOFF +  retval += Pike_sp[7-args].u.integer + date.__tm_gmtoff; + #else   #ifdef HAVE_EXTERNAL_TIMEZONE -  if((args > 7) && (Pike_sp[7-args].subtype == NUMBER_NUMBER)) -  { -  retval=mktime(&date) + Pike_sp[7-args].u.integer - timezone; -  }else{ -  retval=mktime(&date); +  retval += Pike_sp[7-args].u.integer - timezone; + #endif /* HAVE_EXTERNAL_TIMEZONE */ + #endif /* STRUCT_TM_HAS___TM_GMTOFF */ + #endif /* STRUCT_TM_HAS_GMTOFF */    } - #else -  retval=mktime(&date); - #endif - #endif +     -  if (retval == -1) +  if (raw == -1)    PIKE_ERROR("mktime", "Cannot convert.\n", Pike_sp, args);    pop_n_elems(args);    push_int(retval);