-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAddTimes.pm
More file actions
82 lines (57 loc) · 1.84 KB
/
Copy pathAddTimes.pm
File metadata and controls
82 lines (57 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package Time::Duration::AddTimes;
use v5.10.0;
use strict;
use warnings;
use Exporter qw(import);
our $VERSION = '1.0';
our @EXPORT_OK = qw(total_duration);
sub total_duration {
my ($time_list) = @_;
my $total_seconds;
for my $duration (@{$time_list}) {
my $split = ($duration =~ tr/\://);
my ($hours,$minutes,$seconds);
if ($split == 1) {
$hours = 0;
($minutes,$seconds) = split(':',$duration);
}
elsif ($split == 2) {
($hours,$minutes,$seconds) = split(':',$duration);
}
else {
die "Split didn't work";
}
$total_seconds += (($hours * 60) * 60) + ($minutes * 60) + $seconds;
}
my $total_minutes = int($total_seconds/60);
my $total_hours = int($total_minutes/60);
my $total_days = int($total_hours/24);
my $total_weeks = int($total_days/7);
my $mod_seconds = $total_seconds % 60;
my $mod_minutes = $total_minutes % 60;
my $mod_hours = $total_hours % 24;
my $mod_days = $total_days % 7;
my @times = ($mod_days, $mod_hours, $mod_minutes, $mod_seconds);
shift @times while @times && $times[0] == 0;
return join(":", @times)."\n";
}
=pod
=encoding utf8
=head1 NAME
B<Time::Duration::AddTimes> returns total time from a list of smaller durations.
=head1 VERSION
This document describes Time::Duration::AddTimes version 1.0.
=head1 SYNOPSIS
use Time::Duration::AddTimes qw(total_duration);
my @times = qw(3:58 2:48 4:28 5:06 6:50 5:33 4:05 3:29 4:48 6:19);
my $total_time = total_duration(\@times);
# returns 47:24
=head1 DEPENDENCIES
Time::Duration::AddTimes depends on L<Exporter>.
=head1 AUTHOR
Lady Aleena
=head1 LICENSE AND COPYRIGHT
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L<perlartistic>.
Copyright © 2020, Lady Aleena C<(aleena@cpan.org)>. All rights reserved.
=cut
1;