From aa4fe8256ae2f7f70724be99b210c2e7c42c525c Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Tue, 8 Aug 2017 18:22:20 +0300 Subject: [PATCH] [Minor] rspamd_stats: try to guess the last year timestamps for syslog --- utils/rspamd_stats.pl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/rspamd_stats.pl b/utils/rspamd_stats.pl index af5b4ec6f..fcd2ea503 100755 --- a/utils/rspamd_stats.pl +++ b/utils/rspamd_stats.pl @@ -448,15 +448,19 @@ sub numeric { $a_num <=> $b_num; } -# Convert syslog timestamp to "ISO 8601 like" format. -# Using current year, as syslog does not record the year (nor the timezone) +# Convert syslog timestamp to "ISO 8601 like" format +# using current year as syslog does not record the year (nor the timezone) +# or the last year if the guessed time is in the future. sub syslog2iso { my %month_map; @month_map{qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)} = 0 .. 11; my ( $month, @t ) = $_[0] =~ m/^(\w{3}) \s\s? (\d\d?) \s (\d\d):(\d\d):(\d\d)/x; - sprintf '%04d-%02d-%02d %02d:%02d:%02d', 1900 + (localtime)[5], + my $epoch = + timelocal( ( reverse @t ), $month_map{$month}, 1900 + (localtime)[5] ); + sprintf '%04d-%02d-%02d %02d:%02d:%02d', + 1900 + (localtime)[5] - ( $epoch > time ), $month_map{$month} + 1, @t; } -- 2.39.5