File Coverage

blib/lib/Acme/December/Eternal.pm
Criterion Covered Total %
statement 49 51 96.0
branch 5 6 83.3
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 60 64 93.7


line stmt bran cond sub pod time code
1             package Acme::December::Eternal;
2              
3 1     1   68471 use 5.010000;
  1         4  
4 1     1   5 use strict;
  1         2  
  1         19  
5 1     1   5 use warnings;
  1         2  
  1         87  
6              
7             require Exporter;
8              
9             our @ISA = qw(Exporter);
10             our @EXPORT = qw(eternaldecemberize);
11             our $VERSION = '1.0';
12              
13 1     1   468 use Date::Manip;
  1         158328  
  1         151  
14 1     1   577 use Lingua::EN::Numbers::Ordinate;
  1         451  
  1         441  
15              
16             sub eternaldecemberize {
17             # Change date&time string to "Eternal december" date string
18 5     5 0 96 my ($indateraw) = @_;
19              
20 5         14 my ($indate, $intime);
21 5 50       27 if($indateraw =~ /\ /) {
22 5         30 ($indate, $intime) = split/\ /, $indateraw;
23 5         18 $intime = ' ' . $intime;
24             } else {
25 0         0 $indate = $indateraw;
26 0         0 $intime = '';
27             }
28              
29 5         12 my $result = '';
30              
31 5         42 my $date = Date::Manip::Date->new();
32 5         51977 $date->parse($indate);
33              
34 5         100442 my $month = $date->printf('%m');
35 5         479 $month =~ s/^0+//g;
36 5         56 my $dayofyear = $date->printf('%j');
37 5         465 $dayofyear =~ s/^0+//g;
38 5         19 my $dayofmonth = $date->printf('%d');
39 5         322 $dayofmonth =~ s/^0+//g;
40 5         18 my $year = $date->printf('%Y');
41              
42 5         654 my $weekday = $date->printf('%a');
43 5         414 $weekday .= ', ';
44              
45             # December starts on 1st of September...
46 5         42 my $septstart = Date::Manip::Date->new();
47 5         51788 $septstart->parse($year . '-09-01');
48 5         72228 my $septday = $septstart->printf('%j');
49 5         677 $septday =~ s/^0+//g;
50              
51 5 100       41 if($month == 8) {
52             # August
53 2         14 $result = $weekday . ordinate($dayofmonth) . ' August ' . $year;
54             } else {
55             # December
56 3 100       11 if($month > 8) {
57 2         8 my $daycount = $dayofyear - $septday + 1;
58 2         15 $result = $weekday . ordinate($daycount) . ' December ' . $year
59             } else {
60             # Uh-oh, this is the continuation of last years december...
61 1         7 my $decend = Date::Manip::Date->new();
62 1         10245 $decend->parse($year . '-12-31');
63 1         14297 my $decday = $decend->printf('%j');
64 1         123 $decday =~ s/^0+//g;
65 1         4 my $prevyeardays = $decday - $septday + 1;
66 1         4 my $daycount = $dayofyear + $prevyeardays;
67 1         3 $year--; # previous years december
68 1         8 $result = $weekday . ordinate($daycount) . ' December ' . $year
69             }
70             }
71              
72 5         1599 return $result;
73             }
74              
75             1;
76             __END__