Hi all,
I want to generate an array of dates with an epoch not in DST to one
in DST with TimeZone enabled.
I'm using the following code:
use strict;
use DateTime;
use Data::Dumper;
my $fr_12 = 1130536800; # Sat 29 Oct 2005 00:00:00
my $to_12 = 1132009200; # Tue 15 Nov 2005 00:00:00
my $start_dt = DateTime->from_epoch( epoch => $fr_12 );
$start_dt->set_time_zone('Europe/Paris');
my $end_dt = DateTime->from_epoch( epoch => $to_12 );
$end_dt->set_time_zone('Europe/Paris');
my $list = [];
for (my $dt = $start_dt->clone();
$dt <= $end_dt;
$dt->add(days => 1) )
{
my $ndt = $dt->clone;
push @{ $list }, join(' ', $ndt->hms(':'), $ndt->dmy('/'));
}
print Dumper($list);
The output is :
$VAR1 = [
'00:00:00 29/10/2005',
'00:00:00 30/10/2005',
'23:00:00 30/10/2005',
'23:00:00 31/10/2005',
'23:00:00 01/11/2005',
'23:00:00 02/11/2005',
'23:00:00 03/11/2005',
'23:00:00 04/11/2005',
'23:00:00 05/11/2005',
'23:00:00 06/11/2005',
'23:00:00 07/11/2005',
'23:00:00 08/11/2005',
'23:00:00 09/11/2005',
'23:00:00 10/11/2005',
'23:00:00 11/11/2005',
'23:00:00 12/11/2005',
'23:00:00 13/11/2005',
'23:00:00 14/11/2005'
];
Notice the third entry with two days in 30/10/2005 and the hms being 23:00.
I want to have the following output:
$VAR1 = [
'00:00:00 29/10/2005',
'00:00:00 30/10/2005',
'00:00:00 31/10/2005',
'00:00:00 01/11/2005',
'00:00:00 02/11/2005',
'00:00:00 03/11/2005',
'00:00:00 04/11/2005',
'00:00:00 05/11/2005',
'00:00:00 06/11/2005',
'00:00:00 07/11/2005',
'00:00:00 08/11/2005',
'00:00:00 09/11/2005',
'00:00:00 10/11/2005',
'00:00:00 11/11/2005',
'00:00:00 12/11/2005',
'00:00:00 13/11/2005',
'00:00:00 14/11/2005',
'00:00:00 15/11/2005',
];
Is it possible directly in DateTime or do I have use a kind of
'cleaning' functions to reset the hms to 00:00, get rid of the extra day
and have the last date ?
I also want to be able to work with other type of ranges. For example
have for the 30/10/2005 the range in hours (this is producing an extra
02:00 which I want to be aggregated to have 24 elements and not 25).
Any tips or insights on doing this will be very helpful, thanks in advance!
Regards,
M.