def date_addsub(interp, this, datetime_interval, sign): if rffi.cast(lltype.Signed, datetime_interval.time_diff.c_invert): sign *= -1 this.timelib_time.c_relative.c_y += datetime_interval.time_diff.c_y * sign this.timelib_time.c_relative.c_m += datetime_interval.time_diff.c_m * sign this.timelib_time.c_relative.c_d += datetime_interval.time_diff.c_d * sign this.timelib_time.c_relative.c_h += datetime_interval.time_diff.c_h * sign this.timelib_time.c_relative.c_i += datetime_interval.time_diff.c_i * sign this.timelib_time.c_relative.c_s += datetime_interval.time_diff.c_s * sign this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1) this.timelib_time.c_sse_uptodate = rffi.cast( timelib.timelib_time.TO.c_sse_uptodate, 0) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) timelib.timelib_update_from_sse(this.timelib_time) this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 0) this.timelib_time.c_relative.c_y = 0 this.timelib_time.c_relative.c_m = 0 this.timelib_time.c_relative.c_d = 0 this.timelib_time.c_relative.c_h = 0 this.timelib_time.c_relative.c_i = 0 this.timelib_time.c_relative.c_s = 0
def set_timestamp(interp, this, timestamp): timelib.timelib_unixtime2local(this.timelib_time, timestamp) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this
def _mktime(interp, is_gmt, hour, minute, second, month, day, year, dst=-1): now = timelib.timelib_time_ctor() adjust_seconds = 0 if is_gmt: timelib.timelib_unixtime2gmt(now, int(pytime.time())) else: now.c_tz_info = interp.get_default_timezone("mktime").timelib_timezone now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID timelib.timelib_unixtime2local(now, int(pytime.time())) if year >= 0 and year < 70: year += 2000 elif year >= 70 and year <= 100: year += 1900 now.c_y = rffi.cast(lltype.Signed, year) now.c_d = rffi.cast(lltype.Signed, day) now.c_m = rffi.cast(lltype.Signed, month) now.c_s = rffi.cast(lltype.Signed, second) now.c_i = rffi.cast(lltype.Signed, minute) now.c_h = rffi.cast(lltype.Signed, hour) if is_gmt: timelib.timelib_update_ts(now, lltype.nullptr(timelib.timelib_tzinfo.TO)) else: timelib.timelib_update_ts( now, interp.get_default_timezone("mktime").timelib_timezone) if dst != -1: interp.space.ec.deprecated( "mktime(): The is_dst parameter is deprecated") if is_gmt: if dst == 1: adjust_seconds -= 3600 else: tmp_offset = timelib.timelib_get_time_zone_info( now.c_sse, interp.get_default_timezone("mktime").timelib_timezone) if dst == 1 and intmask(tmp_offset.c_is_dst) == 0: adjust_seconds -= 3600 if dst == 0 and intmask(tmp_offset.c_is_dst) == 1: adjust_seconds += 3600 timelib.timelib_time_offset_dtor(tmp_offset) error = lltype.malloc(rffi.CArrayPtr(lltype.Signed).TO, 1, flavor='raw', zero=True) timestamp = timelib.timelib_date_to_int(now, error) timestamp += adjust_seconds timelib.timelib_time_dtor(now) lltype.free(error, flavor='raw') return timestamp
def date_addsub(interp, this, datetime_interval, sign): if rffi.cast(lltype.Signed, datetime_interval.time_diff.c_invert): sign *= -1 this.timelib_time.c_relative.c_y += datetime_interval.time_diff.c_y * sign this.timelib_time.c_relative.c_m += datetime_interval.time_diff.c_m * sign this.timelib_time.c_relative.c_d += datetime_interval.time_diff.c_d * sign this.timelib_time.c_relative.c_h += datetime_interval.time_diff.c_h * sign this.timelib_time.c_relative.c_i += datetime_interval.time_diff.c_i * sign this.timelib_time.c_relative.c_s += datetime_interval.time_diff.c_s * sign this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1 ) this.timelib_time.c_sse_uptodate = rffi.cast( timelib.timelib_time.TO.c_sse_uptodate, 0 ) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) timelib.timelib_update_from_sse(this.timelib_time) this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 0 ) this.timelib_time.c_relative.c_y = 0 this.timelib_time.c_relative.c_m = 0 this.timelib_time.c_relative.c_d = 0 this.timelib_time.c_relative.c_h = 0 this.timelib_time.c_relative.c_i = 0 this.timelib_time.c_relative.c_s = 0
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_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 set_time(interp, this, hour, minute, second=0): this.timelib_time.c_h = hour this.timelib_time.c_i = minute this.timelib_time.c_s = second timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this
def set_date(interp, this, year, month, day): this.timelib_time.c_y = year this.timelib_time.c_m = month this.timelib_time.c_d = day timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this
def date_time_set(interp, date, hour, minute, second=0): date.timelib_time.c_h = hour date.timelib_time.c_i = minute date.timelib_time.c_s = second timelib.timelib_update_ts(date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return date
def date_date_set(interp, date, year, month, day): date.timelib_time.c_y = year date.timelib_time.c_m = month date.timelib_time.c_d = day timelib.timelib_update_ts(date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return date
def date_time_set(interp, date, hour, minute, second=0): date.timelib_time.c_h = hour date.timelib_time.c_i = minute date.timelib_time.c_s = second timelib.timelib_update_ts( date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO) ) return date
def set_iso_date(interp, this, year, week, day=1): this.timelib_time.c_y = year this.timelib_time.c_m = 1 this.timelib_time.c_d = 1 this.timelib_time.c_relative.c_d = timelib.timelib_daynr_from_weeknr(year, week, day) this.timelib_time.c_have_relative = rffi.cast(timelib.timelib_time.TO.c_have_relative, 1) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this
def date_date_set(interp, date, year, month, day): date.timelib_time.c_y = year date.timelib_time.c_m = month date.timelib_time.c_d = day timelib.timelib_update_ts( date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO) ) return date
def diff(interp, this, w_datetime, absolute=False): null_ptr = lltype.nullptr(timelib.timelib_tzinfo.TO) timelib.timelib_update_ts(this.timelib_time, null_ptr) timelib.timelib_update_ts(w_datetime.timelib_time, null_ptr) interval = W_DateInterval(k_DateInterval, []) interval.time_diff = timelib.timelib_diff(this.timelib_time, w_datetime.timelib_time) if absolute: interval.time_diff.c_invert = rffi.cast(rffi.INT, 0) return interval
def date_isodate_set(interp, date, year, week, day=1): date.timelib_time.c_y = year date.timelib_time.c_m = 1 date.timelib_time.c_d = 1 date.timelib_time.c_relative.c_d = timelib.timelib_daynr_from_weeknr( year, week, day) date.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1) timelib.timelib_update_ts(date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return date
def set_iso_date(interp, this, year, week, day=1): this.timelib_time.c_y = year this.timelib_time.c_m = 1 this.timelib_time.c_d = 1 this.timelib_time.c_relative.c_d = timelib.timelib_daynr_from_weeknr( year, week, day) this.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1) timelib.timelib_update_ts(this.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO)) return this
def date_isodate_set(interp, date, year, week, day=1): date.timelib_time.c_y = year date.timelib_time.c_m = 1 date.timelib_time.c_d = 1 date.timelib_time.c_relative.c_d = timelib.timelib_daynr_from_weeknr(year, week, day) date.timelib_time.c_have_relative = rffi.cast( timelib.timelib_time.TO.c_have_relative, 1 ) timelib.timelib_update_ts( date.timelib_time, lltype.nullptr(timelib.timelib_tzinfo.TO) ) return date
def _mktime(interp, is_gmt, hour, minute, second, month, day, year, dst=-1): now = timelib.timelib_time_ctor() adjust_seconds = 0 if is_gmt: timelib.timelib_unixtime2gmt(now, int(pytime.time())) else: now.c_tz_info = interp.get_default_timezone("mktime").timelib_timezone now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID timelib.timelib_unixtime2local(now, int(pytime.time())) if year >= 0 and year < 70: year += 2000 elif year >= 70 and year <= 100: year += 1900 now.c_y = rffi.cast(lltype.Signed, year) now.c_d = rffi.cast(lltype.Signed, day) now.c_m = rffi.cast(lltype.Signed, month) now.c_s = rffi.cast(lltype.Signed, second) now.c_i = rffi.cast(lltype.Signed, minute) now.c_h = rffi.cast(lltype.Signed, hour) if is_gmt: timelib.timelib_update_ts( now, lltype.nullptr(timelib.timelib_tzinfo.TO)) else: timelib.timelib_update_ts( now, interp.get_default_timezone("mktime").timelib_timezone) if dst != -1: interp.space.ec.deprecated( "mktime(): The is_dst parameter is deprecated" ) if is_gmt: if dst == 1: adjust_seconds -= 3600 else: tmp_offset = timelib.timelib_get_time_zone_info( now.c_sse, interp.get_default_timezone("mktime").timelib_timezone ) if dst == 1 and intmask(tmp_offset.c_is_dst) == 0: adjust_seconds -= 3600 if dst == 0 and intmask(tmp_offset.c_is_dst) == 1: adjust_seconds += 3600 timelib.timelib_time_offset_dtor(tmp_offset) error = lltype.malloc( rffi.CArrayPtr(lltype.Signed).TO, 1, flavor='raw', zero=True ) timestamp = timelib.timelib_date_to_int(now, error) timestamp += adjust_seconds timelib.timelib_time_dtor(now) lltype.free(error, flavor='raw') return timestamp