Exemplo n.º 1
0
static git_time_t approxidate_str(const char *date,
	time_t time_sec,
	int *error_ret)
{
	int number = 0;
	int touched = 0;
	struct tm tm = {0}, now;

	p_localtime_r(&time_sec, &tm);
	now = tm;

	tm.tm_year = -1;
	tm.tm_mon = -1;
	tm.tm_mday = -1;

	for (;;) {
		unsigned char c = *date;
		if (!c)
			break;
		date++;
		if (isdigit(c)) {
			pending_number(&tm, &number);
			date = approxidate_digit(date-1, &tm, &number);
			touched = 1;
			continue;
		}
		if (isalpha(c))
			date = approxidate_alpha(date-1, &tm, &now, &number, &touched);
	}
	pending_number(&tm, &number);
	if (!touched)
		*error_ret = 1;
	return update_tm(&tm, &now, 0);
}
Exemplo n.º 2
0
unsigned long approxidate(const char *date)
{
	int number = 0;
	struct tm tm, now;
	struct timeval tv;
	char buffer[50];

	if (parse_date(date, buffer, sizeof(buffer)) > 0)
		return strtoul(buffer, NULL, 10);

	gettimeofday(&tv, NULL);
	localtime_r((time_t *)&tv.tv_sec, &tm);
	now = tm;
	for (;;) {
		unsigned char c = *date;
		if (!c)
			break;
		date++;
		if (isdigit(c)) {
			date = approxidate_digit(date-1, &tm, &number);
			continue;
		}
		if (isalpha(c))
			date = approxidate_alpha(date-1, &tm, &number);
	}
	if (number > 0 && number < 32)
		tm.tm_mday = number;
	if (tm.tm_mon > now.tm_mon && tm.tm_year == now.tm_year)
		tm.tm_year--;
	return mktime(&tm);
}
Exemplo n.º 3
0
static int approxidate_str(const char *date, struct timeval *tv)
{
	int number = 0;
	int touched = 0;
	struct atm tm, now;
	time_t time_sec;

	time_sec = tv->tv_sec;
	localtime_r(&time_sec, (struct tm*)	&tm);
	now = tm;

	tm.tm_year = -1;
	tm.tm_mon = -1;
	tm.tm_mday = -1;
	tm.tm_usec = tv->tv_usec;

	for (;;) {
		unsigned char c = *date;
		if (!c)
			break;
		date++;
		if (isdigit(c)) {
			pending_number(&tm, &number);
			date = approxidate_digit(date-1, &tm, &number);
			touched = 1;
			continue;
		}
		if (isalpha(c))
			date = approxidate_alpha(date-1, &tm, &now, &number, &touched);
	}

	pending_number(&tm, &number);
	if (!touched)
		return -1;

	tv->tv_usec = tm.tm_usec;
	tv->tv_sec = update_tm(&tm, &now, 0);

	return 0;
}