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.534 2004/03/30 12:50:56 grubba Exp $ + || $Id: builtin_functions.c,v 1.535 2004/04/01 15:44:56 grubba Exp $   */      #include "global.h" - RCSID("$Id: builtin_functions.c,v 1.534 2004/03/30 12:50:56 grubba Exp $"); + RCSID("$Id: builtin_functions.c,v 1.535 2004/04/01 15:44:56 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:4297: Inside #if defined(HAVE_LOCALTIME)
   *! Month of the year.    *! @member int(0..) "year"    *! Year since 1900.    *! @member int(0..6) "wday"    *! Day of week (0 = Sunday).    *! @member int(0..365) "yday"    *! Day of the year.    *! @member int(0..1) "isdst"    *! Is daylight savings time.    *! @member int "timezone" -  *! Offset from UTC. +  *! Offset from UTC, including daylight savings time adjustment.    *! @endmapping    *!    *! An error is thrown if the localtime(2) call failed on the system.    *! It's platform dependent what time ranges that function can handle,    *! e.g. Windows doesn't handle a negative @[timestamp].    *!    *! @note -  *! The field @expr{"timezone"@} may not be available on all platforms. +  *! Prior to Pike 7.5 the field @expr{"timezone"@} was sometimes not +  *! present, and was sometimes not adjusted for daylight savings time.    *!    *! @seealso    *! @[Calendar], @[gmtime()], @[time()], @[ctime()], @[mktime()]    */   PMOD_EXPORT void f_localtime(INT32 args)   {    struct tm *tm;    INT_TYPE tt;    time_t t;       get_all_args("localtime", args, "%i", &tt);       t = tt;    tm = localtime(&t);    if (!tm) Pike_error ("localtime() on this system cannot handle "    "the timestamp %ld.\n", (long) t);    pop_n_elems(args);    encode_struct_tm(tm);    - #ifdef STRUCT_TM_HAS_GMTOFF +     push_text("timezone"); -  + #ifdef STRUCT_TM_HAS_GMTOFF    push_int(-tm->tm_gmtoff); -  f_aggregate_mapping(20); - #else - #ifdef STRUCT_TM_HAS___TM_GMTOFF -  push_text("timezone"); + #elif defined(STRUCT_TM_HAS___TM_GMTOFF)    push_int(-tm->__tm_gmtoff); -  f_aggregate_mapping(20); + #elif defined(HAVE_EXTERNAL_TIMEZONE) +  /* Assume dst is one hour. */ +  push_int(timezone - 3600*tm->tm_isdst);   #else - #ifdef HAVE_EXTERNAL_TIMEZONE -  push_text("timezone"); -  push_int(timezone); -  f_aggregate_mapping(20); - #else -  f_aggregate_mapping(18); +  /* Assume dst is one hour. */ +  push_int(-3600*tm->tm_isdst);   #endif - #endif - #endif +  f_aggregate_mapping(20);   }   #endif      #ifdef HAVE_GMTIME   /* Returns the approximate difference in seconds between the    * two struct tm's.    */   static time_t my_tm_diff(const struct tm *t1, const struct tm *t2)   {    time_t base = (t1->tm_year - t2->tm_year) * 32140800 +
pike.git/src/builtin_functions.c:4375: Inside #if defined(HAVE_GMTIME)
     /* 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;    - #if 0 /* The dst offset is part of tz. */ -  /* Assume dst is one hour. */ -  target_tm->tm_hour -= target_tm->tm_isdst; - #endif /* 0 */ -  +     /* 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;