diff --git a/src/builtin.cmod b/src/builtin.cmod index 6876903f930536eb6b9f8356ac386a6fa4a23829..6eca31f1b249c702720add6c4e0caa9b4cb7d0dd 100644 --- a/src/builtin.cmod +++ b/src/builtin.cmod @@ -58,7 +58,7 @@ #define SET_GMTOFF(TM, VAL) (((TM)->tm_gmtoff) = (VAL)) #define SET_ZONE(this, VAL) ((this)->t.tm_zone = (VAL)) #else - struct tm_extra { const char*tm_zone; }; + struct tm_extra { const char *tm_zone; }; #define GET_GMTOFF(TM) 0 #define GET_ZONE(this) ((this)->extra.tm_zone) #define SET_GMTOFF(TM, VAL) (VAL) @@ -79,7 +79,6 @@ PIKECLASS TM CVAR struct tm t; CVAR time_t unix_time; CVAR int modified; - CVAR struct pike_string *set_zone; CVAR struct tm_extra extra; #define strftime_zone strftime @@ -91,20 +90,20 @@ PIKECLASS TM #endif #define MODIFY(X) do{ THIS->modified = 1;THIS->t.X; }while(0) -#define FIX_THIS(fname) do { \ +#define FIX_THIS() do { \ if(THIS->modified) \ - fix_tm(fname, args, THIS); \ + fix_tm(THIS); \ } while(0) -static void fix_tm(const char*fname, int args, struct TM_struct*this) -{ - const char*tm_zone = GET_ZONE(this); - int is_utc_zone = tm_zone && !strcmp(tm_zone, "UTC"); - if (is_utc_zone) - this->t.tm_isdst = 0; - this->unix_time = mktime_zone(fname, args, &this->t, is_utc_zone, 0); - this->modified = 0; -} + static void fix_tm(struct TM_struct *this) + { + const char *tm_zone = GET_ZONE(this); + int is_utc_zone = tm_zone && !strcmp(tm_zone, "UTC"); + if (is_utc_zone) + this->t.tm_isdst = 0; + this->unix_time = mktime_zone(&this->t, is_utc_zone, 0); + this->modified = 0; + } #ifdef HAVE_STRPTIME /*! @decl int(0..1) strptime( string(1..255) format, string(1..255) data ) @@ -366,13 +365,13 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) *! Unlike the system struct tm the 'year' field is not year-1900, *! instead it is the actual year. */ - PIKEFUN int(0..60) `sec() { FIX_THIS("sec");RETURN THIS->t.tm_sec; } - PIKEFUN int(0..59) `min() { FIX_THIS("min");RETURN THIS->t.tm_min; } - PIKEFUN int(0..23) `hour() { FIX_THIS("hour");RETURN THIS->t.tm_hour; } - PIKEFUN int(1..31) `mday() { FIX_THIS("mday");RETURN THIS->t.tm_mday; } - PIKEFUN int(0..11) `mon() { FIX_THIS("mon");RETURN THIS->t.tm_mon; } + PIKEFUN int(0..60) `sec() { FIX_THIS();RETURN THIS->t.tm_sec; } + PIKEFUN int(0..59) `min() { FIX_THIS();RETURN THIS->t.tm_min; } + PIKEFUN int(0..23) `hour() { FIX_THIS();RETURN THIS->t.tm_hour; } + PIKEFUN int(1..31) `mday() { FIX_THIS();RETURN THIS->t.tm_mday; } + PIKEFUN int(0..11) `mon() { FIX_THIS();RETURN THIS->t.tm_mon; } - PIKEFUN int `year() { FIX_THIS("year");RETURN THIS->t.tm_year+1900; } + PIKEFUN int `year() { FIX_THIS();RETURN THIS->t.tm_year+1900; } PIKEFUN int `sec=(int a) { MODIFY(tm_sec=a); } PIKEFUN int `min=(int a) { MODIFY(tm_min=a); } PIKEFUN int `hour=(int a){ MODIFY(tm_hour=a); } @@ -387,7 +386,7 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) *! automatically using the timezone rules. */ PIKEFUN int(-1..1) `isdst() { - FIX_THIS("isdst"); + FIX_THIS(); RETURN THIS->t.tm_isdst; } @@ -395,13 +394,13 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) *! The day of the week, sunday is 0, saturday is 6. *! This is calculated from the other fields and can not be changed directly. */ - PIKEFUN int(0..6) `wday() { FIX_THIS("wday"); RETURN THIS->t.tm_wday; } + PIKEFUN int(0..6) `wday() { FIX_THIS(); RETURN THIS->t.tm_wday; } /*! @decl int yday *! The day of the year, from 0 (the first day) to 365 *! This is calculated from the other fields and can not be changed directly. */ - PIKEFUN int(0..365) `yday() { FIX_THIS("yday"); RETURN THIS->t.tm_yday; } + PIKEFUN int(0..365) `yday() { FIX_THIS(); RETURN THIS->t.tm_yday; } /*! @decl int unix_time() *! Return the unix time corresponding to this time_t. If no time @@ -409,7 +408,7 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) */ PIKEFUN int unix_time() { - FIX_THIS("unix_time"); + FIX_THIS(); RETURN THIS->unix_time; } @@ -420,7 +419,7 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) */ PIKEFUN string asctime() { - FIX_THIS("asctime"); + FIX_THIS(); { #define STRFTIME_MAXSIZE 26 char s[STRFTIME_MAXSIZE]; @@ -495,7 +494,7 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) *! The timezone of this structure */ PIKEFUN string `zone() { - FIX_THIS("zone"); + FIX_THIS(); if( GET_ZONE(THIS) ) push_text( GET_ZONE(THIS) ); else @@ -506,20 +505,10 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) *! The offset from GMT for the time in this tm-struct */ PIKEFUN int `gmtoff() { - FIX_THIS("gmtoff"); + FIX_THIS(); push_int( GET_GMTOFF(&(THIS->t)) ); } - /* Setting the zone does not work, so.. */ - - /* PIKEFUN string `zone=(string x) { */ - /* if( THIS->set_zone ) */ - /* free_string( THIS->set_zone ); */ - /* THIS->set_zone = x; */ - /* MODIFY( tm_zone = x->str ); */ - /* x->refs++; */ - /* } */ - /*! @decl int(0..1) localtime( int time ) *! Initialize the struct tm to the local time for the specified *! unix time_t. @@ -589,41 +578,30 @@ static void fix_tm(const char*fname, int args, struct TM_struct*this) string|void timezone ) { struct tm *t = &THIS->t; - int use_utc; - t->tm_isdst = use_utc ? 0 : -1; + int use_utc = 0; + t->tm_isdst = -1; t->tm_year = year - 1900; t->tm_mon = mon; t->tm_mday = mday; t->tm_hour = hour; t->tm_min = min; t->tm_sec = sec; - use_utc = 0; if (timezone) { if (strcmp(timezone->str, "UTC")) Pike_error("Timezone must either be UTC or omitted.\n"); use_utc = 1; } - if (THIS->set_zone) { - free_string(THIS->set_zone); - THIS->set_zone = NULL; - } if (use_utc) t->tm_isdst = 0; - THIS->unix_time = mktime_zone("TM", args, &THIS->t, use_utc, 0); + THIS->unix_time = mktime_zone(&THIS->t, use_utc, 0); /* Setting it to other timezones than UTC is not supported (yet) */ if (use_utc) SET_ZONE(THIS, "UTC"); } INIT { - THIS->set_zone = 0; THIS->modified = 0; } - - EXIT { - if( THIS->set_zone ) - free_string( THIS->set_zone ); - } } /*! @endclass */ diff --git a/src/builtin_functions.c b/src/builtin_functions.c index dc86b6a8c07254bea99283433fa4e646e99d19e9..323ab04fbd92e5e4b7464cb7798cc41a65cce87a 100644 --- a/src/builtin_functions.c +++ b/src/builtin_functions.c @@ -5733,8 +5733,7 @@ PMOD_EXPORT void f_localtime(INT32 args) f_aggregate_mapping(20); } -time_t mktime_zone(const char*fname, int args, - struct tm*date, int other_timezone, int tz) +time_t mktime_zone(struct tm *date, int other_timezone, int tz) { time_t retval; int normalised_time; @@ -5760,7 +5759,7 @@ time_t mktime_zone(const char*fname, int args, retval = mktime(date); if (date->tm_wday < 0) - PIKE_ERROR("mktime", "Time conversion unsuccessful.\n", Pike_sp, args); + Pike_error("Time conversion unsuccessful.\n"); if(other_timezone) { @@ -5865,7 +5864,7 @@ PMOD_EXPORT void f_mktime (INT32 args) date.tm_isdst=isdst; /* date.tm_zone = NULL; */ - retval = mktime_zone("mktime", args, &date, + retval = mktime_zone(&date, args > 7 && SUBTYPEOF(Pike_sp[7-args]) == NUMBER_NUMBER, tz); diff --git a/src/builtin_functions.h b/src/builtin_functions.h index decb02ade0de976ffc285a8d8e00319da9f6b065..fd1c1b2abdfd7edb87100c6bf21ffcd3005b5b8d 100644 --- a/src/builtin_functions.h +++ b/src/builtin_functions.h @@ -7,6 +7,8 @@ #ifndef BUILTIN_EFUNS_H #define BUILTIN_EFUNS_H +#include "time_stuff.h" + #define TYPEP(ID,NAME,TYPE) PMOD_EXPORT void ID(INT32 args); #include "callback.h" @@ -124,8 +126,7 @@ PMOD_EXPORT void f__assembler_debug(INT32 args); PMOD_EXPORT void f__compiler_trace(INT32 args); PMOD_EXPORT void f_gmtime(INT32 args); PMOD_EXPORT void f_localtime(INT32 args); -time_t mktime_zone(const char*fname, int args, - struct tm*date, int other_timezone, int tz); +time_t mktime_zone(struct tm *date, int other_timezone, int tz); PMOD_EXPORT void f_mktime (INT32 args); PMOD_EXPORT void f_glob(INT32 args); PMOD_EXPORT void f_permute(INT32 args);