File Coverage

blib/lib/Date/Holidays/PF.pm
Criterion Covered Total %
statement 50 57 87.7
branch 27 30 90.0
condition 30 45 66.6
subroutine 11 13 84.6
pod 5 6 83.3
total 123 151 81.4


line stmt bran cond sub pod time code
1             package Date::Holidays::PF;
2              
3 1     1   51368 use strict;
  1         4  
  1         40  
4 1     1   8 use warnings;
  1         3  
  1         44  
5 1     1   395 use Time::Local;
  1         2510  
  1         75  
6 1     1   380 use Date::Easter;
  1         748  
  1         77  
7 1     1   9 use Exporter;
  1         3  
  1         87  
8             our @ISA = qw(Exporter);
9             our @EXPORT = qw(is_pf_holiday get_easter get_ascension get_pentecost get_vendredisaint get_lundipaques);
10              
11             our $VERSION = '0.01';
12 1     1   490 use utf8;
  1         19  
  1         7  
13              
14             sub get_easter {
15 33     33 1 43 my ($year) = @_;
16 33         57 return Date::Easter::easter($year);
17             }
18              
19             sub get_ascension {
20 1     1 1 997 my ($year) = @_;
21 1         4 return _compute_date_from_easter($year, 39);
22             }
23              
24             sub get_pentecost {
25 1     1 1 930 my ($year) = @_;
26 1         3 return _compute_date_from_easter($year, 50);
27             }
28              
29             sub get_vendredisaint {
30 0     0 1 0 my ($year) = @_;
31 0         0 return _compute_date_from_easter($year, -2);
32             }
33              
34             sub get_lundipaques {
35 0     0 0 0 my ($year) = @_;
36 0         0 return _compute_date_from_easter($year, 1);
37             }
38              
39             sub _compute_date_from_easter {
40 26     26   41 my ($year, $delta) = @_;
41              
42 26         31 my ($easter_month, $easter_day) = get_easter($year);
43 26         390 my $easter_date = Time::Local::timelocal(0, 0, 1, $easter_day, $easter_month - 1, $year - 1900);
44 26         1067 my ($date_month, $date_day) = (localtime($easter_date + $delta * 86400))[4, 3];
45 26         44 $date_month++;
46              
47 26         48 return ($date_month, $date_day);
48             }
49              
50             sub is_pf_holiday {
51 14     14 1 105 my ($year, $month, $day) = @_;
52              
53 14 100 100     153 if ($day == 1 and $month == 1) { return "Nouvel an"; }
  1 50 33     7  
    100 100        
    100 66        
    50 33        
    100 66        
    100 66        
    100 66        
    100 100        
    100 66        
54 0         0 elsif ($day == 5 and $month == 3) { return "Arrivé de l'évangile"; }
55 1         6 elsif ($day == 1 and $month == 5) { return "Fête du travail"; }
56 1         5 elsif ($day == 8 and $month == 5) { return "Armistice 39-45"; }
57 0         0 elsif ($day == 29 and $month == 6) { return "Fête de l'autonomie"; }
58 1         7 elsif ($day == 14 and $month == 7) { return "Fête nationale"; }
59 1         6 elsif ($day == 15 and $month == 8) { return "Assomption"; }
60 1         5 elsif ($day == 1 and $month == 11) { return "Toussaint"; }
61 1         12 elsif ($day == 11 and $month == 11) { return "Armistice 14-18"; }
62 1         6 elsif ($day == 25 and $month == 12) { return "Noël"; }
63             else {
64 6         13 my ($easter_month, $easter_day) = get_easter($year);
65 6         122 my ($vendredisaint_month, $vendredisaint_day) = _compute_date_from_easter($year, -2);
66 6         9 my ($lundipaques_month, $lundipaques_day) = _compute_date_from_easter($year, 1);
67 6         10 my ($ascension_month, $ascension_day) = _compute_date_from_easter($year, 39);
68 6         12 my ($pentecost_month, $pentecost_day) = _compute_date_from_easter($year, 50);
69              
70 6 100 66     57 if ($day == $easter_day and $month == $easter_month) { return "Pâques"; }
  1 100 66     4  
    50 33        
    100 66        
    100 66        
71 1         6 elsif ($day == $lundipaques_day and $month == $lundipaques_month) { return "Lundi de pâques"; }
72 0         0 elsif ($day == $vendredisaint_day and $month == $vendredisaint_month) { return "Vendredi saint"; }
73 1         6 elsif ($day == $ascension_day and $month == $ascension_month) { return "Ascension"; }
74 1         9 elsif ($day == $pentecost_day and $month == $pentecost_month) { return "Lundi de Pentecôte"; }
75             }
76             }
77              
78             1;
79              
80             __END__