pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:37:
#include <errno.h> #include <math.h> #include <fcntl.h> #ifdef HAVE_ARPA_INET_H #include <arpa/inet.h> #endif /* HAVE_ARPA_INET_H */ #define DEFAULT_CMOD_STORAGE
+
#ifdef STRUCT_TM_HAS___TM_GMTOFF
+
struct tm_extra { };
+
#define tm_zone __tm_zone
+
#define tm_gmtoff __tm_gmtoff
+
#define GET_GMTOFF(TM) ((TM)->tm_gmtoff)
+
#define GET_ZONE(this) ((this)->t.tm_zone)
+
#define SET_GMTOFF(TM, VAL) (((TM)->tm_gmtoff) = (VAL))
+
#define SET_ZONE(this, VAL) ((this)->t.tm_zone = (VAL))
+
#elif defined(STRUCT_TM_HAS_GMTOFF)
+
struct tm_extra { };
+
#define GET_GMTOFF(TM) ((TM)->tm_gmtoff)
+
#define GET_ZONE(this) ((this)->t.tm_zone)
+
#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; };
+
#define GET_GMTOFF(TM) 0
+
#define GET_ZONE(this) ((this)->extra.tm_zone)
+
#define SET_GMTOFF(TM, VAL) (VAL)
+
#define SET_ZONE(this, VAL) ((this)->extra.tm_zone = (VAL))
+
#endif
+
DECLARATIONS
-
+
/*! @module System */ /*! @class TM *! A wrapper for the system struct tm time keeping structure. *! This can be used as a (very) lightweight alternative to Calendar. */ 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;
-
#ifdef STRUCT_TM_HAS___TM_GMTOFF
-
#define tm_zone __tm_zone
-
#define tm_gmtoff __tm_gmtoff
-
#define GET_GMTOFF(TM) ((TM)->tm_gmtoff)
-
#define GET_ZONE(TM) ((TM)->tm_zone)
-
#define SET_GMTOFF(TM, VAL) (((TM)->tm_gmtoff) = (VAL))
-
#define SET_ZONE(TM, VAL) (((TM)->tm_zone) = (VAL))
-
#elif defined(STRUCT_TM_HAS_GMTOFF)
-
#define GET_GMTOFF(TM) ((TM)->tm_gmtoff)
-
#define GET_ZONE(TM) ((TM)->tm_zone)
-
#define SET_GMTOFF(TM, VAL) (((TM)->tm_gmtoff) = (VAL))
-
#define SET_ZONE(TM, VAL) (((TM)->tm_zone) = (VAL))
-
#else
-
#define GET_GMTOFF(TM) 0
-
#define GET_ZONE(TM) ((char*)NULL)
-
#define SET_GMTOFF(TM, VAL) (VAL)
-
#define SET_ZONE(TM, VAL) (VAL)
-
#endif
-
+
#define strftime_zone strftime #define strptime_zone strptime #define localtime_zone(X,Y) localtime(X) #ifndef HAVE_EXTERNAL_TIMEZONE #undef timezone #endif #define MODIFY(X) do{ THIS->modified = 1;THIS->t.X; }while(0) #define FIX_THIS(fname) do { \ if(THIS->modified) \ fix_tm(fname, args, THIS); \ } while(0) static void fix_tm(const char*fname, int args, struct TM_struct*this) {
-
const char*tm_zone = GET_ZONE(
&
this
->t
);
+
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; } #ifdef HAVE_STRPTIME /*! @decl int(0..1) strptime( string(1..255) format, string(1..255) data ) *!
pike.git/src/builtin.cmod:433:
int post_sum = 0; switch( flag ) { case 'O': push_static_text("System.TM("); post_sum = 1; /* fallthrough */ case 's': f_TM_asctime(0); push_static_text("\n");
-
if( GET_ZONE(
&(
THIS
->t
)
)
)
+
if( GET_ZONE(THIS) )
{ push_static_text(" ");
-
push_text( GET_ZONE(
&(
THIS
->t
)
)
);
+
push_text( GET_ZONE(THIS) );
f_add( 2 ); } else push_static_text(""); f_replace( 3 ); break; case 'd': f_TM_unix_time(0); break; default:
pike.git/src/builtin.cmod:486:
pop_stack(); push_undefined(); } /*! @decl string zone *! *! The timezone of this structure */ PIKEFUN string `zone() { FIX_THIS("zone");
-
if( GET_ZONE(
&(
THIS
->t
)
)
)
-
push_text( GET_ZONE(
&(
THIS
->t
)
)
);
+
if( GET_ZONE(THIS) )
+
push_text( GET_ZONE(THIS) );
else push_undefined(); } /*! @decl int gmtoff *! The offset from GMT for the time in this tm-struct */ PIKEFUN int `gmtoff() { FIX_THIS("gmtoff"); push_int( GET_GMTOFF(&(THIS->t)) );
pike.git/src/builtin.cmod:540:
*/ PIKEFUN int(0..1) gmtime( int _t ) { time_t t = _t; struct tm *res = gmtime( &t ); if( !res ) RETURN 0; THIS->t = *res;
-
SET_ZONE(
&
THIS
->t
, "UTC");
/* Override timezone */
+
SET_ZONE(THIS, "UTC"); /* Override timezone */
THIS->modified = 1; RETURN 1; } /*! @decl void create(int t) *! Create a new @[TM] initialized from a unix time_t. *! The timezone will always be UTC when using this function. */ PIKEFUN void create( int _t ) {
pike.git/src/builtin.cmod:602:
} 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); /* Setting it to other timezones than UTC is not supported (yet) */ if (use_utc)
-
SET_ZONE(
t
, "UTC");
+
SET_ZONE(
THIS
, "UTC");
} #ifdef PIKE_NULL_IS_SPECIAL INIT { THIS->set_zone = 0; THIS->modified = 0; } #endif EXIT