def initialize_date(interp, func_name, this, time_string=None, w_datetimezone=None): from hippy.module.date.datetimezone_klass import W_DateTimeZone, k_DateTimeZone this.timelib_time, error = timelib.timelib_time_from_string(time_string) this.timelib_time.c_zone_type, this.timelib_time.c_tz_info zone_type = rffi.cast(lltype.Signed, this.timelib_time.c_zone_type) timezone_offset = None if w_datetimezone: timelib_timezone = w_datetimezone.timelib_timezone elif zone_type == timelib.ZONETYPE_ID: timelib_timezone = this.timelib_time.c_tz_info elif zone_type == timelib.ZONETYPE_ABBR: timelib_timezone = timelib.timelib_parse_tzfile( this.timelib_time.c_tz_abbr, timelib.timelib_builtin_db()) if not timelib_timezone: timelib_timezone = interp.get_default_timezone( func_name).timelib_timezone elif zone_type == timelib.ZONETYPE_OFFSET: timelib_timezone = lltype.nullptr(timelib.timelib_tzinfo.TO) offset = timelib.timelib_get_current_offset(this.timelib_time) / 36 mark = '+' if offset >= 0 else '' h, m = offset / 100, offset % 100 "%s%s:%s" % (mark, timelib.format_to(2, h), timelib.format_to(2, m)) timezone_offset = "%s%s:%s" % (mark, timelib.format_to( 2, h), timelib.format_to(2, m)) else: timelib_timezone = interp.get_default_timezone( func_name).timelib_timezone if timelib_timezone: now = timelib.timelib_time_ctor() now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID now.c_tz_info = timelib_timezone timelib.timelib_unixtime2local(now, int(time.time())) timelib.timelib_fill_holes(this.timelib_time, now, timelib.TIMELIB_NO_CLONE) timelib.timelib_update_ts(this.timelib_time, timelib_timezone) timelib.timelib_time_dtor(now) this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1) this.w_datetimezone = W_DateTimeZone(k_DateTimeZone, []) this.w_datetimezone.timezone_info = TimeZoneWrapper( timelib_timezone, zone_type, timezone_offset) return error
def initialize_date(interp, func_name, this, time_string=None, w_datetimezone=None): from hippy.module.date.datetimezone_klass import W_DateTimeZone, k_DateTimeZone this.timelib_time, error = timelib.timelib_time_from_string(time_string) this.timelib_time.c_zone_type, this.timelib_time.c_tz_info zone_type = rffi.cast(lltype.Signed, this.timelib_time.c_zone_type) timezone_offset = None if w_datetimezone: timelib_timezone = w_datetimezone.timelib_timezone elif zone_type == timelib.ZONETYPE_ID: timelib_timezone = this.timelib_time.c_tz_info elif zone_type == timelib.ZONETYPE_ABBR: timelib_timezone = timelib.timelib_parse_tzfile( this.timelib_time.c_tz_abbr, timelib.timelib_builtin_db() ) if not timelib_timezone: timelib_timezone = interp.get_default_timezone(func_name).timelib_timezone elif zone_type == timelib.ZONETYPE_OFFSET: timelib_timezone = lltype.nullptr(timelib.timelib_tzinfo.TO) offset = timelib.timelib_get_current_offset(this.timelib_time) / 36 mark = '+' if offset >= 0 else '' h, m = offset / 100, offset % 100 "%s%s:%s" % (mark, timelib.format_to(2, h), timelib.format_to(2, m)) timezone_offset = "%s%s:%s" % ( mark, timelib.format_to(2, h), timelib.format_to(2, m) ) else: timelib_timezone = interp.get_default_timezone(func_name).timelib_timezone if timelib_timezone: now = timelib.timelib_time_ctor() now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID now.c_tz_info = timelib_timezone timelib.timelib_unixtime2local(now, int(time.time())) timelib.timelib_fill_holes(this.timelib_time, now, timelib.TIMELIB_NO_CLONE) timelib.timelib_update_ts(this.timelib_time, timelib_timezone) timelib.timelib_time_dtor(now) this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1 ) this.w_datetimezone = W_DateTimeZone(k_DateTimeZone, []) this.w_datetimezone.timezone_info = TimeZoneWrapper( timelib_timezone, zone_type, timezone_offset ) return error
def initialize_timezone_info(tz_name): tzi = TimeZoneInfo(tz_name is None) with rffi.scoped_str2charp("UTC") as ll_s: ll_tzi = timelib.timelib_parse_tzfile( ll_s, timelib.timelib_builtin_db()) if not ll_tzi: raise Exception("failed to initialize timezone") tzi.timezone = tz_name tzi.utc_tzi = ll_tzi if tz_name is None: tzi.timezone = 'UTC' return tzi with rffi.scoped_str2charp(tz_name) as ll_s: ll_tzi = timelib.timelib_parse_tzfile( ll_s, timelib.timelib_builtin_db()) if not ll_tzi: raise Exception("failed to initialize timezone") tzi.local_tzi = ll_tzi return tzi
def initialize_timezone(interp, func_name, this, name, warning=False): this.timelib_timezone = timelib.timelib_parse_tzfile( rffi.str2charp(name), timelib.timelib_builtin_db()) if this.timelib_timezone == lltype.nullptr(timelib.timelib_tzinfo.TO): message = "%s(): Unknown or bad timezone (%s)" % (func_name, name) if warning: interp.space.ec.warn(message) else: raise PHPException( k_Exception.call_args(interp, [interp.space.wrap(message)])) return False return True
def initialize_timezone(interp, func_name, this, name, warning=False): this.timelib_timezone = timelib.timelib_parse_tzfile( rffi.str2charp(name), timelib.timelib_builtin_db() ) if this.timelib_timezone == lltype.nullptr(timelib.timelib_tzinfo.TO): message = "%s(): Unknown or bad timezone (%s)" % (func_name, name) if warning: interp.space.ec.warn(message) else: raise PHPException(k_Exception.call_args( interp, [interp.space.wrap(message)] )) return False return True