Quantity/Time/Time.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 76 CC 4 SCAR 19.7
CC
4
Cov
0%
readable
20.0
new
2.0
hour
2.0
CRAP 7.1
1 ### Change History
2 # 1999-03-03 Stub created. -Simon
3  
4 package Data::Quantity::Time::Time;
5  
6 require 5;
7 use strict;
8 use Carp;
9  
10 use vars qw( $VERSION );
11 $VERSION = 0.001;
12  
13 use Data::Quantity::Number::Integer '-isasubclass';
14  
15 sub new {
16 my $package = shift;
17 bless [ @_ ], $package;
18 }
19  
20 # $hour = $time_q->hour;
21 sub hour {
22 my $time_q = shift;
23 $time_q->[0];
24 }
25  
26 # $hour = $time_q->minute;
27 sub minute {
28 my $time_q = shift;
29 $time_q->[1];
30 }
31  
32 # $hour = $time_q->second;
33 sub second {
34 my $time_q = shift;
35 $time_q->[2];
36 }
37  
38 use vars qw( $default_readable_format );
39 $default_readable_format ||= 'hh:mm:ss';
40  
41 sub readable {
42 my $time_q = shift;
43
44 my $style = shift;
45 $style ||= $default_readable_format;
46
47 my ( $sec, $min, $hour ) = ( $time_q->[2], $time_q->[1], $time_q->[0] );
48 my ( $ss, $mm, $hh ) = ( $sec, $min, $hour );
49 foreach ( $ss, $mm, $hh ) {
50 $_ = ( '0' x ( 2 - length($_) ) ) . $_;
51 }
52 my $h = ( $hour % 12 ) || 12;
53 my $ampm = ( $hour > 11 ) ? 'pm' : 'am';
54 my $AMPM = uc($ampm);
55
56 if ( $style eq 'hh:mm:ss' ) {
57 return "$hh:$mm:$ss";
58 } elsif ( $style eq 'h:mmPM' ) {
59 return "$h:$mm$AMPM";
60 } else {
61 croak "Unkown timestamp readable format.";
62 }
63  
64 }
65  
66 1;