def initialize_date_from_format(interp, func_name, w_date, format_string, time_string, w_datetimezone): if not w_datetimezone: w_date.timezone = interp.get_default_timezone(func_name) else: w_date.timezone = w_datetimezone w_date.timelib_time, error = timelib.timelib_time_from_format( format_string, time_string ) now = timelib.timelib_time_ctor() now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID now.c_tz_info = w_date.timezone.timelib_timezone zone_type = rffi.cast(lltype.Signed, w_date.timelib_time.c_zone_type) if zone_type == timelib.ZONETYPE_ID: pass elif zone_type == timelib.ZONETYPE_ABBR: pass elif zone_type == timelib.ZONETYPE_OFFSET: pass timelib.timelib_unixtime2local(now, int(time.time())) timelib.timelib_fill_holes(w_date.timelib_time, now, timelib.TIMELIB_NO_CLONE) timelib.timelib_update_ts(w_date.timelib_time, w_date.timezone.timelib_timezone) timelib.timelib_time_dtor(now) w_date.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1 ) return error
def initialize_date_from_format(interp, func_name, w_date, format_string, time_string, w_datetimezone): if not w_datetimezone: w_date.timezone = interp.get_default_timezone(func_name) else: w_date.timezone = w_datetimezone w_date.timelib_time, error = timelib.timelib_time_from_format( format_string, time_string) now = timelib.timelib_time_ctor() now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID now.c_tz_info = w_date.timezone.timelib_timezone zone_type = rffi.cast(lltype.Signed, w_date.timelib_time.c_zone_type) if zone_type == timelib.ZONETYPE_ID: pass elif zone_type == timelib.ZONETYPE_ABBR: pass elif zone_type == timelib.ZONETYPE_OFFSET: pass timelib.timelib_unixtime2local(now, int(time.time())) timelib.timelib_fill_holes(w_date.timelib_time, now, timelib.TIMELIB_NO_CLONE) timelib.timelib_update_ts(w_date.timelib_time, w_date.timezone.timelib_timezone) timelib.timelib_time_dtor(now) w_date.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1) 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_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