line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::Holidays::CN; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
92632
|
use warnings; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
127
|
|
4
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
136
|
|
5
|
4
|
|
|
4
|
|
23
|
use Carp; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
300
|
|
6
|
4
|
|
|
4
|
|
24
|
use base 'Exporter'; |
|
4
|
|
|
|
|
9
|
|
|
4
|
|
|
|
|
375
|
|
7
|
4
|
|
|
4
|
|
25
|
use vars qw/$VERSION @EXPORT @EXPORT_OK/; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
408
|
|
8
|
|
|
|
|
|
|
$VERSION = '0.01'; |
9
|
|
|
|
|
|
|
@EXPORT = qw(is_cn_holiday cn_holidays); |
10
|
|
|
|
|
|
|
@EXPORT_OK = qw(is_cn_solar_holiday is_cn_lunar_holiday); |
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
5583
|
use DateTime; |
|
4
|
|
|
|
|
839109
|
|
|
4
|
|
|
|
|
216
|
|
13
|
4
|
|
|
4
|
|
5775
|
use DateTime::Calendar::Chinese; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
use Time::Local; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# The Gregorian calendar/solar calendar |
17
|
|
|
|
|
|
|
my $SOLAR = { |
18
|
|
|
|
|
|
|
'0101' => '元旦', |
19
|
|
|
|
|
|
|
'0214' => '情人节', |
20
|
|
|
|
|
|
|
'0308' => '妇女节', |
21
|
|
|
|
|
|
|
'0312' => '植树节', |
22
|
|
|
|
|
|
|
'0401' => '愚人节', |
23
|
|
|
|
|
|
|
'0405' => '清明节', |
24
|
|
|
|
|
|
|
'0501' => '劳动节', |
25
|
|
|
|
|
|
|
'0504' => '青年节', |
26
|
|
|
|
|
|
|
'0601' => '劳动节', |
27
|
|
|
|
|
|
|
'0701' => '建党日', |
28
|
|
|
|
|
|
|
'0801' => '建军节', |
29
|
|
|
|
|
|
|
'0910' => '教师节', |
30
|
|
|
|
|
|
|
'1001' => '国庆节', |
31
|
|
|
|
|
|
|
'1225' => '圣诞节', |
32
|
|
|
|
|
|
|
}; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# The Chinese calendar/lunar calendar |
35
|
|
|
|
|
|
|
my $LUNAR = { |
36
|
|
|
|
|
|
|
'0101' => '春节', |
37
|
|
|
|
|
|
|
'0115' => '元宵节', |
38
|
|
|
|
|
|
|
'0505' => '端午节', |
39
|
|
|
|
|
|
|
'0707' => '七夕情人节', |
40
|
|
|
|
|
|
|
'0815' => '中秋节', |
41
|
|
|
|
|
|
|
'0909' => '重阳节', |
42
|
|
|
|
|
|
|
'1208' => '腊八节', |
43
|
|
|
|
|
|
|
'1222' => '冬至节', |
44
|
|
|
|
|
|
|
'1230' => '除夕', |
45
|
|
|
|
|
|
|
}; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub is_cn_solar_holiday { |
48
|
|
|
|
|
|
|
my ($year, $month, $day) = @_; |
49
|
|
|
|
|
|
|
defined $year || return undef; |
50
|
|
|
|
|
|
|
defined $month || return undef; |
51
|
|
|
|
|
|
|
defined $day || return undef; |
52
|
|
|
|
|
|
|
# the special day: mother's day and father's day |
53
|
|
|
|
|
|
|
# mother's day = 2th sunday of 5 |
54
|
|
|
|
|
|
|
if ($month == 5 && ($day > 7 && $day < 15)) { |
55
|
|
|
|
|
|
|
my $time = timelocal(0,0,0, $day, $month - 1, $year); |
56
|
|
|
|
|
|
|
my @ltime = localtime($time); |
57
|
|
|
|
|
|
|
return '母亲节' if ($ltime[6] == 0); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
# father's day = 3th sunday of 6 |
60
|
|
|
|
|
|
|
if ($month == 6 && ($day > 14 && $day < 22)) { |
61
|
|
|
|
|
|
|
my $time = timelocal(0,1,0, $day, $month - 1, $year); |
62
|
|
|
|
|
|
|
my @ltime = localtime($time); |
63
|
|
|
|
|
|
|
return '父亲节' if ($ltime[6] == 0); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
return $SOLAR->{sprintf "%02d%02d", $month, $day}; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub is_cn_lunar_holiday { |
69
|
|
|
|
|
|
|
my ($year, $month, $day) = @_; |
70
|
|
|
|
|
|
|
defined $year || return undef; |
71
|
|
|
|
|
|
|
defined $month || return undef; |
72
|
|
|
|
|
|
|
defined $day || return undef; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
my $dt2 = DateTime->new( |
75
|
|
|
|
|
|
|
year => $year, |
76
|
|
|
|
|
|
|
month => $month, |
77
|
|
|
|
|
|
|
day => $day, |
78
|
|
|
|
|
|
|
hour => 0, |
79
|
|
|
|
|
|
|
minute => 0, |
80
|
|
|
|
|
|
|
second => 0, |
81
|
|
|
|
|
|
|
nanosecond => 500000000, |
82
|
|
|
|
|
|
|
time_zone => 'Asia/Shanghai', |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
# ouch! the DateTime::Calendar::Chinese is a bit too slow! |
85
|
|
|
|
|
|
|
my $dt = DateTime::Calendar::Chinese->from_object(object => $dt2); |
86
|
|
|
|
|
|
|
return $LUNAR->{sprintf "%02d%02d", $dt->month, $dt->day}; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub is_cn_holiday { |
90
|
|
|
|
|
|
|
is_cn_solar_holiday(@_) || is_cn_lunar_holiday(@_); |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub cn_holidays { |
94
|
|
|
|
|
|
|
my ($year) = @_; |
95
|
|
|
|
|
|
|
defined $year || return undef; |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
# only provide solar calendar for now |
98
|
|
|
|
|
|
|
return $SOLAR; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
__END__ |