示例#1
0
文件: datetime.c 项目: Werkov/rsyslog
/* getOrdinal - 1-366 day of the year
 * I've given little thought to leap seconds here.
 */
int getOrdinal(struct syslogTime *ts)
{
	int yday;
	time_t thistime;
	time_t previousyears;
	int utcOffset;
	time_t seconds_into_year;

	if(ts->year < 1970 || ts->year > 2100) {
		yday = 0;
		errmsg.LogError(0, RS_RET_ERR, "getOrdinal: invalid year %d "
			"in timestamp - returning 1970-01-01 instead", ts->year);
		goto done;
	}

	thistime = syslogTime2time_t(ts);

	previousyears = yearInSecs[ts->year - yearInSec_startYear - 1];

	/* adjust previous years to match UTC offset */
	utcOffset = ts->OffsetHour*3600 + ts->OffsetMinute*60;
	if(ts->OffsetMode == '+')
		utcOffset += -1; /* if timestamp is ahead, we need to "go back" to UTC */
	previousyears += utcOffset;

	/* subtract seconds from previous years */
	seconds_into_year = thistime - previousyears;

	/* divide by seconds in a day and truncate to int */
	yday = seconds_into_year / 86400;
done:
	return yday;
}
示例#2
0
文件: datetime.c 项目: adruch/rsyslog
/* getOrdinal - 1-366 day of the year
 * I've given little thought to leap seconds here.
 */
int getOrdinal(struct syslogTime *ts)
{
	int yday;
	time_t thistime;
	time_t previousyears;
	int utcOffset;
	time_t seconds_into_year;

	thistime = syslogTime2time_t(ts);

	previousyears = yearInSecs[ts->year - yearInSec_startYear - 1];

	/* adjust previous years to match UTC offset */
	utcOffset = ts->OffsetHour*3600 + ts->OffsetMinute*60;
	if(ts->OffsetMode == '+')
		utcOffset += -1; /* if timestamp is ahead, we need to "go back" to UTC */
	previousyears += utcOffset;

	/* subtract seconds from previous years */
	seconds_into_year = thistime - previousyears;

	/* divide by seconds in a day and truncate to int */
	yday = seconds_into_year / 86400;
	return yday;
}
示例#3
0
/**
 * format a timestamp as a UNIX timestamp; subsecond resolution is
 * discarded.
 * Note that this code can use some refactoring. I decided to use it
 * because mktime() requires an upfront TZ update as it works on local
 * time. In any case, it is worth reconsidering to move to mktime() or
 * some other method.
 * Important: pBuf must point to a buffer of at least 11 bytes.
 * rgerhards, 2012-03-29
 */
int formatTimestampUnix(struct syslogTime *ts, char *pBuf)
{
	snprintf(pBuf, 11, "%u", (unsigned) syslogTime2time_t(ts));
	return 11;
}
示例#4
0
	/* calculate week of year for given date by pinning 1/1 as start
	 * of year, then going back and adjusting for the actual week day. */
	weekNum = ((curYearDay + 6) / 7);
	if (curDow < jan1Dow) {
		++weekNum;
	}
	return weekNum;
}

void
timeConvertToUTC(const struct syslogTime *const __restrict__ local,
	struct syslogTime *const __restrict__ utc)
{
	struct timeval tp;
	tp.tv_sec = syslogTime2time_t(local);
	tp.tv_usec = local->secfrac;
	timeval2syslogTime(&tp, utc, 1);
}

/* queryInterface function
 * rgerhards, 2008-03-05
 */
BEGINobjQueryInterface(datetime)
CODESTARTobjQueryInterface(datetime)
	if(pIf->ifVersion != datetimeCURR_IF_VERSION) { /* check for current version, increment on each change */
		ABORT_FINALIZE(RS_RET_INTERFACE_NOT_SUPPORTED);
	}

	/* ok, we have the right interface, so let's fill it
	 * Please note that we may also do some backwards-compatibility