line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Time::Tradedates; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
6878
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
106
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
require Exporter; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our @EXPORT = qw( getNumDays lastTradeDay firstTradeDay ); |
14
|
|
|
|
|
|
|
our $VERSION = '0.1.2'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Preloaded methods go here. |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
1004
|
use Time::Local; |
|
1
|
|
|
|
|
1787
|
|
|
1
|
|
|
|
|
844
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub getNumDays |
23
|
|
|
|
|
|
|
{ |
24
|
6
|
|
|
6
|
0
|
486
|
my $etime = shift; |
25
|
|
|
|
|
|
|
|
26
|
6
|
|
|
|
|
24
|
my @months = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ); |
27
|
6
|
|
|
|
|
15
|
my @wkdays = ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ); |
28
|
6
|
|
|
|
|
117
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $etime ); |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
12
|
my $py = $year+1900; |
31
|
|
|
|
|
|
|
|
32
|
6
|
|
|
|
|
8
|
my $days = 0; |
33
|
|
|
|
|
|
|
|
34
|
6
|
50
|
|
|
|
16
|
if ( $mon <= 5 ) { |
|
|
0
|
|
|
|
|
|
35
|
6
|
50
|
|
|
|
24
|
if ( ($mon % 2) == 0 ) { |
|
|
100
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$days = 31; |
37
|
|
|
|
|
|
|
} elsif ( $mon == 1 ) { |
38
|
3
|
50
|
|
|
|
11
|
if ( (($year+1900)%4) == 0 ) { |
39
|
3
|
|
|
|
|
5
|
$days = 29; |
40
|
|
|
|
|
|
|
} else { |
41
|
0
|
|
|
|
|
0
|
$days = 28; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} else { |
44
|
3
|
|
|
|
|
7
|
$days = 30; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} elsif ( ($mon % 2) == 1 ) { |
47
|
0
|
|
|
|
|
0
|
$days = 31; |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
|
|
|
|
0
|
$days = 30; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
6
|
|
|
|
|
21
|
return( $days ); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub lastTradeDay |
56
|
|
|
|
|
|
|
{ |
57
|
5
|
|
|
5
|
0
|
183
|
my $mon = shift; |
58
|
5
|
|
|
|
|
9
|
my $py = shift; |
59
|
5
|
|
|
|
|
6
|
my $minus = shift; |
60
|
|
|
|
|
|
|
|
61
|
5
|
|
|
|
|
14
|
my $days = &getNumDays( timelocal( 0,0,0,1,$mon,$py ) ); |
62
|
|
|
|
|
|
|
|
63
|
5
|
|
|
|
|
14
|
my $lday=timelocal( 0,0,0,$days,$mon,$py); |
64
|
5
|
|
|
|
|
312
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $lday ); |
65
|
|
|
|
|
|
|
|
66
|
5
|
|
|
|
|
6
|
my $done = 0; |
67
|
|
|
|
|
|
|
|
68
|
5
|
|
|
|
|
16
|
while ( $done == 0 ) { |
69
|
9
|
100
|
100
|
|
|
40
|
if ( ($wday > 0) && ($wday < 6) ) { |
70
|
5
|
|
|
|
|
16
|
$done = 1; |
71
|
|
|
|
|
|
|
} else { |
72
|
4
|
|
|
|
|
6
|
$days = $days-1; |
73
|
4
|
|
|
|
|
12
|
$lday=timelocal( 0,0,0,$days,$mon,$py); |
74
|
4
|
|
|
|
|
265
|
( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $lday ); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
} |
77
|
5
|
100
|
|
|
|
14
|
if ( $minus != 0 ) { |
78
|
3
|
|
|
|
|
5
|
$minus = $minus * -1; |
79
|
3
|
100
|
|
|
|
9
|
if ( $minus > 1 ) { |
80
|
1
|
|
|
|
|
7
|
return( 0 ); |
81
|
|
|
|
|
|
|
} |
82
|
2
|
|
|
|
|
3
|
$mday=$mday - $minus; |
83
|
2
|
|
|
|
|
5
|
$lday = timelocal( 0,0,0,$mday,$mon,$py ); |
84
|
2
|
|
|
|
|
123
|
( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $lday ); |
85
|
|
|
|
|
|
|
|
86
|
2
|
|
|
|
|
3
|
my $done = 0; |
87
|
|
|
|
|
|
|
|
88
|
2
|
|
|
|
|
7
|
while ( $done == 0 ) { |
89
|
5
|
100
|
100
|
|
|
21
|
if ( ($wday > 0) && ($wday < 6) ) { |
90
|
2
|
|
|
|
|
7
|
$done = 1; |
91
|
|
|
|
|
|
|
} else { |
92
|
3
|
|
|
|
|
5
|
$days = $days-1; |
93
|
3
|
|
|
|
|
20
|
$lday=timelocal( 0,0,0,$days,$mon,$py); |
94
|
3
|
|
|
|
|
208
|
( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $lday ); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
4
|
|
|
|
|
10
|
return( $mday ); |
100
|
|
|
|
|
|
|
} # End sub lastBusDay |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub firstTradeDay |
103
|
|
|
|
|
|
|
{ |
104
|
1
|
|
|
1
|
0
|
36
|
my $mon = shift; |
105
|
1
|
|
|
|
|
2
|
my $py = shift; |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
2
|
my $day = 1; |
108
|
1
|
|
|
|
|
3
|
my $fday=timelocal( 0,0,0,$day,$mon,$py); |
109
|
1
|
|
|
|
|
64
|
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $fday ); |
110
|
|
|
|
|
|
|
|
111
|
1
|
|
|
|
|
3
|
my $done = 0; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
5
|
while ( $done == 0 ) { |
114
|
3
|
100
|
100
|
|
|
18
|
if ( ($wday > 0) && ($wday < 6) ) { |
115
|
1
|
|
|
|
|
4
|
$done = 1; |
116
|
|
|
|
|
|
|
} else { |
117
|
2
|
|
|
|
|
3
|
$day = $day+1; |
118
|
2
|
|
|
|
|
22
|
$fday=timelocal( 0,0,0,$day,$mon,$py); |
119
|
2
|
|
|
|
|
135
|
( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime( $fday ); |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
1
|
|
|
|
|
3
|
return( $mday ); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
__END__ |