File Coverage

blib/lib/Date/Holidays/PF.pm
Criterion Covered Total %
statement 49 57 85.9
branch 26 30 86.6
condition 30 45 66.6
subroutine 11 13 84.6
pod 5 6 83.3
total 121 151 80.1


line stmt bran cond sub pod time code
1             package Date::Holidays::PF;
2              
3 1     1   51826 use strict;
  1         3  
  1         28  
4 1     1   5 use warnings;
  1         2  
  1         28  
5 1     1   275 use Time::Local;
  1         2088  
  1         64  
6 1     1   280 use Date::Easter;
  1         536  
  1         52  
7 1     1   6 use Exporter;
  1         2  
  1         54  
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.03';
12 1     1   361 use utf8;
  1         12  
  1         4  
13              
14             sub get_easter {
15 33     33 1 46 my ($year) = @_;
16 33         60 return Date::Easter::easter($year);
17             }
18              
19             sub get_ascension {
20 1     1 1 927 my ($year) = @_;
21 1         5 return _compute_date_from_easter($year, 39);
22             }
23              
24             sub get_pentecost {
25 1     1 1 921 my ($year) = @_;
26 1         4 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   42 my ($year, $delta) = @_;
41              
42 26         39 my ($easter_month, $easter_day) = get_easter($year);
43 26         401 my $easter_date = Time::Local::timelocal(0, 0, 1, $easter_day, $easter_month - 1, $year - 1900);
44 26         1215 my ($date_month, $date_day) = (localtime($easter_date + $delta * 86400))[4, 3];
45 26         45 $date_month++;
46              
47 26         50 return ($date_month, $date_day);
48             }
49              
50             sub is_pf_holiday {
51 14     14 1 109 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         7 elsif ($day == 1 and $month == 5) { return "Fête du travail"; }
56 1         7 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         6 elsif ($day == 1 and $month == 11) { return "Toussaint"; }
61 1         5 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         14 my ($easter_month, $easter_day) = get_easter($year);
65 6         138 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         7 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 50 66     71 if ($day == $easter_day and $month == $easter_month) { return "Pâques"; }
  0 100 66     0  
    50 33        
    100 66        
    100 66        
71 1         7 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         7 elsif ($day == $ascension_day and $month == $ascension_month) { return "Ascension"; }
74 1         12 elsif ($day == $pentecost_day and $month == $pentecost_month) { return "Lundi de Pentecôte"; }
75             }
76             }
77              
78             1;
79              
80             __END__