Avoid use of POSIX strftime to help with timezones

This commit is contained in:
Chris 2024-06-04 15:25:28 +01:00
parent 826b1e5d94
commit ea0a3643c8

View File

@ -126,6 +126,7 @@ use Webperl::Utils qw(path_join superchomp);
use Carp qw(longmess carp);
use HTML::WikiConverter;
use HTML::Entities;
use DateTime;
use v5.12;
use strict;
@ -899,13 +900,12 @@ sub ordinal {
sub format_time {
my $self = shift;
my $time = shift;
my $format = shift;
# Fall back on the default if the user has not set a format.
$format = $self -> {"timefmt"} if(!defined($format));
my $datestr = strftime($format, localtime($time));
$datestr =~ s/(\d+)\s*%o/ordinal($1)/ge;
my $format = shift // $self -> {"timefmt"};
return "" unless($time);
my $datestr = eval { DateTime -> from_epoch(epoch => $time, time_zone = $self -> {"tz"} // "Europe/London") -> strftime($format); };
return "" if($@);
return $datestr;
}