def date_sunrise_sunset(func_name, interp, num_args, timestamp, return_format, latitude, longitude, zenith, gmt_offset): sunrise = False if func_name == "date_sunrise": sunrise = True if return_format not in [SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, SUNFUNCS_RET_DOUBLE]: interp.space.ec.warn( "%s(): Wrong return format given, pick one of " "SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE" % func_name) return interp.space.w_False altitude = 90 - zenith 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, timestamp) c_h_rise = lltype.malloc(rffi.CArrayPtr(lltype.Float).TO, 1, flavor='raw') c_h_set = 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') rs = timelib.timelib_astro_rise_set_altitude( timelib_time, longitude, latitude, altitude, 1, c_h_rise, c_h_set, c_rise, c_set, c_transit ) if num_args <= 5: gmt_offset = float(timelib.timelib_get_current_offset(timelib_time) / 3600) timelib.timelib_time_dtor(timelib_time) if rs != 0: return interp.space.w_False if return_format == 0: return interp.space.wrap(c_rise[0] if sunrise else c_set[0]) N = (c_h_rise[0] if sunrise else c_h_set[0]) + gmt_offset if N > 24 or N < 0: N -= math.floor(N / 24) * 24 if return_format == 1: return interp.space.wrap("%s:%s" % ( timelib.format_to(2, int(math.floor(N))), timelib.format_to(2, int(math.floor(60 * (N - int(N))))) )) elif return_format == 2: return interp.space.wrap(N)
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)
def date_sunrise_sunset(func_name, interp, num_args, timestamp, return_format, latitude, longitude, zenith, gmt_offset): sunrise = False if func_name == "date_sunrise": sunrise = True if return_format not in [ SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING, SUNFUNCS_RET_DOUBLE ]: interp.space.ec.warn( "%s(): Wrong return format given, pick one of " "SUNFUNCS_RET_TIMESTAMP, SUNFUNCS_RET_STRING or SUNFUNCS_RET_DOUBLE" % func_name) return interp.space.w_False altitude = 90 - zenith 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, timestamp) c_h_rise = lltype.malloc(rffi.CArrayPtr(lltype.Float).TO, 1, flavor='raw') c_h_set = 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') rs = timelib.timelib_astro_rise_set_altitude(timelib_time, longitude, latitude, altitude, 1, c_h_rise, c_h_set, c_rise, c_set, c_transit) if num_args <= 5: gmt_offset = float( timelib.timelib_get_current_offset(timelib_time) / 3600) timelib.timelib_time_dtor(timelib_time) if rs != 0: return interp.space.w_False if return_format == 0: return interp.space.wrap(c_rise[0] if sunrise else c_set[0]) N = (c_h_rise[0] if sunrise else c_h_set[0]) + gmt_offset if N > 24 or N < 0: N -= math.floor(N / 24) * 24 if return_format == 1: return interp.space.wrap( "%s:%s" % (timelib.format_to(2, int(math.floor(N))), timelib.format_to(2, int(math.floor(60 * (N - int(N))))))) elif return_format == 2: return interp.space.wrap(N)
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)