line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package PlotCalendar::DateTools; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
494
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
145
|
|
4
|
4
|
|
|
4
|
|
21
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
577
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
9
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
10
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
11
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
12
|
|
|
|
|
|
|
@EXPORT = qw( Day_of_Year Days_in_Month Decode_Day_of_Week Day_of_Week Add_Delta_Days Day_of_Week_to_Text Month_to_Text Days_in_Year ); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = sprintf "%d.%02d", q$Revision: 1.0 $ =~ m#(\d+)\.(\d+)#; |
15
|
|
|
|
|
|
|
|
16
|
4
|
|
|
4
|
|
23
|
use Carp; |
|
4
|
|
|
|
|
66
|
|
|
4
|
|
|
|
|
3117
|
|
17
|
|
|
|
|
|
|
require Time::DaysInMonth; |
18
|
|
|
|
|
|
|
require Time::JulianDay; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my %data; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$data{MONTHS} = { '1' => 'Jan', |
23
|
|
|
|
|
|
|
'2' => 'Feb', |
24
|
|
|
|
|
|
|
'3' => 'Mar', |
25
|
|
|
|
|
|
|
'4' => 'Apr', |
26
|
|
|
|
|
|
|
'5' => 'May', |
27
|
|
|
|
|
|
|
'6' => 'Jun', |
28
|
|
|
|
|
|
|
'7' => 'Jul', |
29
|
|
|
|
|
|
|
'8' => 'Aug', |
30
|
|
|
|
|
|
|
'9' => 'Sep', |
31
|
|
|
|
|
|
|
'10' => 'Oct', |
32
|
|
|
|
|
|
|
'11' => 'Nov', |
33
|
|
|
|
|
|
|
'12' => 'Dec', |
34
|
|
|
|
|
|
|
}; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
$data{LONGMONTHS} = { '1' => 'January', |
37
|
|
|
|
|
|
|
'2' => 'February', |
38
|
|
|
|
|
|
|
'3' => 'March', |
39
|
|
|
|
|
|
|
'4' => 'April', |
40
|
|
|
|
|
|
|
'5' => 'May', |
41
|
|
|
|
|
|
|
'6' => 'June', |
42
|
|
|
|
|
|
|
'7' => 'July', |
43
|
|
|
|
|
|
|
'8' => 'August', |
44
|
|
|
|
|
|
|
'9' => 'September', |
45
|
|
|
|
|
|
|
'10' => 'October', |
46
|
|
|
|
|
|
|
'11' => 'November', |
47
|
|
|
|
|
|
|
'12' => 'December', |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$data{DAYS} = { '7' => 'Sun', |
51
|
|
|
|
|
|
|
'1' => 'Mon', |
52
|
|
|
|
|
|
|
'2' => 'Tue', |
53
|
|
|
|
|
|
|
'3' => 'Wed', |
54
|
|
|
|
|
|
|
'4' => 'Thu', |
55
|
|
|
|
|
|
|
'5' => 'Fri', |
56
|
|
|
|
|
|
|
'6' => 'Sat', |
57
|
|
|
|
|
|
|
}; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$data{LONGDAYS} = { '7' => 'Sunday', |
60
|
|
|
|
|
|
|
'1' => 'Monday', |
61
|
|
|
|
|
|
|
'2' => 'Tuesday', |
62
|
|
|
|
|
|
|
'3' => 'Wednesday', |
63
|
|
|
|
|
|
|
'4' => 'Thursday', |
64
|
|
|
|
|
|
|
'5' => 'Friday', |
65
|
|
|
|
|
|
|
'6' => 'Saturday', |
66
|
|
|
|
|
|
|
}; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# **************************************************************** |
69
|
|
|
|
|
|
|
sub Day_of_Year { # done |
70
|
1
|
|
|
1
|
0
|
36
|
my ($yr,$mon,$day) = @_; |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
|
|
0
|
my $jd = julian_day($yr, $mon, $day); |
73
|
0
|
|
|
|
|
0
|
my $jdjan = julian_day($yr, 1, 1); |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
0
|
return $jd-$jdjan+1; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# **************************************************************** |
79
|
|
|
|
|
|
|
sub Days_in_Month { # done |
80
|
1
|
|
|
1
|
0
|
2
|
my ($yr,$mon) = @_; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
0
|
return days_in($yr, $mon);; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# **************************************************************** |
86
|
|
|
|
|
|
|
sub Decode_Day_of_Week { # done |
87
|
2
|
|
|
2
|
0
|
4
|
my $dayname = shift; |
88
|
|
|
|
|
|
|
|
89
|
2
|
|
|
|
|
14
|
$dayname =~ tr/A-Z/a-z/; #lowercase it |
90
|
2
|
|
|
|
|
3
|
my $dow; |
91
|
2
|
|
|
|
|
9
|
for ($dow=1; $dow<=7; $dow++) { |
92
|
14
|
100
|
|
|
|
59
|
if (index($data{LONGDAYS}{$dow},"\u$dayname") == 0) {last;} |
|
2
|
|
|
|
|
7
|
|
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
2
|
|
|
|
|
7
|
return $dow; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
# **************************************************************** |
99
|
|
|
|
|
|
|
sub Day_of_Week { # done |
100
|
1
|
|
|
1
|
0
|
2
|
my ($yr,$mon,$day) = @_; |
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
|
|
0
|
my $jd = julian_day($yr, $mon, $day); |
103
|
0
|
|
|
|
|
0
|
my $dow = day_of_week($jd); |
104
|
0
|
0
|
|
|
|
0
|
if ($dow == 0) { $dow = 7; } |
|
0
|
|
|
|
|
0
|
|
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
return $dow; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# **************************************************************** |
110
|
|
|
|
|
|
|
sub Add_Delta_Days { # done |
111
|
0
|
|
|
0
|
0
|
0
|
my ($yr,$mon,$day, $numdays) = @_; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
0
|
my $jd = julian_day($yr, $mon, $day); |
114
|
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
0
|
$jd += $numdays; |
116
|
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
0
|
($yr, $mon, $day) = inverse_julian_day($jd); |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
0
|
return ($yr,$mon,$day); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# **************************************************************** |
123
|
|
|
|
|
|
|
sub Day_of_Week_to_Text { # done |
124
|
7
|
|
|
7
|
0
|
13
|
my $dow = shift; |
125
|
|
|
|
|
|
|
|
126
|
7
|
|
|
|
|
18
|
return $data{LONGDAYS}{$dow}; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# **************************************************************** |
130
|
|
|
|
|
|
|
sub Month_to_Text { # done |
131
|
1
|
|
|
1
|
0
|
2
|
my $mon = shift; |
132
|
|
|
|
|
|
|
|
133
|
1
|
|
|
|
|
5
|
return $data{LONGMONTHS}{$mon}; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
# **************************************************************** |
137
|
|
|
|
|
|
|
sub Days_in_Year { # done |
138
|
0
|
|
|
0
|
0
|
|
my $yr = shift; |
139
|
0
|
|
|
|
|
|
my $mon = shift; |
140
|
0
|
|
|
|
|
|
my $days = 0; |
141
|
0
|
|
|
|
|
|
for (my $i=1;$i<=$mon;$i++) { |
142
|
0
|
|
|
|
|
|
$days += days_in($yr,$i); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
return $days; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
1; |
149
|
|
|
|
|
|
|
__END__ |