* boundaries. This implementation tries to "do what I mean".
* @param ts RFC3164-compatible timestamp to be parsed
* @return Typical (for Java) milliseconds since the UNIX epoch
*/
protected long parseRfc3164Time(String ts) {
DateTime now = DateTime.now();
int year = now.getYear();
ts = TWO_SPACES.matcher(ts).replaceFirst(" ");
DateTime date;
try {
date = rfc3164Format.parseDateTime(ts);
} catch (IllegalArgumentException e) {
logger.debug("rfc3164 date parse failed on ("+ts+"): invalid format", e);
return 0;
}
// try to deal with boundary cases, i.e. new year's eve.
// rfc3164 dates are really dumb.
// NB: cannot handle replaying of old logs or going back to the future
if (date != null) {
DateTime fixed = date.withYear(year);
// flume clock is ahead or there is some latency, and the year rolled
if (fixed.isAfter(now) && fixed.minusMonths(1).isAfter(now)) {
fixed = date.withYear(year - 1);
// flume clock is behind and the year rolled
} else if (fixed.isBefore(now) && fixed.plusMonths(1).isBefore(now)) {
fixed = date.withYear(year + 1);
}
date = fixed;
}