pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:407:
*! Return a string representing the time. Mostly useful for debug *! purposes, the exact format is very locale (see *! @[Gettext.setlocale]) and OS dependent. */ PIKEFUN string asctime() { FIX_THIS(); { #define STRFTIME_MAXSIZE 26 char s[STRFTIME_MAXSIZE];
-
if( !strftime(s, STRFTIME_MAXSIZE, "%
c
", &THIS->t) )
+
if( !strftime(s, STRFTIME_MAXSIZE, "%
c\n
", &THIS->t) )
push_undefined(); else push_text(s); } } PIKEFUN string _sprintf( int flag, mapping options ) {
-
int post_sum =
1
;
+
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)) )
pike.git/src/builtin.cmod:514:
*! Initialize the struct tm to the local time for the specified *! unix time_t. */ PIKEFUN int(0..1) localtime( int _t ) { time_t t = _t; struct tm *res = localtime_zone( &t, &THIS->t ); if( !res ) RETURN 0;
-
/* These are supposedly correctly by localtime_zone. */
-
SET_GMTOFF(res, GET_GMTOFF(&(THIS->t)));
-
SET_ZONE(res, GET_ZONE(&(THIS->t)));
-
+
THIS->t = *res; THIS->modified = 1; RETURN 1; } /*! @decl int(0..1) gmtime( int time ) *! Initialize the struct tm to the UTC time for the specified *! unix time_t. */ 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 */
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:575:
*! int(0..24) hour, int(0..59) min, int(0..59) sec, @ *! string|void timezone ) *! Construct a new time using the given values. *! Slightly faster than setting them individually. */ PIKEFUN void create( int year, int(0..11) mon, int(1..31) mday, int(0..24) hour, int(0..59) min, int(0..59) sec, string|void timezone ) { struct tm *t = &THIS->t;
-
t->tm_isdst = -1;
+
int use_utc = !timezone || !strcmp(timezone->str, "UTC");
+
t->tm_isdst =
use_utc ? 0 :
-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;
-
+
t->tm_wday = -1; /* Conversion valid flag */
if (THIS->set_zone) { free_string(THIS->set_zone); THIS->set_zone = NULL; }
-
if(
!timezone
) /*
gmtime.
*/
+
THIS->unix_time = mktime_zone( t );
+
if
(
t->tm_wday
<
0
)
+
Pike_error("Invalid time conversion\n");
+
/*
Setting
it to other timezones than UTC is not supported (yet)
*/
+
if (use_utc) {
SET_ZONE(t, "UTC");
-
else
-
{
-
add_ref(timezone);
-
THIS->
set
_
zone
=
timezone;
-
SET
_
ZONE
(t
, timezone->str
);
+
THIS->
unix
_
time
+
=
GET
_
GMTOFF
(t);
}
-
THIS->unix_time = mktime_zone( t );
+
} #ifdef PIKE_NULL_IS_SPECIAL INIT { THIS->set_zone = 0; THIS->modified = 0; } #endif EXIT