line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Date::MSAccess; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Documentation: |
4
|
|
|
|
|
|
|
# POD-style documentation is at the end. Extract it with pod2html.*. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# Reference: |
7
|
|
|
|
|
|
|
# Object Oriented Perl |
8
|
|
|
|
|
|
|
# Damian Conway |
9
|
|
|
|
|
|
|
# Manning |
10
|
|
|
|
|
|
|
# 1-884777-79-1 |
11
|
|
|
|
|
|
|
# P 114 |
12
|
|
|
|
|
|
|
# |
13
|
|
|
|
|
|
|
# Note: |
14
|
|
|
|
|
|
|
# o Tab = 4 spaces || die. |
15
|
|
|
|
|
|
|
# |
16
|
|
|
|
|
|
|
# Author: |
17
|
|
|
|
|
|
|
# Ron Savage |
18
|
|
|
|
|
|
|
# Home page: http://savage.net.au/index.html |
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# Licence: |
21
|
|
|
|
|
|
|
# Australian copyright (c) 2003 Ron Savage. |
22
|
|
|
|
|
|
|
# |
23
|
|
|
|
|
|
|
# All Programs of mine are 'OSI Certified Open Source Software'; |
24
|
|
|
|
|
|
|
# you can redistribute them and/or modify them under the terms of |
25
|
|
|
|
|
|
|
# The Artistic License, a copy of which is available at: |
26
|
|
|
|
|
|
|
# http://www.opensource.org/licenses/index.html |
27
|
|
|
|
|
|
|
|
28
|
1
|
|
|
1
|
|
31221
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
29
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
|
|
1
|
|
735
|
use Date::Calc qw(Days_in_Year Delta_Days leap_year); |
|
1
|
|
|
|
|
47549
|
|
|
1
|
|
|
|
|
915
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
require 5.005_62; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
require Exporter; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
40
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
41
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# This allows declaration use Date::MSAccess ':all'; |
44
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
45
|
|
|
|
|
|
|
# will save memory. |
46
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
) ] ); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
our @EXPORT = qw( |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
); |
55
|
|
|
|
|
|
|
our $VERSION = '1.05'; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# ----------------------------------------------- |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Preloaded methods go here. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# ----------------------------------------------- |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
# Encapsulated class data. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
my(%_attr_data) = |
67
|
|
|
|
|
|
|
( |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _default_for |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
|
0
|
my($self, $attr_name) = @_; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
0
|
$_attr_data{$attr_name}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _standard_keys |
78
|
|
|
|
|
|
|
{ |
79
|
1
|
|
|
1
|
|
5
|
keys %_attr_data; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
} # End of encapsulated class data. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# ----------------------------------------------- |
85
|
|
|
|
|
|
|
# 37622 is 2003-01-01 12:00:00. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub decode_date |
88
|
|
|
|
|
|
|
{ |
89
|
1
|
|
|
1
|
0
|
1206
|
my($self, $date) = @_; |
90
|
1
|
|
|
|
|
4
|
$date -= 1; |
91
|
1
|
|
|
|
|
3
|
my($year) = 1900; |
92
|
1
|
|
|
|
|
2
|
my($days_per_year) = 0; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
6
|
while ($date > $days_per_year) |
95
|
|
|
|
|
|
|
{ |
96
|
104
|
|
|
|
|
301
|
$days_per_year = Days_in_Year($year + 1, 12); |
97
|
|
|
|
|
|
|
|
98
|
104
|
50
|
|
|
|
1119
|
if ($date > $days_per_year) |
99
|
|
|
|
|
|
|
{ |
100
|
104
|
|
|
|
|
109
|
$year++; |
101
|
|
|
|
|
|
|
|
102
|
104
|
|
|
|
|
205
|
$date -= $days_per_year; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
1
|
|
|
|
|
12
|
my(@days_per_month) = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); |
107
|
1
|
50
|
|
|
|
6
|
$days_per_month[2] = 29 if (leap_year($year) ); |
108
|
1
|
|
|
|
|
21
|
my(@month_name) = ('', 'Jan', 'Feb', 'Mar', 'May', 'Apr', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); |
109
|
1
|
|
|
|
|
2
|
my($month) = 1; |
110
|
1
|
|
|
|
|
3
|
my($days_per_month) = $days_per_month[$month]; |
111
|
1
|
|
|
|
|
3
|
my($day) = int($date); |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
3
|
while ($day > $days_per_month) |
114
|
|
|
|
|
|
|
{ |
115
|
0
|
|
|
|
|
0
|
$days_per_month = $days_per_month[$month]; |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
0
|
if ($day > $days_per_month) |
118
|
|
|
|
|
|
|
{ |
119
|
0
|
|
|
|
|
0
|
$month++; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
0
|
$day -= $days_per_month; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
1
|
50
|
|
|
|
6
|
$month = "0$month" if (length($month) == 1); |
126
|
1
|
50
|
|
|
|
4
|
$day = "0$day" if (length($day) == 1); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# One last check... |
129
|
|
|
|
|
|
|
|
130
|
1
|
50
|
33
|
|
|
43
|
( ($year > 1980) && ($year < 2038) && ($month >= '01') && ($month <= '12') && ($day >= '01') && ($day <= '31') ) ? "$year$month$day" : '00000000'; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
} # End of decode_date. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# ----------------------------------------------- |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
sub new |
137
|
|
|
|
|
|
|
{ |
138
|
1
|
|
|
1
|
0
|
14
|
my($caller, %arg) = @_; |
139
|
1
|
|
|
|
|
3
|
my($caller_is_obj) = ref($caller); |
140
|
1
|
|
33
|
|
|
10
|
my($class) = $caller_is_obj || $caller; |
141
|
1
|
|
|
|
|
37
|
my($self) = bless({}, $class); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
9
|
for my $attr_name ($self -> _standard_keys() ) |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
|
|
|
|
0
|
my($arg_name) = $attr_name =~ /^_(.*)/; |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
0
|
if (exists($arg{$arg_name}) ) |
|
|
0
|
|
|
|
|
|
148
|
|
|
|
|
|
|
{ |
149
|
0
|
|
|
|
|
0
|
$$self{$attr_name} = $arg{$arg_name}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
elsif ($caller_is_obj) |
152
|
|
|
|
|
|
|
{ |
153
|
0
|
|
|
|
|
0
|
$$self{$attr_name} = $$caller{$attr_name}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
else |
156
|
|
|
|
|
|
|
{ |
157
|
0
|
|
|
|
|
0
|
$$self{$attr_name} = $self -> _default_for($attr_name); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
1
|
|
|
|
|
5
|
return $self; |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} # End of new. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# ----------------------------------------------- |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub todays_date |
168
|
|
|
|
|
|
|
{ |
169
|
0
|
|
|
0
|
0
|
|
my($self) = @_; |
170
|
0
|
|
|
|
|
|
my(@now_time) = localtime(); |
171
|
0
|
|
|
|
|
|
my($now_year) = $now_time[5] + 1900; |
172
|
0
|
|
|
|
|
|
my($now_month) = $now_time[4] + 1; |
173
|
0
|
|
|
|
|
|
my($now_day) = $now_time[3]; |
174
|
0
|
|
|
|
|
|
my($then_year) = 2003; |
175
|
0
|
|
|
|
|
|
my($then_month) = 1; |
176
|
0
|
|
|
|
|
|
my($then_day) = 1; |
177
|
0
|
|
|
|
|
|
my($delta) = Delta_Days($then_year, $then_month, $then_day, $now_year, $now_month, $now_day); |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
|
$delta + 37622; # + 2003-01-01 in MS Access. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
} # End of todays_date. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# ----------------------------------------------- |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__ |