예제 #1
0
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
예제 #2
0
def date_timestamp_get(interp, w_datetime):
    error = lltype.malloc(
        rffi.CArrayPtr(lltype.Signed).TO, 1, flavor='raw', zero=True
    )

    timestamp = timelib.timelib_date_to_int(w_datetime.timelib_time, error)

    lltype.free(error, flavor='raw')
    return interp.space.wrap(timestamp)
예제 #3
0
def date_timestamp_get(interp, w_datetime):
    error = lltype.malloc(rffi.CArrayPtr(lltype.Signed).TO,
                          1,
                          flavor='raw',
                          zero=True)

    timestamp = timelib.timelib_date_to_int(w_datetime.timelib_time, error)

    lltype.free(error, flavor='raw')
    return interp.space.wrap(timestamp)
예제 #4
0
def date_sun_info(interp, time, latitude, longitude):

    space = interp.space

    timelib_time = timelib.timelib_time_ctor()
    timelib_timezone = interp.get_default_timezone("date").timelib_timezone

    timelib_time.c_tz_info = timelib_timezone
    timelib_time.c_zone_type = timelib.TIMELIB_ZONETYPE_ID

    timelib.timelib_unixtime2local(timelib_time, time)

    timelib_time_2 = timelib.timelib_time_ctor()

    dummy = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    ddummy = lltype.malloc(rffi.CArrayPtr(lltype.Float).TO, 1, flavor='raw')
    c_rise = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    c_set = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    c_transit = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO,
                              1,
                              flavor='raw')

    ret_val = []

    # Get sun up/down and transit
    rs = timelib.timelib_astro_rise_set_altitude(timelib_time, longitude,
                                                 latitude, -35.0 / 60, 1,
                                                 ddummy, ddummy, c_rise, c_set,
                                                 c_transit)

    if rs == -1:
        ret_val.append((space.wrap("sunrise"), space.w_False))
        ret_val.append((space.wrap("sunset"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("sunrise"), space.w_True))
        ret_val.append((space.wrap("sunset"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append(
            (space.wrap("sunrise"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append(
            (space.wrap("sunset"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))

    timelib_time_2.c_sse = c_transit[0]
    ret_val.append(
        (space.wrap("transit"),
         space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))

    # Get civil twilight
    rs = timelib.timelib_astro_rise_set_altitude(timelib_time, longitude,
                                                 latitude, -6.0, 0, ddummy,
                                                 ddummy, c_rise, c_set,
                                                 c_transit)

    if rs == -1:
        ret_val.append((space.wrap("civil_twilight_begin"), space.w_False))
        ret_val.append((space.wrap("civil_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("civil_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("civil_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append(
            (space.wrap("civil_twilight_begin"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append(
            (space.wrap("civil_twilight_end"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))

    # Get nautical twilight
    rs = timelib.timelib_astro_rise_set_altitude(timelib_time, longitude,
                                                 latitude, -12.0, 0, ddummy,
                                                 ddummy, c_rise, c_set,
                                                 c_transit)

    if rs == -1:
        ret_val.append((space.wrap("nautical_twilight_begin"), space.w_False))
        ret_val.append((space.wrap("nautical_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("nautical_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("nautical_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append(
            (space.wrap("nautical_twilight_begin"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append(
            (space.wrap("nautical_twilight_end"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))

    # Get astronomical twilight
    rs = timelib.timelib_astro_rise_set_altitude(timelib_time, longitude,
                                                 latitude, -18.0, 0, ddummy,
                                                 ddummy, c_rise, c_set,
                                                 c_transit)

    if rs == -1:
        ret_val.append(
            (space.wrap("astronomical_twilight_begin"), space.w_False))
        ret_val.append(
            (space.wrap("astronomical_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append(
            (space.wrap("astronomical_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("astronomical_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append(
            (space.wrap("astronomical_twilight_begin"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append(
            (space.wrap("astronomical_twilight_end"),
             space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))))

    timelib.timelib_time_dtor(timelib_time)
    timelib.timelib_time_dtor(timelib_time_2)

    return space.new_array_from_pairs(ret_val)
예제 #5
0
파일: funcs.py 프로젝트: LewisGet/hippyvm
def date_sun_info(interp, time, latitude, longitude):

    space = interp.space

    timelib_time = timelib.timelib_time_ctor()
    timelib_timezone = interp.get_default_timezone("date").timelib_timezone

    timelib_time.c_tz_info = timelib_timezone
    timelib_time.c_zone_type = timelib.TIMELIB_ZONETYPE_ID

    timelib.timelib_unixtime2local(timelib_time, time)

    timelib_time_2 = timelib.timelib_time_ctor()

    dummy = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    ddummy = lltype.malloc(rffi.CArrayPtr(lltype.Float).TO, 1, flavor='raw')
    c_rise = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    c_set = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')
    c_transit = lltype.malloc(rffi.CArrayPtr(rffi.LONGLONG).TO, 1, flavor='raw')

    ret_val = []

    # Get sun up/down and transit
    rs = timelib.timelib_astro_rise_set_altitude(
        timelib_time,
        longitude, latitude,
        -35.0/60, 1,
        ddummy, ddummy, c_rise, c_set, c_transit
    )

    if rs == -1:
        ret_val.append((space.wrap("sunrise"), space.w_False))
        ret_val.append((space.wrap("sunset"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("sunrise"), space.w_True))
        ret_val.append((space.wrap("sunset"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append((
            space.wrap("sunrise"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append((
            space.wrap("sunset"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))

    timelib_time_2.c_sse = c_transit[0]
    ret_val.append((
            space.wrap("transit"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))

    # Get civil twilight
    rs = timelib.timelib_astro_rise_set_altitude(
        timelib_time,
        longitude, latitude,
        -6.0, 0,
        ddummy, ddummy, c_rise, c_set, c_transit
    )

    if rs == -1:
        ret_val.append((space.wrap("civil_twilight_begin"), space.w_False))
        ret_val.append((space.wrap("civil_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("civil_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("civil_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append((
            space.wrap("civil_twilight_begin"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append((
            space.wrap("civil_twilight_end"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))


    # Get nautical twilight
    rs = timelib.timelib_astro_rise_set_altitude(
        timelib_time,
        longitude, latitude,
        -12.0, 0,
        ddummy, ddummy, c_rise, c_set, c_transit
    )

    if rs == -1:
        ret_val.append((space.wrap("nautical_twilight_begin"), space.w_False))
        ret_val.append((space.wrap("nautical_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("nautical_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("nautical_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append((
            space.wrap("nautical_twilight_begin"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append((
            space.wrap("nautical_twilight_end"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))

    # Get astronomical twilight
    rs = timelib.timelib_astro_rise_set_altitude(
        timelib_time,
        longitude, latitude,
        -18.0, 0,
        ddummy, ddummy, c_rise, c_set, c_transit
    )

    if rs == -1:
        ret_val.append((space.wrap("astronomical_twilight_begin"), space.w_False))
        ret_val.append((space.wrap("astronomical_twilight_end"), space.w_False))
    elif rs == 1:
        ret_val.append((space.wrap("astronomical_twilight_begin"), space.w_True))
        ret_val.append((space.wrap("astronomical_twilight_end"), space.w_True))
    else:
        timelib_time_2.c_sse = c_rise[0]
        ret_val.append((
            space.wrap("astronomical_twilight_begin"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))
        timelib_time_2.c_sse = c_set[0]
        ret_val.append((
            space.wrap("astronomical_twilight_end"),
            space.wrap(timelib.timelib_date_to_int(timelib_time_2, dummy))
        ))

    timelib.timelib_time_dtor(timelib_time)
    timelib.timelib_time_dtor(timelib_time_2)

    return space.new_array_from_pairs(ret_val)
예제 #6
0
파일: funcs.py 프로젝트: LewisGet/hippyvm
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