Beispiel #1
0
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;
}
Beispiel #2
0
static timelib_sll do_adjust_timezone(timelib_time *tz, timelib_tzinfo *tzi)
{
	switch (tz->zone_type) {
		case TIMELIB_ZONETYPE_OFFSET:

			tz->is_localtime = 1;
			return tz->z * 60;
			break;

		case TIMELIB_ZONETYPE_ABBR: {
			timelib_sll tmp;

			tz->is_localtime = 1;
			tmp = tz->z;
			tmp -= tz->dst * 60;
			tmp *= 60;
			return tmp;
			}
			break;

		case TIMELIB_ZONETYPE_ID:
			tzi = tz->tz_info;
			/* Break intentionally missing */

		default:
			/* No timezone in struct, fallback to reference if possible */
			if (tzi) {
				timelib_time_offset *before, *after;
				timelib_sll          tmp;
				int                  in_transistion;
				
				tz->is_localtime = 1;
				before = timelib_get_time_zone_info(tz->sse, tzi);
				after = timelib_get_time_zone_info(tz->sse - before->offset, tzi);
				timelib_set_timezone(tz, tzi);

				in_transistion = (
					((tz->sse - after->offset) >= (after->transistion_time + (before->offset - after->offset))) &&
					((tz->sse - after->offset) < after->transistion_time)
				);
				
				if ((before->offset != after->offset) && !in_transistion) {
					tmp = -after->offset;
				} else {
					tmp = -tz->z;
				}
				timelib_time_offset_dtor(before);
				timelib_time_offset_dtor(after);
				
				return tmp;
			}
	}
	return 0;
}