From f01e7bc536a3d22daca325961bbdcf246037aaca Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 23 Feb 2021 12:17:00 +0000 Subject: [PATCH] Bug 27048: (follow-up) Use DateTime instead of POSIX This introduces additional dependancies and builds DateTime objects multiple times.. I'm not sure it's worth it. --- misc/migration_tools/rebuild_zebra.pl | 30 +++++++++++---------------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 8fd611a83b..98988d7b4f 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -18,6 +18,8 @@ use Modern::Perl; use Koha::Script; +use Koha::DateUtils; +use DateTime::Format::Duration; use C4::Context; use Getopt::Long; use Fcntl qw(:flock); @@ -209,9 +211,9 @@ if( !defined $LockFH ) { # the lockfile) }; -my $start_time = time(); +my $start_time = dt_from_string; if ( $verbose_logging ) { - my $pretty_time = POSIX::strftime("%H:%M:%S",localtime($start_time)); + my $pretty_time = dt_from_string()->strftime("%H:%M:%S"); print "Zebra configuration information\n"; print "================================\n"; print "Zebra biblio directory = $biblioserverdir\n"; @@ -833,22 +835,14 @@ sub _create_lockfile { #returns undef on failure sub pretty_time { use integer; - my $now = time; - my $elapsed = $now - $start_time; - local $_ = $elapsed; - my ( $d, $h, $m, $s ); - $s = $_ % 60; - $_ /= 60; - $m = $_ % 60; - $_ /= 60; - $h = $_ % 24; - $_ /= 24; - $d = $_; - - my $now_pretty = POSIX::strftime("%H:%M:%S",localtime($now)); - my $elapsed_pretty = $d ? "[$d:$h:$m:$s]" : $h ? "[$h:$m:$s]" : $m ? "[$m:$s]" : "[$s]"; - - return "$now_pretty $elapsed_pretty"; + my $now = dt_from_string; + my $elapsed = $now->delta_ms($start_time); + my $duration_formatter = DateTime::Format::Duration->new(pattern => '%e:%H:%M:%S'); + + my $now_pretty = $now->strftime("%H:%M:%S"); + #my $elapsed_pretty = $d ? "[$d:$h:$m:$s]" : $h ? "[$h:$m:$s]" : $m ? "[$m:$s]" : "[$s]"; + + return "$now_pretty [" . $duration_formatter->format_duration($elapsed) . "]"; } sub print_usage { -- 2.20.1