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   50338 use strict;
  1         2  
  1         23  
4 1     1   5 use warnings;
  1         2  
  1         20  
5 1     1   250 use Time::Local;
  1         1549  
  1         45  
6 1     1   260 use Date::Easter;
  1         483  
  1         47  
7 1     1   6 use Exporter;
  1         1  
  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.01';
12 1     1   317 use utf8;
  1         11  
  1         4  
13              
14             sub get_easter {
15 33     33 1 39 my ($year) = @_;
16 33         56 return Date::Easter::easter($year);
17             }
18              
19             sub get_ascension {
20 1     1 1 868 my ($year) = @_;
21 1         2 return _compute_date_from_easter($year, 39);
22             }
23              
24             sub get_pentecost {
25 1     1 1 999 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   32 my ($year, $delta) = @_;
41              
42 26         35 my ($easter_month, $easter_day) = get_easter($year);
43 26         403 my $easter_date = Time::Local::timelocal(0, 0, 1, $easter_day, $easter_month - 1, $year - 1900);
44 26         1011 my ($date_month, $date_day) = (localtime($easter_date + $delta * 86400))[4, 3];
45 26         44 $date_month++;
46              
47 26         40 return ($date_month, $date_day);
48             }
49              
50             sub is_pf_holiday {
51 14     14 1 96 my ($year, $month, $day) = @_;
52              
53 14 100 100     128 if ($day == 1 and $month == 1) { return "Nouvel an"; }
  1 50 33     6  
    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         5 elsif ($day == 14 and $month == 7) { return "Fête nationale"; }
59 1         5 elsif ($day == 15 and $month == 8) { return "Assomption"; }
60 1         5 elsif ($day == 1 and $month == 11) { return "Toussaint"; }
61 1         6 elsif ($day == 11 and $month == 11) { return "Armistice 14-18"; }
62 1         5 elsif ($day == 25 and $month == 12) { return "Noël"; }
63             else {
64 6         12 my ($easter_month, $easter_day) = get_easter($year);
65 6         109 my ($vendredisaint_month, $vendredisaint_day) = _compute_date_from_easter($year, -2);
66 6         11 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         13 my ($pentecost_month, $pentecost_day) = _compute_date_from_easter($year, 50);
69              
70 6 50 66     52 if ($day == $easter_day and $month == $easter_month) { return "Pâques"; }
  0 100 66     0  
    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         7 elsif ($day == $pentecost_day and $month == $pentecost_month) { return "Lundi de Pentecôte"; }
75             }
76             }
77              
78             1;
79              
80             __END__