From 20b48244b99d3bc63cca2e36b290c834347653b5 Mon Sep 17 00:00:00 2001
From: Olav Morken <olav.morken@uninett.no>
Date: Tue, 8 Dec 2009 14:14:49 +0000
Subject: [PATCH] statistics: Handle new year wraparound without year included
 in log lines.

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2049 44740490-163a-0410-bde0-09ae8108e29a
---
 modules/statistics/lib/LogParser.php | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/modules/statistics/lib/LogParser.php b/modules/statistics/lib/LogParser.php
index 5d1ff70df..a0e144767 100644
--- a/modules/statistics/lib/LogParser.php
+++ b/modules/statistics/lib/LogParser.php
@@ -25,6 +25,21 @@ class sspmod_statistics_LogParser {
 
 	public function parseEpoch($line) {
 		$epoch = strtotime(substr($line, 0, $this->datelength));
+		if ($epoch > time() + 60*60*24*31) {
+			/*
+			 * More than a month in the future - probably caused by
+			 * the log files missing the year.
+			 * We will therefore subtrackt one year.
+			 */
+			$hour = gmdate('H', $epoch);
+			$minute = gmdate('i', $epoch);
+			$second = gmdate('s', $epoch);
+			$month = gmdate('n', $epoch);
+			$day = gmdate('j', $epoch);
+			$year = gmdate('Y', $epoch) - 1;
+			$epoch = gmmktime($hour, $minute, $second, $month, $day, $year);
+		}
+
 // 		echo 'debug   ' . $line . "\n";
 // 		echo 'debug   [' . substr($line, 0, $this->datelength)  . '] => [' . $epoch . ']' . "\n";
 		return $epoch;
-- 
GitLab