static int get_rise_set(date_t todayGreg, double *h_rise, double *h_set, double *gmt_offset) { double latitude, longitude; timelib_sll rise, set, transit; int rs; timelib_time *t; latitude = (double) latdeg + (latmin / 60.0); longitude = (longdeg * -1.0) + ((longmin * -1.0) / 60.0); t = timelib_time_ctor(); t->y = todayGreg.yy; t->m = todayGreg.mm; t->d = todayGreg.dd; t->h = 17; /* assume 5pm */ timelib_set_timezone(t, TZ_INFO); /* t->tz_info = TZ_INFO; */ /* t->zone_type = TIMELIB_ZONETYPE_ID; */ /* t->is_localtime = 1; */ /* t->have_zone = 1; */ timelib_update_ts(t, TZ_INFO); *gmt_offset = timelib_get_current_offset(t) / 3600.0; rs = timelib_astro_rise_set_altitude(t, longitude, latitude, SUNRISE_SUNSET_ALTITUDE, 1, h_rise, h_set, &rise, &set, &transit); timelib_time_dtor(t); return rs; }
int main(int argc, char *argv[]) { timelib_time *t; timelib_sll rise, set, transit; int rs, h, m, s; double h_rise, h_set; if (argc != 4) { printf("Usage: ./test-astro time longitude latitude\n ./test-astro \"2005-10-17 00:00:00\" 9.627 59.186\n"); return -1; } t = timelib_strtotime(argv[1] /*"2005-10-17 00:00:00"*/, strlen(argv[1]), NULL, timelib_builtin_db(), timelib_parse_tzfile); timelib_dump_date(t, 1); rs = timelib_astro_rise_set_altitude(t, atof(argv[2]) /*9.627*/, atof(argv[3]) /*59.186*/, 0, 0, &h_rise, &h_set, &rise, &set, &transit); switch (rs) { case 0: break; case +1: printf( "Sun always above horizon\n"); break; case -1: printf( "Sun always below horizon\n"); break; } timelib_unixtime2local(t, rise); timelib_dump_date(t, 1); timelib_decimal_hour_to_hms(h_rise, &h, &m, &s); timelib_unixtime2local(t, set); timelib_dump_date(t, 1); timelib_decimal_hour_to_hms(h_set, &h, &m, &s); if (t->tz_info) { timelib_tzinfo_dtor(t->tz_info); } timelib_time_dtor(t); return 0; }