File Coverage

blib/lib/Date/Holidays/FR.pm
Criterion Covered Total %
statement 44 44 100.0
branch 22 22 100.0
condition 25 33 75.7
subroutine 10 10 100.0
pod 4 4 100.0
total 105 113 92.9


line stmt bran cond sub pod time code
1             package Date::Holidays::FR;
2            
3 1     1   26654 use strict;
  1         3  
  1         37  
4 1     1   6 use warnings;
  1         1  
  1         31  
5 1     1   897 use Time::Local;
  1         5226  
  1         111  
6 1     1   1172 use Date::Easter;
  1         713  
  1         65  
7 1     1   6 use Exporter;
  1         2  
  1         745  
8             our @ISA = qw(Exporter);
9             our @EXPORT = qw(is_fr_holiday);
10            
11             our $VERSION = '0.02';
12            
13             sub get_easter {
14 21     21 1 32 my ($year) = @_;
15            
16 21         61 return Date::Easter::easter($year);
17             }
18            
19             sub get_ascension {
20 1     1 1 1200 my ($year) = @_;
21            
22 1         6 return _compute_date_from_easter($year, 39);
23             }
24            
25             sub get_pentecost {
26 1     1 1 1022 my ($year) = @_;
27            
28 1         4 return _compute_date_from_easter($year, 50);
29             }
30            
31             sub _compute_date_from_easter {
32 14     14   23 my ($year, $delta) = @_;
33            
34 14         25 my ($easter_month, $easter_day) = get_easter($year);
35 14         230 my $easter_date = Time::Local::timelocal(0, 0, 1, $easter_day, $easter_month - 1, $year - 1900);
36 14         1091 my ($date_month, $date_day) = (localtime($easter_date + $delta * 86400))[4, 3];
37 14         24 $date_month++;
38            
39 14         33 return ($date_month, $date_day);
40             }
41            
42             sub is_fr_holiday {
43 14     14 1 37 my ($year, $month, $day) = @_;
44            
45 14 100 100     196 if ($day == 1 and $month == 1) { return "Nouvel an"; }
  1 100 100     8  
    100 66        
    100 66        
    100 66        
    100 66        
    100 100        
    100 66        
46 1         8 elsif ($day == 1 and $month == 5) { return "Fête du travail"; }
47 1         8 elsif ($day == 8 and $month == 5) { return "Armistice 39-45"; }
48 1         7 elsif ($day == 14 and $month == 7) { return "Fête nationale"; }
49 1         8 elsif ($day == 15 and $month == 8) { return "Assomption"; }
50 1         9 elsif ($day == 1 and $month == 11) { return "Toussaint"; }
51 1         8 elsif ($day == 11 and $month == 11) { return "Armistice 14-18"; }
52 1         10 elsif ($day == 25 and $month == 12) { return "Noël"; }
53             else {
54 6         15 my ($easter_month, $easter_day) = get_easter($year);
55 6         110 my ($ascension_month, $ascension_day) = _compute_date_from_easter($year, 39);
56 6         14 my ($pentecost_month, $pentecost_day) = _compute_date_from_easter($year, 50);
57            
58 6 100 66     76 if ($day == ($easter_day + 1) and $month == $easter_month) { return "Lundi de pâques"; }
  1 100 66     7  
    100 66        
59 1         10 elsif ($day == $ascension_day and $month == $ascension_month) { return "Ascension"; }
60 1         13 elsif ($day == $pentecost_day and $month == $pentecost_month) { return "Pentecôte"; }
61             }
62             }
63            
64             1;
65            
66             __END__