Hi,
I have a list of dates in local standard time that I want to convert to local time.
I came up with this, but I guess there's some smarter way...
Thanks
use strict;
use DateTime::Duration;
use DateTime;
# These are local standard times in Europe/Rome, i.e. always UTC+0100
my @dates = (
[2020,12,2,1,0],
[2021,7,2,1,0]
);
my $timezone = '+0100';
# This is the duration to be added to go from LST to UTC
my $seconds = -($timezone/100) * 3600;
my $dur = DateTime::Duration->new(
years => 0,
months => 0,
weeks => 0,
days => 0,
hours => 0,
minutes => 0,
seconds => $seconds,
nanoseconds => 0
);
for my $date (@dates) {
my $dt = DateTime->new(
year => => $date->[0],
month => $date->[1],
day => $date->[2],
hour => $date->[3],
minute => $date->[4],
second => 0,
nanosecond => 0,
time_zone => 'UTC'
);
$dt->add($dur); # This is a DateTime object in LST
print "LST: ",join("-",@{$date}),"\n";
print "UTC: ",$dt->set_time_zone("UTC"),"\n";
print "LT: ",$dt->set_time_zone("Europe/Rome"),"\n";
}