From 1f6705b1fb9ec07da27ce4f5d88b716c712ad209 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Thu, 18 Oct 2018 16:08:03 +0100 Subject: [PATCH] Bug 20750: (follow-up) Fix sorting of log entries The log entries are received from C4::Log::GetLogs with their timestamps formatted as '2018-18-10 16:09:29', this doesn't sort well. In fact, it causes a warning in the Koha logs: Argument "2018-10-04 15:48:15" isn't numeric in numeric comparison (<=>) at /home/koha/kohaclone/Koha/Illrequest/Logger.pm line 231 This patch converts the timestamps to be sorted into epoch dates prior to them being compared --- Koha/Illrequest/Logger.pm | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Koha/Illrequest/Logger.pm b/Koha/Illrequest/Logger.pm index 6cfa3031b3..5643ecde80 100644 --- a/Koha/Illrequest/Logger.pm +++ b/Koha/Illrequest/Logger.pm @@ -19,6 +19,7 @@ package Koha::Illrequest::Logger; use Modern::Perl; use JSON qw( to_json from_json ); +use Time::Piece; use C4::Context; use C4::Templates; @@ -228,7 +229,8 @@ sub get_request_logs { ); } - my @sorted = sort {$$b{'timestamp'} <=> $$a{'timestamp'}} @{$logs}; + my $format = '%Y-%m-%d %H:%M:%S'; + my @sorted = sort {Time::Piece->strptime($$b{'timestamp'}, $format)->epoch <=> Time::Piece->strptime($$a{'timestamp'}, $format)->epoch} @{$logs}; return \@sorted; } -- 2.11.0