Example #1
0
def initialize_date(interp, func_name, this, time_string=None, w_datetimezone=None):

    if not w_datetimezone:
        this.timezone = interp.get_default_timezone(func_name)
    else:
        this.timezone = w_datetimezone

    this.timelib_time, error = timelib.timelib_time_from_string(time_string)

    now = timelib.timelib_time_ctor()
    now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID
    now.c_tz_info = this.timezone.timelib_timezone
    zone_type = rffi.cast(lltype.Signed, this.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(this.timelib_time, now, timelib.TIMELIB_NO_CLONE)
    timelib.timelib_update_ts(this.timelib_time, this.timezone.timelib_timezone)
    timelib.timelib_time_dtor(now)

    this.timelib_time.c_have_relative = rffi.cast(
        timelib.timelib_time.TO.c_have_relative, 1
    )

    return error
Example #2
0
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
Example #3
0
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
Example #4
0
def initialize_date(interp,
                    func_name,
                    this,
                    time_string=None,
                    w_datetimezone=None):

    if not w_datetimezone:
        this.timezone = interp.get_default_timezone(func_name)
    else:
        this.timezone = w_datetimezone

    this.timelib_time, error = timelib.timelib_time_from_string(time_string)

    now = timelib.timelib_time_ctor()
    now.c_zone_type = timelib.TIMELIB_ZONETYPE_ID
    now.c_tz_info = this.timezone.timelib_timezone
    zone_type = rffi.cast(lltype.Signed, this.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(this.timelib_time, now,
                               timelib.TIMELIB_NO_CLONE)
    timelib.timelib_update_ts(this.timelib_time,
                              this.timezone.timelib_timezone)
    timelib.timelib_time_dtor(now)

    this.timelib_time.c_have_relative = rffi.cast(
        timelib.timelib_time.TO.c_have_relative, 1)

    return error
Example #5
0
def date_parse(interp, time_string):
    timelib_time, error = timelib.timelib_time_from_string(time_string)
    return _date_parse(interp.space, timelib_time, error)