line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
2
|
|
|
|
|
|
|
package Date::Handler; |
3
|
|
|
|
|
|
|
|
4
|
8
|
|
|
8
|
|
899
|
use strict; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
341
|
|
5
|
8
|
|
|
8
|
|
42
|
use Carp; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
628
|
|
6
|
8
|
|
|
8
|
|
5678
|
use Data::Dumper; |
|
8
|
|
|
|
|
47037
|
|
|
8
|
|
|
|
|
549
|
|
7
|
8
|
|
|
8
|
|
62
|
use vars qw(@ISA $VERSION); |
|
8
|
|
|
|
|
15
|
|
|
8
|
|
|
|
|
679
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
$VERSION = '1.2'; |
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
21309
|
use POSIX qw(floor strftime mktime setlocale); |
|
8
|
|
|
|
|
72736
|
|
|
8
|
|
|
|
|
67
|
|
12
|
|
|
|
|
|
|
|
13
|
8
|
|
|
8
|
|
22454
|
use Date::Handler::Constants; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
1016
|
|
14
|
8
|
|
|
8
|
|
82
|
use constant DEFAULT_FORMAT_STRING => '%c'; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
751
|
|
15
|
8
|
|
|
8
|
|
42
|
use constant DEFAULT_TIMEZONE => 'GMT'; |
|
8
|
|
|
|
|
31
|
|
|
8
|
|
|
|
|
455
|
|
16
|
8
|
|
|
8
|
|
45
|
use constant DEFAULT_LOCALE => 'en_US'; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
323
|
|
17
|
|
|
|
|
|
|
|
18
|
8
|
|
|
8
|
|
38
|
use constant DELTA_CLASS => 'Date::Handler::Delta'; |
|
8
|
|
|
|
|
16
|
|
|
8
|
|
|
|
|
379
|
|
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
8
|
|
967
|
use constant INTUITIVE_MONTH_CALCULATIONS => 0; |
|
8
|
|
|
|
|
22
|
|
|
8
|
|
|
|
|
735
|
|
21
|
8
|
|
|
8
|
|
39
|
use constant INTUITIVE_TIME_CALCULATIONS => 0; |
|
8
|
|
|
|
|
14
|
|
|
8
|
|
|
|
|
408
|
|
22
|
8
|
|
|
8
|
|
40
|
use constant INTUITIVE_DST_ADJUSTMENTS => 0; |
|
8
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
1032
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
use overload ( |
25
|
|
|
|
|
|
|
'""' => 'AsScalar', |
26
|
|
|
|
|
|
|
'0+' => 'AsNumber', |
27
|
|
|
|
|
|
|
'+' => 'Add', |
28
|
|
|
|
|
|
|
'-' => 'Sub', |
29
|
|
|
|
|
|
|
'<=>' => 'Cmp', |
30
|
|
|
|
|
|
|
'++' => 'Incr', |
31
|
0
|
|
|
0
|
|
0
|
'*' => sub { croak "Cannot multiply an absolute date"; }, |
32
|
0
|
|
|
0
|
|
0
|
'**' => sub { croak "Cannot power an absolute date"; }, |
33
|
0
|
|
|
0
|
|
0
|
'/' => sub { croak "Cannot divide an absolute date"; }, |
34
|
8
|
|
|
|
|
127
|
fallback => 1, |
35
|
8
|
|
|
8
|
|
45
|
); |
|
8
|
|
|
|
|
14
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new |
39
|
|
|
|
|
|
|
{ |
40
|
499
|
|
|
499
|
0
|
5152
|
my $classname = shift; |
41
|
499
|
|
|
|
|
581
|
my $args = shift; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Allow classic style arguments passing. # Thanks to Roland Rauch for the spot |
45
|
499
|
50
|
|
|
|
1237
|
unless (ref($args) eq "HASH") |
46
|
|
|
|
|
|
|
{ |
47
|
0
|
|
|
|
|
0
|
unshift(@_, $args); |
48
|
0
|
|
|
|
|
0
|
$args = {@_}; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
499
|
|
|
|
|
817
|
my $self = {}; |
52
|
499
|
|
|
|
|
12632
|
bless $self, $classname; |
53
|
|
|
|
|
|
|
|
54
|
499
|
50
|
|
|
|
934
|
croak "No args to new()" if not defined $args; |
55
|
499
|
50
|
|
|
|
1617
|
croak "Argument to new() is not a hashref" if not ref($args) =~ /HASH/; |
56
|
499
|
50
|
|
|
|
1018
|
croak "No date specified for new()" if not defined $args->{date}; |
57
|
|
|
|
|
|
|
|
58
|
499
|
|
|
|
|
642
|
my $date = $args->{date}; |
59
|
|
|
|
|
|
|
|
60
|
499
|
|
66
|
|
|
1767
|
my $timezone = $args->{time_zone} || $self->DEFAULT_TIMEZONE(); |
61
|
499
|
|
|
|
|
989
|
$self->TimeZone($timezone); |
62
|
|
|
|
|
|
|
|
63
|
499
|
|
|
|
|
772
|
$self->{locale} = ""; |
64
|
499
|
50
|
|
|
|
1042
|
if(defined $args->{locale}) |
65
|
|
|
|
|
|
|
{ |
66
|
0
|
0
|
|
|
|
0
|
$self->SetLocale($args->{locale}) || $self->SetLocale($self->DEFAULT_LOCALE()); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
else |
69
|
|
|
|
|
|
|
{ |
70
|
499
|
|
|
|
|
1336
|
$self->SetLocale($self->DEFAULT_LOCALE()); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
499
|
50
|
|
|
|
1049
|
if(not defined $self->Locale()) |
74
|
|
|
|
|
|
|
{ |
75
|
0
|
|
|
|
|
0
|
warn "Impossible to set locale OR default locale correctly. Defaulting to GMT/UTC."; |
76
|
0
|
|
|
|
|
0
|
$self->SetLocale('GMT'); |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
499
|
50
|
|
|
|
2343
|
if(ref($date) =~ /SCALAR/) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
81
|
|
|
|
|
|
|
{ |
82
|
0
|
0
|
0
|
|
|
0
|
if($date !~ /\s/ && $date !~ /[A-Za-z]/) |
83
|
|
|
|
|
|
|
{ |
84
|
0
|
|
|
|
|
0
|
$self->{epoch} = $date; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
elsif(ref($date) =~ /ARRAY/) |
88
|
|
|
|
|
|
|
{ |
89
|
357
|
|
|
|
|
903
|
$self->{epoch} = $self->Array2Epoch($date); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
elsif(ref($date) =~ /HASH/) |
92
|
|
|
|
|
|
|
{ |
93
|
0
|
|
|
|
|
0
|
$self->{epoch} = $self->Array2Epoch([ |
94
|
|
|
|
|
|
|
$date->{year}, |
95
|
|
|
|
|
|
|
$date->{month}, |
96
|
|
|
|
|
|
|
$date->{day}, |
97
|
|
|
|
|
|
|
$date->{hour}, |
98
|
|
|
|
|
|
|
$date->{min}, |
99
|
|
|
|
|
|
|
$date->{sec}, |
100
|
|
|
|
|
|
|
]); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
else |
103
|
|
|
|
|
|
|
{ |
104
|
142
|
50
|
33
|
|
|
920
|
if($date !~ /\s/ && $date !~ /[A-Za-z]/) |
105
|
|
|
|
|
|
|
{ |
106
|
142
|
|
|
|
|
352
|
$self->{epoch} = $date; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
499
|
100
|
|
|
|
10585
|
$self->{_intuitive_day} = $args->{intuitive_day} if($self->INTUITIVE_MONTH_CALCULATIONS()); |
111
|
499
|
100
|
|
|
|
1477
|
$self->{_intuitive_hour} = $args->{intuitive_hour} if($self->INTUITIVE_TIME_CALCULATIONS()); |
112
|
|
|
|
|
|
|
|
113
|
499
|
50
|
|
|
|
1142
|
croak "Date format not recognized." if not defined $self->{epoch}; |
114
|
|
|
|
|
|
|
|
115
|
499
|
|
|
|
|
1594
|
return $self; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
#Accessors (Might want to optimised some of those) |
120
|
0
|
|
|
0
|
0
|
0
|
sub Year { return shift->AsArray()->[0]; } |
121
|
9
|
|
|
9
|
0
|
17
|
sub Day { return shift->AsArray()->[2]; } |
122
|
17
|
|
|
17
|
0
|
45
|
sub Hour { return shift->AsArray()->[3]; } |
123
|
0
|
|
|
0
|
0
|
0
|
sub Min { return shift->AsArray()->[4]; } |
124
|
0
|
|
|
0
|
0
|
0
|
sub Sec { return shift->AsArray()->[5]; } |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#To be consistent with our WeekDay function, wich is zero based. |
128
|
|
|
|
|
|
|
sub Month |
129
|
|
|
|
|
|
|
{ |
130
|
102
|
|
|
102
|
0
|
123
|
my $self = shift; |
131
|
|
|
|
|
|
|
|
132
|
102
|
|
|
|
|
171
|
local $ENV{'TZ'} = $self->TimeZone(); |
133
|
102
|
|
|
|
|
208
|
local $ENV{'LC_TIME'} = $self->Locale(); |
134
|
|
|
|
|
|
|
|
135
|
102
|
|
|
|
|
1264
|
return strftime('%m', localtime($self->{epoch})); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub Epoch |
139
|
|
|
|
|
|
|
{ |
140
|
476
|
|
|
476
|
1
|
553
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
476
|
100
|
|
|
|
884
|
if(@_) |
143
|
|
|
|
|
|
|
{ |
144
|
159
|
|
|
|
|
166
|
my $epoch = shift; |
145
|
|
|
|
|
|
|
|
146
|
159
|
|
|
|
|
260
|
$self->{epoch} = $epoch; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
476
|
|
|
|
|
799
|
return $self->{epoch}; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub TimeZone |
153
|
|
|
|
|
|
|
{ |
154
|
2387
|
|
|
2387
|
1
|
2823
|
my $self = shift; |
155
|
|
|
|
|
|
|
|
156
|
2387
|
100
|
|
|
|
4806
|
if(@_) |
157
|
|
|
|
|
|
|
{ |
158
|
499
|
|
|
|
|
642
|
my $time_zone = shift; |
159
|
499
|
|
|
|
|
1689
|
$self->{time_zone} = $time_zone; |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
2387
|
|
|
|
|
13737
|
return $self->{time_zone}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub Locale |
166
|
|
|
|
|
|
|
{ |
167
|
2103
|
|
|
2103
|
0
|
2593
|
my $self = shift; |
168
|
|
|
|
|
|
|
|
169
|
2103
|
50
|
|
|
|
4133
|
if(@_) |
170
|
|
|
|
|
|
|
{ |
171
|
0
|
|
|
|
|
0
|
warn "Calling Locale() with an argument to set the locale is deprecated. Please use SetLocale(locale) instead.\n"; |
172
|
|
|
|
|
|
|
|
173
|
0
|
|
|
|
|
0
|
return $self->SetLocale(@_); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
2103
|
|
|
|
|
8308
|
return $self->{locale}; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub SetLocale |
180
|
|
|
|
|
|
|
{ |
181
|
499
|
|
|
499
|
1
|
573
|
my $self = shift; |
182
|
499
|
|
|
|
|
709
|
my $locale = shift; |
183
|
|
|
|
|
|
|
|
184
|
499
|
50
|
|
|
|
942
|
croak "No locale passed to SetLocale()" if not defined $locale; |
185
|
|
|
|
|
|
|
|
186
|
499
|
|
|
|
|
4212
|
my $locale_return = POSIX::setlocale(&POSIX::LC_TIME, $locale); |
187
|
|
|
|
|
|
|
|
188
|
499
|
50
|
|
|
|
1054
|
if( defined $locale_return ) |
189
|
|
|
|
|
|
|
{ |
190
|
0
|
|
|
|
|
0
|
$self->{locale} = $locale; |
191
|
0
|
|
|
|
|
0
|
$self->{locale_realname} = $locale_return; |
192
|
|
|
|
|
|
|
|
193
|
0
|
|
|
|
|
0
|
return $self->{locale}; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
499
|
|
|
|
|
17291
|
print STDERR "Locale $locale does not seem to be implemented on this system, keeping locale ".$self->{locale}."\n"; |
197
|
499
|
|
|
|
|
8694
|
return undef; |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
sub LocaleRealName |
202
|
|
|
|
|
|
|
{ |
203
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
204
|
|
|
|
|
|
|
|
205
|
0
|
|
0
|
|
|
0
|
return $self->{locale_realname} || $self->DEFAULT_LOCALE(); |
206
|
|
|
|
|
|
|
} |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
#Time Conversion and info methods |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
sub TimeZoneName |
211
|
|
|
|
|
|
|
{ |
212
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
213
|
|
|
|
|
|
|
|
214
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
215
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
#Old code. |
218
|
|
|
|
|
|
|
#my ($std,$dst) = POSIX::tzname(); |
219
|
|
|
|
|
|
|
#return $std." / ".$dst; |
220
|
|
|
|
|
|
|
|
221
|
0
|
|
|
|
|
0
|
return strftime("%Z", localtime($self->{epoch}) ); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
sub LocalTime |
225
|
|
|
|
|
|
|
{ |
226
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
227
|
|
|
|
|
|
|
|
228
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
229
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
0
|
return localtime($self->{epoch}); |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
sub TimeFormat |
236
|
|
|
|
|
|
|
{ |
237
|
374
|
|
|
374
|
0
|
466
|
my $self = shift; |
238
|
374
|
|
|
|
|
375
|
my $format_string = shift; |
239
|
|
|
|
|
|
|
|
240
|
374
|
|
|
|
|
1114
|
local $ENV{'TZ'} = $self->TimeZone(); |
241
|
374
|
|
|
|
|
777
|
local $ENV{'LC_TIME'} = $self->Locale(); |
242
|
|
|
|
|
|
|
|
243
|
374
|
|
33
|
|
|
1943
|
$format_string ||= $self->DEFAULT_FORMAT_STRING(); |
244
|
|
|
|
|
|
|
|
245
|
374
|
|
|
|
|
5382
|
return strftime($format_string, localtime($self->{epoch})); |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub GmtTime |
250
|
|
|
|
|
|
|
{ |
251
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
252
|
|
|
|
|
|
|
|
253
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
254
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
255
|
|
|
|
|
|
|
|
256
|
0
|
|
|
|
|
0
|
return gmtime($self->{epoch}); |
257
|
|
|
|
|
|
|
} |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
sub UtcTime |
260
|
|
|
|
|
|
|
{ |
261
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
262
|
|
|
|
|
|
|
|
263
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
264
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
265
|
|
|
|
|
|
|
|
266
|
0
|
|
|
|
|
0
|
return gmtime($self->{epoch}); |
267
|
|
|
|
|
|
|
} |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
#Idea and base code for this function from: |
271
|
|
|
|
|
|
|
# Larry Rosler, February 13, 1999, Thanks Larry! - |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
sub GmtOffset |
274
|
|
|
|
|
|
|
{ |
275
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
278
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
#Old code. |
281
|
|
|
|
|
|
|
#use Time::Local; |
282
|
|
|
|
|
|
|
#my $gmt_time = timegm( gmtime $self->{epoch} ); |
283
|
|
|
|
|
|
|
#my $local_time = timelocal( gmtime $self->{epoch} ); |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
|
286
|
0
|
|
|
|
|
0
|
my $now = $self->Epoch(); |
287
|
|
|
|
|
|
|
|
288
|
0
|
|
|
|
|
0
|
my ($l_min, $l_hour, $l_year, $l_yday) = (localtime $now)[1, 2, 5, 7]; |
289
|
0
|
|
|
|
|
0
|
my ($g_min, $g_hour, $g_year, $g_yday) = (gmtime $now)[1, 2, 5, 7]; |
290
|
|
|
|
|
|
|
|
291
|
0
|
|
0
|
|
|
0
|
return (($l_min - $g_min)/60 + $l_hour - $g_hour + 24 * ($l_year - $g_year || $l_yday - $g_yday)) * 3600; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
#Useful methods |
296
|
|
|
|
|
|
|
sub MonthName |
297
|
|
|
|
|
|
|
{ |
298
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
299
|
|
|
|
|
|
|
|
300
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
301
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
302
|
|
|
|
|
|
|
|
303
|
0
|
|
|
|
|
0
|
return strftime('%B', localtime($self->{epoch})); |
304
|
|
|
|
|
|
|
} |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
sub WeekDay |
307
|
|
|
|
|
|
|
{ |
308
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
309
|
|
|
|
|
|
|
|
310
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
311
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
312
|
|
|
|
|
|
|
|
313
|
0
|
|
|
|
|
0
|
return strftime('%u', localtime($self->{epoch})); |
314
|
|
|
|
|
|
|
} |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
sub WeekDayName |
317
|
|
|
|
|
|
|
{ |
318
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
319
|
|
|
|
|
|
|
|
320
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
321
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
322
|
|
|
|
|
|
|
|
323
|
0
|
|
|
|
|
0
|
return strftime('%A', localtime($self->{epoch})); |
324
|
|
|
|
|
|
|
} |
325
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
sub FirstWeekDayOfMonth |
327
|
|
|
|
|
|
|
{ |
328
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
329
|
|
|
|
|
|
|
|
330
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
331
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
332
|
|
|
|
|
|
|
|
333
|
0
|
|
|
|
|
0
|
return (($self->WeekDay() - $self->Day() % 7) + 8) % 7; |
334
|
|
|
|
|
|
|
} |
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
sub WeekOfMonth |
337
|
|
|
|
|
|
|
{ |
338
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
339
|
|
|
|
|
|
|
|
340
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
341
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
342
|
|
|
|
|
|
|
|
343
|
0
|
|
|
|
|
0
|
return int(($self->Day() + $self->FirstWeekDayOfMonth() - 1) / 7) + 1; |
344
|
|
|
|
|
|
|
} |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
|
347
|
|
|
|
|
|
|
sub DaysInMonth |
348
|
|
|
|
|
|
|
{ |
349
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
350
|
|
|
|
|
|
|
|
351
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
352
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
353
|
|
|
|
|
|
|
|
354
|
0
|
|
|
|
|
0
|
my $month = $self->Month() - 1; |
355
|
|
|
|
|
|
|
|
356
|
0
|
0
|
|
|
|
0
|
if($month == 1) #Feb |
357
|
|
|
|
|
|
|
{ |
358
|
0
|
0
|
|
|
|
0
|
return 29 if $self->IsLeapYear(); |
359
|
0
|
|
|
|
|
0
|
return 28; |
360
|
|
|
|
|
|
|
} |
361
|
|
|
|
|
|
|
else |
362
|
|
|
|
|
|
|
{ |
363
|
0
|
|
|
|
|
0
|
return $DAYS_IN_MONTH->{$month}; |
364
|
|
|
|
|
|
|
} |
365
|
|
|
|
|
|
|
} |
366
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub DayLightSavings |
368
|
|
|
|
|
|
|
{ |
369
|
461
|
|
|
461
|
0
|
1315
|
my $self = shift; |
370
|
|
|
|
|
|
|
|
371
|
461
|
|
|
|
|
766
|
local $ENV{'TZ'} = $self->TimeZone(); |
372
|
461
|
|
|
|
|
999
|
local $ENV{'LC_TIME'} = $self->Locale(); |
373
|
|
|
|
|
|
|
|
374
|
461
|
|
|
|
|
1896
|
my @self_localtime = localtime($self->{epoch}); |
375
|
|
|
|
|
|
|
|
376
|
461
|
|
|
|
|
3502
|
return $self_localtime[8]; |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
sub DayOfYear |
380
|
|
|
|
|
|
|
{ |
381
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
382
|
|
|
|
|
|
|
|
383
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
384
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
385
|
|
|
|
|
|
|
|
386
|
0
|
|
|
|
|
0
|
my @self_localtime = localtime($self->{epoch}); |
387
|
|
|
|
|
|
|
|
388
|
0
|
|
|
|
|
0
|
return $self_localtime[7]; |
389
|
|
|
|
|
|
|
} |
390
|
|
|
|
|
|
|
|
391
|
|
|
|
|
|
|
sub DaysInYear |
392
|
|
|
|
|
|
|
{ |
393
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
394
|
|
|
|
|
|
|
|
395
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
396
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
397
|
|
|
|
|
|
|
|
398
|
0
|
0
|
|
|
|
0
|
return 365 if !$self->IsLeapYear(); |
399
|
0
|
0
|
|
|
|
0
|
return 366 if $self->IsLeapYear(); |
400
|
|
|
|
|
|
|
} |
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
sub DaysLeftInYear |
403
|
|
|
|
|
|
|
{ |
404
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
405
|
|
|
|
|
|
|
|
406
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
407
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
408
|
|
|
|
|
|
|
|
409
|
0
|
|
|
|
|
0
|
my $days = $self->DaysInYear(); |
410
|
0
|
|
|
|
|
0
|
my $day = $self->DayOfYear(); |
411
|
|
|
|
|
|
|
|
412
|
0
|
|
|
|
|
0
|
return $days - $day; |
413
|
|
|
|
|
|
|
} |
414
|
|
|
|
|
|
|
|
415
|
|
|
|
|
|
|
sub LastDayOfMonth |
416
|
|
|
|
|
|
|
{ |
417
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
418
|
|
|
|
|
|
|
|
419
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
420
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
421
|
|
|
|
|
|
|
|
422
|
0
|
0
|
|
|
|
0
|
if($self->Day() >= $self->DaysInMonth()) |
423
|
|
|
|
|
|
|
{ |
424
|
0
|
|
|
|
|
0
|
return 1; |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
} |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
sub IsLeapYear |
430
|
|
|
|
|
|
|
{ |
431
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
432
|
|
|
|
|
|
|
|
433
|
0
|
|
|
|
|
0
|
local $ENV{'TZ'} = $self->TimeZone(); |
434
|
0
|
|
|
|
|
0
|
local $ENV{'LC_TIME'} = $self->Locale(); |
435
|
|
|
|
|
|
|
|
436
|
0
|
|
|
|
|
0
|
my $year = $self->Year(); |
437
|
|
|
|
|
|
|
|
438
|
0
|
0
|
|
|
|
0
|
return 1 if( !($year % 400) ); |
439
|
0
|
0
|
0
|
|
|
0
|
return 1 if( !($year %4) && ($year % 100) ); |
440
|
0
|
|
|
|
|
0
|
return 0; |
441
|
|
|
|
|
|
|
} |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
sub IntuitiveDay |
444
|
|
|
|
|
|
|
{ |
445
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
446
|
0
|
|
|
|
|
0
|
my $intuitive_day = shift; |
447
|
|
|
|
|
|
|
|
448
|
0
|
0
|
|
|
|
0
|
if($intuitive_day) |
449
|
|
|
|
|
|
|
{ |
450
|
0
|
|
|
|
|
0
|
$self->{_intuitive_day} = $intuitive_day; |
451
|
|
|
|
|
|
|
} |
452
|
0
|
|
|
|
|
0
|
return $self->{_intuitive_day}; |
453
|
|
|
|
|
|
|
} |
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
sub IntuitiveHour |
456
|
|
|
|
|
|
|
{ |
457
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
458
|
0
|
|
|
|
|
0
|
my $intuitive_hour = shift; |
459
|
|
|
|
|
|
|
|
460
|
0
|
0
|
|
|
|
0
|
if($intuitive_hour) |
461
|
|
|
|
|
|
|
{ |
462
|
0
|
|
|
|
|
0
|
$self->{_intuitive_hour} = $intuitive_hour; |
463
|
|
|
|
|
|
|
} |
464
|
0
|
|
|
|
|
0
|
return $self->{_intuitive_hour}; |
465
|
|
|
|
|
|
|
} |
466
|
|
|
|
|
|
|
|
467
|
|
|
|
|
|
|
sub Array2Epoch |
468
|
|
|
|
|
|
|
{ |
469
|
357
|
|
|
357
|
0
|
372
|
my $self = shift; |
470
|
357
|
|
|
|
|
378
|
my $input = shift; |
471
|
|
|
|
|
|
|
|
472
|
357
|
|
|
|
|
410
|
my ($y,$m,$d,$h,$mm,$ss) = @{$input}[0,1,2,3,4,5]; |
|
357
|
|
|
|
|
824
|
|
473
|
|
|
|
|
|
|
|
474
|
357
|
|
|
|
|
674
|
local $ENV{'TZ'} = $self->TimeZone(); |
475
|
357
|
|
|
|
|
727
|
local $ENV{'LC_TIME'} = $self->Locale(); |
476
|
|
|
|
|
|
|
|
477
|
357
|
|
100
|
|
|
7452
|
return mktime( |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
50
|
|
|
|
|
478
|
|
|
|
|
|
|
$ss || 0, |
479
|
|
|
|
|
|
|
$mm || 0, |
480
|
|
|
|
|
|
|
$h || 0, |
481
|
|
|
|
|
|
|
$d || 1, |
482
|
|
|
|
|
|
|
($m || 1)-1, |
483
|
|
|
|
|
|
|
($y || 2000)-1900, |
484
|
|
|
|
|
|
|
0, |
485
|
|
|
|
|
|
|
0, |
486
|
|
|
|
|
|
|
-1); |
487
|
|
|
|
|
|
|
} |
488
|
|
|
|
|
|
|
|
489
|
|
|
|
|
|
|
|
490
|
|
|
|
|
|
|
#Oveload methods. |
491
|
|
|
|
|
|
|
|
492
|
374
|
|
|
374
|
0
|
3882
|
sub AsScalar { return shift->TimeFormat(shift); } |
493
|
0
|
|
|
0
|
0
|
0
|
sub AsNumber { return shift->{epoch}; } |
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
sub AsArray |
496
|
|
|
|
|
|
|
{ |
497
|
168
|
|
|
168
|
0
|
213
|
my $self = shift; |
498
|
|
|
|
|
|
|
|
499
|
168
|
|
|
|
|
323
|
local $ENV{'TZ'} = $self->TimeZone(); |
500
|
168
|
|
|
|
|
355
|
local $ENV{'LC_TIME'} = $self->Locale(); |
501
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
|
503
|
168
|
|
|
|
|
727
|
my ($ss,$mm,$h,$d,$m,$y) = localtime($self->{epoch}); |
504
|
168
|
|
|
|
|
294
|
$y += 1900; |
505
|
168
|
|
|
|
|
197
|
$m += 1; |
506
|
|
|
|
|
|
|
|
507
|
168
|
|
|
|
|
1092
|
return [$y,$m,$d,$h,$mm,$ss]; |
508
|
|
|
|
|
|
|
} |
509
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
sub AsHash |
511
|
|
|
|
|
|
|
{ |
512
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
513
|
|
|
|
|
|
|
|
514
|
0
|
|
|
|
|
0
|
my $self_array = $self->AsArray(); |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
return { |
517
|
0
|
|
|
|
|
0
|
year => $self_array->[0], |
518
|
|
|
|
|
|
|
month => $self_array->[1], |
519
|
|
|
|
|
|
|
day => $self_array->[2], |
520
|
|
|
|
|
|
|
hour => $self_array->[3], |
521
|
|
|
|
|
|
|
min => $self_array->[4], |
522
|
|
|
|
|
|
|
sec => $self_array->[5], |
523
|
|
|
|
|
|
|
}; |
524
|
|
|
|
|
|
|
} |
525
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
sub Add |
528
|
|
|
|
|
|
|
{ |
529
|
142
|
|
|
142
|
0
|
234
|
my ($self, $delta) = @_; |
530
|
|
|
|
|
|
|
|
531
|
142
|
50
|
|
|
|
815
|
if(!ref($delta)) |
|
|
50
|
|
|
|
|
|
532
|
|
|
|
|
|
|
{ |
533
|
0
|
|
|
|
|
0
|
$delta = $self->DELTA_CLASS()->new([0,0,0,0,0,$delta]); |
534
|
0
|
|
|
|
|
0
|
return $self + $delta; |
535
|
|
|
|
|
|
|
} |
536
|
|
|
|
|
|
|
elsif($delta->isa($self->DELTA_CLASS())) |
537
|
|
|
|
|
|
|
{ |
538
|
142
|
|
|
|
|
326
|
local $ENV{'TZ'} = $self->TimeZone(); |
539
|
142
|
|
|
|
|
468
|
local $ENV{'LC_TIME'} = $self->Locale(); |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
|
542
|
142
|
|
|
|
|
257
|
my $epoch = $self->{epoch}; |
543
|
|
|
|
|
|
|
|
544
|
142
|
|
|
|
|
326
|
my $newdate = ref($self)->new({ date => $epoch, time_zone => $self->TimeZone() }); |
545
|
|
|
|
|
|
|
|
546
|
142
|
|
|
|
|
488
|
my $self_array = $newdate->AsArray(); |
547
|
|
|
|
|
|
|
#Take care of the months. |
548
|
142
|
|
|
|
|
528
|
$self_array->[1] += $delta->Months(); |
549
|
|
|
|
|
|
|
|
550
|
142
|
|
|
|
|
540
|
my $years = floor(($self_array->[1]-1)/12); |
551
|
142
|
|
|
|
|
238
|
$self_array->[1] -= 12*$years; |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
#Take care of the years. |
554
|
142
|
|
|
|
|
184
|
$self_array->[0] += $years; |
555
|
|
|
|
|
|
|
|
556
|
142
|
|
|
|
|
340
|
my $posix_date = ref($self)->new({ date => $self_array, |
557
|
|
|
|
|
|
|
time_zone => $self->TimeZone(), |
558
|
|
|
|
|
|
|
}); |
559
|
|
|
|
|
|
|
|
560
|
142
|
100
|
|
|
|
602
|
if($self->INTUITIVE_MONTH_CALCULATIONS()) |
561
|
|
|
|
|
|
|
{ |
562
|
51
|
100
|
|
|
|
105
|
if((($self->Month() + $delta->Months() - 1) % 12 + 1) != $posix_date->Month()) |
563
|
|
|
|
|
|
|
{ |
564
|
3
|
|
|
|
|
14
|
my $compensation_seconds = 86400 * $posix_date->Day(); |
565
|
3
|
|
|
|
|
13
|
my $compensated_epoch = $posix_date->Epoch(); |
566
|
|
|
|
|
|
|
|
567
|
3
|
|
|
|
|
6
|
$compensated_epoch -= $compensation_seconds; |
568
|
|
|
|
|
|
|
|
569
|
3
|
|
|
|
|
7
|
$posix_date->Epoch($compensated_epoch); |
570
|
|
|
|
|
|
|
|
571
|
3
|
|
33
|
|
|
12
|
$posix_date->{_intuitive_day} = $self->{_intuitive_day} || $self->Day(); |
572
|
|
|
|
|
|
|
} |
573
|
|
|
|
|
|
|
else |
574
|
|
|
|
|
|
|
{ |
575
|
48
|
100
|
|
|
|
123
|
if($self->{_intuitive_day}) |
576
|
|
|
|
|
|
|
{ |
577
|
3
|
|
|
|
|
5
|
my $lastdayofmonth = $self->{_intuitive_day}; |
578
|
3
|
|
|
|
|
8
|
my $compensated_seconds = 86400 * ($lastdayofmonth - $posix_date->Day()); |
579
|
3
|
50
|
|
|
|
10
|
if($compensated_seconds > 0) |
580
|
|
|
|
|
|
|
{ |
581
|
3
|
|
|
|
|
6
|
my $epoch = $posix_date->Epoch(); |
582
|
3
|
|
|
|
|
6
|
$epoch += $compensated_seconds; |
583
|
3
|
|
|
|
|
5
|
$posix_date->Epoch($epoch); |
584
|
|
|
|
|
|
|
} |
585
|
|
|
|
|
|
|
|
586
|
3
|
50
|
|
|
|
10
|
if($self->{_intuitive_day} > $lastdayofmonth) |
587
|
|
|
|
|
|
|
{ |
588
|
0
|
|
|
|
|
0
|
$posix_date->{_intuitive_day} = $self->{_intuitive_day}; |
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
} |
592
|
|
|
|
|
|
|
} |
593
|
|
|
|
|
|
|
} |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
#Take care of the seconds |
596
|
142
|
|
|
|
|
344
|
my $posix_epoch = $posix_date->Epoch(); |
597
|
142
|
|
|
|
|
423
|
$posix_epoch += $delta->Seconds(); |
598
|
142
|
|
|
|
|
390
|
$posix_date->Epoch($posix_epoch); |
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
|
601
|
142
|
|
|
|
|
237
|
my $adjustment_epoch = $posix_date->Epoch(); |
602
|
142
|
|
|
|
|
171
|
my $add_intuitive_hour = 0; |
603
|
142
|
|
|
|
|
157
|
my $intuitive_hour; |
604
|
|
|
|
|
|
|
|
605
|
142
|
100
|
100
|
|
|
4453
|
if($posix_date->DayLightSavings() && !$self->DayLightSavings()) |
|
|
100
|
100
|
|
|
|
|
606
|
|
|
|
|
|
|
{ |
607
|
4
|
|
|
|
|
27
|
my $posix_hour = $posix_date->Hour(); |
608
|
4
|
|
|
|
|
10
|
$posix_hour -= 1; |
609
|
4
|
|
|
|
|
6
|
$intuitive_hour = $posix_hour; |
610
|
|
|
|
|
|
|
|
611
|
4
|
50
|
|
|
|
20
|
if($self->INTUITIVE_DST_ADJUSTMENTS()) |
612
|
|
|
|
|
|
|
{ |
613
|
4
|
|
|
|
|
7
|
$adjustment_epoch -= 3600; |
614
|
4
|
|
|
|
|
9
|
$posix_date->Epoch($adjustment_epoch); |
615
|
|
|
|
|
|
|
|
616
|
4
|
50
|
|
|
|
12
|
$posix_hour = 0 if $posix_hour == 24; |
617
|
4
|
100
|
|
|
|
11
|
if($posix_date->Hour() != $posix_hour) |
618
|
|
|
|
|
|
|
{ |
619
|
2
|
|
|
|
|
4
|
$add_intuitive_hour = 1; |
620
|
2
|
|
|
|
|
2
|
$adjustment_epoch += 3600; |
621
|
2
|
|
|
|
|
5
|
$posix_date->Epoch($adjustment_epoch); |
622
|
|
|
|
|
|
|
} |
623
|
|
|
|
|
|
|
} |
624
|
|
|
|
|
|
|
} |
625
|
|
|
|
|
|
|
elsif(!$posix_date->DayLightSavings() && $self->DayLightSavings()) |
626
|
|
|
|
|
|
|
{ |
627
|
|
|
|
|
|
|
|
628
|
4
|
|
|
|
|
13
|
my $posix_hour = $posix_date->Hour(); |
629
|
4
|
|
|
|
|
12
|
$posix_hour += 1; |
630
|
4
|
|
|
|
|
6
|
$intuitive_hour = $posix_hour; |
631
|
|
|
|
|
|
|
|
632
|
4
|
50
|
|
|
|
18
|
if($self->INTUITIVE_DST_ADJUSTMENTS()) |
633
|
|
|
|
|
|
|
{ |
634
|
4
|
|
|
|
|
6
|
$adjustment_epoch += 3600; |
635
|
4
|
|
|
|
|
14
|
$posix_date->Epoch($adjustment_epoch); |
636
|
|
|
|
|
|
|
|
637
|
4
|
100
|
|
|
|
12
|
$posix_hour = 0 if $posix_hour == 24; |
638
|
4
|
50
|
|
|
|
25
|
if($posix_date->Hour() != $posix_hour) |
639
|
|
|
|
|
|
|
{ |
640
|
0
|
|
|
|
|
0
|
$add_intuitive_hour = 1; |
641
|
0
|
|
|
|
|
0
|
$adjustment_epoch -= 3600; |
642
|
0
|
|
|
|
|
0
|
$posix_date->Epoch($adjustment_epoch); |
643
|
|
|
|
|
|
|
} |
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
} |
646
|
|
|
|
|
|
|
|
647
|
142
|
100
|
|
|
|
480
|
if($self->INTUITIVE_TIME_CALCULATIONS()) |
648
|
|
|
|
|
|
|
{ |
649
|
51
|
100
|
|
|
|
104
|
if($add_intuitive_hour) |
650
|
|
|
|
|
|
|
{ |
651
|
2
|
|
|
|
|
3
|
$posix_date->{_intuitive_hour} = $intuitive_hour; |
652
|
|
|
|
|
|
|
} |
653
|
|
|
|
|
|
|
|
654
|
51
|
100
|
|
|
|
254
|
if(defined $self->{_intuitive_hour}) |
655
|
|
|
|
|
|
|
{ |
656
|
1
|
|
|
|
|
3
|
my $hour = $posix_date->Hour(); |
657
|
1
|
|
|
|
|
4
|
my $intuitive_epoch = $posix_date->Epoch(); |
658
|
|
|
|
|
|
|
|
659
|
1
|
50
|
|
|
|
5
|
if($hour > $self->{_intuitive_hour}) |
660
|
|
|
|
|
|
|
{ |
661
|
1
|
|
|
|
|
2
|
$intuitive_epoch -= 3600; |
662
|
1
|
|
|
|
|
4
|
$posix_date->Epoch($intuitive_epoch); |
663
|
|
|
|
|
|
|
} |
664
|
|
|
|
|
|
|
#elsif($hour < $self->{_intuitive_hour}) |
665
|
|
|
|
|
|
|
#{ |
666
|
|
|
|
|
|
|
# print STDERR "Intuitive Adjust +1 hour\n"; |
667
|
|
|
|
|
|
|
# $intuitive_epoch += 3600; |
668
|
|
|
|
|
|
|
# $posix_date->Epoch($intuitive_epoch); |
669
|
|
|
|
|
|
|
#} |
670
|
|
|
|
|
|
|
} |
671
|
|
|
|
|
|
|
} |
672
|
|
|
|
|
|
|
|
673
|
142
|
|
|
|
|
2778
|
return $posix_date; |
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
else |
677
|
|
|
|
|
|
|
{ |
678
|
0
|
|
|
|
|
0
|
croak "Trying to add/substract an unknown object to a Date::Handler"; |
679
|
|
|
|
|
|
|
} |
680
|
|
|
|
|
|
|
} |
681
|
|
|
|
|
|
|
|
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
sub Sub |
684
|
|
|
|
|
|
|
{ |
685
|
47
|
|
|
47
|
0
|
73
|
my ($self, $delta) = @_; |
686
|
|
|
|
|
|
|
|
687
|
47
|
50
|
|
|
|
353
|
if(!ref($delta)) |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
688
|
|
|
|
|
|
|
{ |
689
|
0
|
|
|
|
|
0
|
$delta = $self->DELTA_CLASS()->new([0,0,0,0,0,$delta]); |
690
|
0
|
|
|
|
|
0
|
return $self - $delta; |
691
|
|
|
|
|
|
|
} |
692
|
|
|
|
|
|
|
elsif($delta->isa($self->DELTA_CLASS())) |
693
|
|
|
|
|
|
|
{ |
694
|
34
|
|
|
|
|
117
|
return $self->Add(-$delta); |
695
|
|
|
|
|
|
|
} |
696
|
|
|
|
|
|
|
elsif($delta->isa('Date::Handler')) |
697
|
|
|
|
|
|
|
{ |
698
|
|
|
|
|
|
|
|
699
|
13
|
|
|
|
|
27
|
my $seconds = $self->Epoch() - $delta->Epoch(); |
700
|
|
|
|
|
|
|
|
701
|
13
|
50
|
33
|
|
|
26
|
if(($self->DayLightSavings() && !$delta->DayLightSavings()) || |
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
702
|
|
|
|
|
|
|
!$self->DayLightSavings() && $delta->DayLightSavings()) |
703
|
|
|
|
|
|
|
{ |
704
|
0
|
|
|
|
|
0
|
$seconds += 3600; |
705
|
|
|
|
|
|
|
} |
706
|
|
|
|
|
|
|
|
707
|
13
|
|
|
|
|
57
|
return $self->DELTA_CLASS()->new($seconds); |
708
|
|
|
|
|
|
|
} |
709
|
|
|
|
|
|
|
else |
710
|
|
|
|
|
|
|
{ |
711
|
0
|
|
|
|
|
|
croak "Cannot substract something else than a ".$self->DELTA_CLASS()." or Date::Handler or constant from a Date::Handler"; |
712
|
|
|
|
|
|
|
} |
713
|
|
|
|
|
|
|
} |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
sub Cmp |
717
|
|
|
|
|
|
|
{ |
718
|
0
|
|
|
0
|
0
|
|
my ($self, $date, $reverse) = @_; |
719
|
|
|
|
|
|
|
|
720
|
0
|
|
|
|
|
|
my $cmp_date; |
721
|
|
|
|
|
|
|
|
722
|
0
|
0
|
|
|
|
|
if(!ref($date)) |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
723
|
|
|
|
|
|
|
{ |
724
|
0
|
|
|
|
|
|
$cmp_date = $date; |
725
|
|
|
|
|
|
|
} |
726
|
|
|
|
|
|
|
elsif($date->isa('Date::Handler')) |
727
|
|
|
|
|
|
|
{ |
728
|
0
|
|
|
|
|
|
$cmp_date = $date->{epoch}; |
729
|
|
|
|
|
|
|
} |
730
|
|
|
|
|
|
|
elsif($date->isa($self->DELTA_CLASS())) |
731
|
|
|
|
|
|
|
{ |
732
|
0
|
|
|
|
|
|
croak "Cannot compare a Date::Handler to a Delta."; |
733
|
|
|
|
|
|
|
} |
734
|
|
|
|
|
|
|
else |
735
|
|
|
|
|
|
|
{ |
736
|
0
|
|
|
|
|
|
croak "Trying to compare a Date::Handler to an unknown object."; |
737
|
|
|
|
|
|
|
} |
738
|
|
|
|
|
|
|
|
739
|
0
|
|
|
|
|
|
return $self->{epoch} <=> $cmp_date; |
740
|
|
|
|
|
|
|
} |
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
sub Incr |
743
|
|
|
|
|
|
|
{ |
744
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
745
|
|
|
|
|
|
|
|
746
|
0
|
|
|
|
|
|
my $epoch = $self->{epoch}; |
747
|
0
|
|
|
|
|
|
$epoch++; |
748
|
|
|
|
|
|
|
|
749
|
0
|
|
|
|
|
|
return ref($self)->new({ date => $epoch, time_zone => $self->TimeZone() }); |
750
|
|
|
|
|
|
|
} |
751
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
|
753
|
|
|
|
|
|
|
sub AllInfo |
754
|
|
|
|
|
|
|
{ |
755
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
756
|
0
|
|
|
|
|
|
my $out_string; |
757
|
|
|
|
|
|
|
|
758
|
0
|
|
|
|
|
|
local $ENV{'TZ'} = $self->TimeZone(); |
759
|
0
|
|
|
|
|
|
local $ENV{'LC_TIME'} = $self->Locale(); |
760
|
|
|
|
|
|
|
|
761
|
0
|
|
|
|
|
|
$out_string .= "LocalTime: ".$self->LocalTime()."\n"; |
762
|
0
|
|
|
|
|
|
$out_string .= "TimeFormat: ".$self->TimeFormat()."\n"; |
763
|
0
|
|
|
|
|
|
$out_string .= "Epoch: ".$self->Epoch()."\n"; |
764
|
0
|
|
|
|
|
|
$out_string .= "Locale: ".$self->Locale()."\n"; |
765
|
0
|
|
|
|
|
|
$out_string .= "LocaleRealName: ".$self->LocaleRealName()."\n"; |
766
|
0
|
|
|
|
|
|
$out_string .= "TimeZone: ".$self->TimeZone()." (".$self->TimeZoneName().")\n"; |
767
|
0
|
|
|
|
|
|
$out_string .= "DayLightSavings: ".$self->DayLightSavings()."\n"; |
768
|
0
|
|
|
|
|
|
$out_string .= "GMT Time: ".$self->GmtTime()."\n"; |
769
|
0
|
|
|
|
|
|
$out_string .= "GmtOffset: ".$self->GmtOffset()." (".($self->GmtOffset() / 60 / 60).")\n"; |
770
|
0
|
|
|
|
|
|
$out_string .= "Year: ".$self->Year()."\n"; |
771
|
0
|
|
|
|
|
|
$out_string .= "Month: ".$self->Month()."\n"; |
772
|
0
|
|
|
|
|
|
$out_string .= "Day: ".$self->Day()."\n"; |
773
|
0
|
|
|
|
|
|
$out_string .= "Hour: ".$self->Hour()."\n"; |
774
|
0
|
|
|
|
|
|
$out_string .= "Min: ".$self->Min()."\n"; |
775
|
0
|
|
|
|
|
|
$out_string .= "Sec: ".$self->Sec()."\n"; |
776
|
0
|
|
|
|
|
|
$out_string .= "WeekDay: ".$self->WeekDay()."\n"; |
777
|
0
|
|
|
|
|
|
$out_string .= "WeekDayName: ".$self->WeekDayName()."\n"; |
778
|
0
|
|
|
|
|
|
$out_string .= "FirstWeekDayOfMonth: ".$self->FirstWeekDayOfMonth()."\n"; |
779
|
0
|
|
|
|
|
|
$out_string .= "WeekOfMonth: ".$self->WeekOfMonth()."\n"; |
780
|
0
|
|
|
|
|
|
$out_string .= "DayOfYear: ".$self->DayOfYear()."\n"; |
781
|
0
|
|
|
|
|
|
$out_string .= "MonthName: ".$self->MonthName()."\n"; |
782
|
0
|
|
|
|
|
|
$out_string .= "DaysInMonth: ".$self->DaysInMonth()."\n"; |
783
|
0
|
|
|
|
|
|
$out_string .= "Leap Year: ".$self->IsLeapYear()."\n"; |
784
|
0
|
|
|
|
|
|
$out_string .= "DaysInYear: ".$self->DaysInYear()."\n"; |
785
|
0
|
|
|
|
|
|
$out_string .= "DaysLeftInYear: ".$self->DaysLeftInYear()."\n"; |
786
|
0
|
|
|
|
|
|
$out_string .= "Intuitive Day: ".$self->IntuitiveDay()."\n"; |
787
|
0
|
|
|
|
|
|
$out_string .= "Intuitive Hour: ".$self->IntuitiveHour()."\n"; |
788
|
0
|
|
|
|
|
|
$out_string .= "\n\n"; |
789
|
0
|
|
|
|
|
|
return $out_string; |
790
|
|
|
|
|
|
|
} |
791
|
|
|
|
|
|
|
|
792
|
|
|
|
|
|
|
666; |
793
|
|
|
|
|
|
|
__END__ |