Esempio n. 1
0
static void do_normalize(timelib_time* time)
{
	do {} while (do_range_limit(0, 60, 60, &time->s, &time->i));
	do {} while (do_range_limit(0, 60, 60, &time->i, &time->h));
	do {} while (do_range_limit(0, 24, 24, &time->h, &time->d));
	do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));

	do {} while (do_range_limit_days(&time->y, &time->m, &time->d));
	do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));
}
Esempio n. 2
0
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
{
	do {} while (do_range_limit(0, 60, 60, &rt->s, &rt->i));
	do {} while (do_range_limit(0, 60, 60, &rt->i, &rt->h));
	do {} while (do_range_limit(0, 24, 24, &rt->h, &rt->d));
	do {} while (do_range_limit(0, 12, 12, &rt->m, &rt->y));

	do {} while (do_range_limit_days_relative(&base->y, &base->m, &rt->y, &rt->m, &rt->d));
	do {} while (do_range_limit(0, 12, 12, &rt->m, &rt->y));
}
Esempio n. 3
0
void timelib_do_normalize(timelib_time* time)
{
	if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 60, 60, &time->s, &time->i));
	if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 60, 60, &time->i, &time->h));
	if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 24, 24, &time->h, &time->d));
	do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));

	do {} while (do_range_limit_days(&time->y, &time->m, &time->d));
	do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));
}
Esempio n. 4
0
void timelib_do_rel_normalize(timelib_time *base, timelib_rel_time *rt)
{
	do_range_limit_fraction(&rt->us, &rt->s);
	do_range_limit(0, 60, 60, &rt->s, &rt->i);
	do_range_limit(0, 60, 60, &rt->i, &rt->h);
	do_range_limit(0, 24, 24, &rt->h, &rt->d);
	do_range_limit(0, 12, 12, &rt->m, &rt->y);

	do_range_limit_days_relative(&base->y, &base->m, &rt->y, &rt->m, &rt->d, rt->invert);
	do_range_limit(0, 12, 12, &rt->m, &rt->y);
}
Esempio n. 5
0
static int do_range_limit_days_relative(timelib_sll *base_y, timelib_sll *base_m, timelib_sll *y, timelib_sll *m, timelib_sll *d)
{
	timelib_sll leapyear;
	timelib_sll days_this_month;
	timelib_sll next_month, next_year;
	timelib_sll days_next_month;

	do_range_limit(1, 13, 12, base_m, base_y);

	leapyear = timelib_is_leap(*base_y);
	days_this_month = leapyear ? days_in_month_leap[*base_m] : days_in_month[*base_m];
	next_month = (*base_m) + 1;

	if (next_month > 12) {
		next_month -= 12;
		next_year = (*base_y) + 1;
	} else {
		next_year = (*base_y);
	}
	leapyear = timelib_is_leap(next_year);
	days_next_month = leapyear ? days_in_month_leap[next_month] : days_in_month[next_month];

	if (*d < 0) {
		*d += days_this_month;
		(*m)--;
		return 1;
	}
	if (*d > days_next_month) {
		*d -= days_next_month;
		(*m)++;
		return 1;
	}
	return 0;
}
Esempio n. 6
0
void timelib_do_normalize(timelib_time* time)
{
	if (time->us != TIMELIB_UNSET) do_range_limit_fraction(&time->us, &time->s);
	if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->s, &time->i);
	if (time->s != TIMELIB_UNSET) do_range_limit(0, 60, 60, &time->i, &time->h);
	if (time->s != TIMELIB_UNSET) do_range_limit(0, 24, 24, &time->h, &time->d);
	do_range_limit(1, 13, 12, &time->m, &time->y);

	/* Short cut if we're doing things against the Epoch */
	if (time->y == 1970 && time->m == 1 && time->d != 1) {
		magic_date_calc(time);
	}

	do {} while (do_range_limit_days(&time->y, &time->m, &time->d));
	do_range_limit(1, 13, 12, &time->m, &time->y);
}
Esempio n. 7
0
static void do_range_limit_days_relative(timelib_sll *base_y, timelib_sll *base_m, timelib_sll *y, timelib_sll *m, timelib_sll *d, timelib_sll invert)
{
	timelib_sll leapyear;
	timelib_sll month, year;
	timelib_sll days;

	do_range_limit(1, 13, 12, base_m, base_y);

	year = *base_y;
	month = *base_m;

/*
	printf( "S: Y%d M%d   %d %d %d   %d\n", year, month, *y, *m, *d, days);
*/
	if (!invert) {
		while (*d < 0) {
			dec_month(&year, &month);
			leapyear = timelib_is_leap(year);
			days = leapyear ? days_in_month_leap[month] : days_in_month[month];

			/* printf( "I  Y%d M%d   %d %d %d   %d\n", year, month, *y, *m, *d, days); */

			*d += days;
			(*m)--;
		}
	} else {
		while (*d < 0) {
			leapyear = timelib_is_leap(year);
			days = leapyear ? days_in_month_leap[month] : days_in_month[month];

			/* printf( "I  Y%d M%d   %d %d %d   %d\n", year, month, *y, *m, *d, days); */

			*d += days;
			(*m)--;
			inc_month(&year, &month);
		}
	}
	/*
	printf( "E: Y%d M%d   %d %d %d   %d\n", year, month, *y, *m, *d, days);
	*/
}
Esempio n. 8
0
static int do_range_limit_days(timelib_sll *y, timelib_sll *m, timelib_sll *d)
{
	timelib_sll leapyear;
	timelib_sll days_this_month;
	timelib_sll last_month, last_year;
	timelib_sll days_last_month;
	
	/* can jump an entire leap year period quickly */
	if (*d >= DAYS_PER_LYEAR_PERIOD || *d <= -DAYS_PER_LYEAR_PERIOD) {
		*y += YEARS_PER_LYEAR_PERIOD * (*d / DAYS_PER_LYEAR_PERIOD);
		*d -= DAYS_PER_LYEAR_PERIOD * (*d / DAYS_PER_LYEAR_PERIOD);
	}

	do_range_limit(1, 13, 12, m, y);

	leapyear = timelib_is_leap(*y);
	days_this_month = leapyear ? days_in_month_leap[*m] : days_in_month[*m];
	last_month = (*m) - 1;

	if (last_month < 1) {
		last_month += 12;
		last_year = (*y) - 1;
	} else {
		last_year = (*y);
	}
	leapyear = timelib_is_leap(last_year);
	days_last_month = leapyear ? days_in_month_leap[last_month] : days_in_month[last_month];

	if (*d <= 0) {
		*d += days_last_month;
		(*m)--;
		return 1;
	}
	if (*d > days_this_month) {
		*d -= days_this_month;
		(*m)++;
		return 1;
	}
	return 0;
}