The algorithm is simple enough; here's a function that takes two arguments, an interval length in minutes and a number of intervals to return, and returns an arrayref containing the specified intervals, expressed in your desired time format:
sub intervals {
my $interval = shift(); # interval length in minutes
my $n_points = shift(); # number of intervals to return
die "intervals() takes two arguments\n"
unless $interval and $n_points;
my @now_tm = localtime();
# check DST delta per @ikegami
my $dst_delta = 0;
my @yesterday_tm = localtime(time() - 86400);
if ($yesterday_tm[8] && !$now_tm[8]) {
# "fall back" - today is an hour shorter
$dst_delta = -3600;
}
elsif (!$yesterday_tm[8] && $now_tm[8]) {
# "spring forward" - today is an hour longer
$dst_delta = 3600;
};
# find timestamp for 00:00 today
my $now_ts = time();
my $then_ts = $now_ts
+ $dst_delta # apply any dst correction required
- ($now_tm[2] * 3600) # subtract hours since midnight
- ($now_tm[1] * 60) # ...and minutes
- $now_tm[0]; # ...and seconds
# generate actual intervals, starting at midnight
my @interval_times = ();
for (my $point = 0; $point < $n_points; $point++) {
my $interval_ts = $then_ts + (($interval * 60) * $point);
my @interval_tm = localtime($interval_ts);
my $interval_formatted = sprintf("%0.2d:%0.2d",
$interval_tm[2],
$interval_tm[1]);
push @interval_times, $interval_formatted;
};
return [@interval_times];
};
Called as intervals(10, 20)
, it returns the following:
0 ARRAY(0xd284e40)
0 '00:00'
1 '00:10'
2 '00:20'
3 '00:30'
4 '00:40'
5 '00:50'
6 '01:00'
7 '01:10'
8 '01:20'
9 '01:30'
10 '01:40'
11 '01:50'
12 '02:00'
13 '02:10'
14 '02:20'
15 '02:30'
16 '02:40'
17 '02:50'
18 '03:00'
19 '03:10'
And no Perl modules required, whether core or otherwise.