File Coverage

blib/lib/Date/Object.pm
Criterion Covered Total %
statement 497 1030 48.2
branch 211 618 34.1
condition 103 314 32.8
subroutine 66 164 40.2
pod 75 141 53.1
total 952 2267 41.9


line stmt bran cond sub pod time code
1             #############################################################################
2             ## This file was generated automatically by Class::HPLOO/0.18
3             ##
4             ## Original file: ./lib/Date/Object.hploo
5             ## Generation date: 2005-01-05 20:52:25
6             ##
7             ## ** Do not change this file, use the original HPLOO source! **
8             #############################################################################
9            
10             #############################################################################
11             ## Name: Object.pm
12             ## Purpose: Date::Object
13             ## Author: Graciliano M. P.
14             ## Modified by:
15             ## Created: 2004-03-19
16             ## RCS-ID:
17             ## Copyright: (c) 2004 Graciliano M. P.
18             ## Licence: This program is free software; you can redistribute it and/or
19             ## modify it under the same terms as Perl itself
20             #############################################################################
21            
22            
23 8     8   2016832 sub Date::O { Date::Object->new(@_) ;}
24 838     838   13771 sub Date::O_gmt { Date::Object->new_gmt(@_) ;}
25 4     4   112170 sub Date::O_local { Date::Object->new_local(@_) ;}
26 8     8   265 sub Date::O_zone { Date::Object->new_zone(@_) ;}
27 0     0   0 sub Date::check { Date::Object::check(@_) ;}
28 0     0   0 sub Date::timelocal { Date::Object::timelocal(@_) ;}
29            
30             { package Date::Object ;
31            
32 1     1   6185 use strict qw(vars) ; no warnings ;
  1     1   5  
  1         40  
  1         5  
  1         2  
  1         43  
33            
34 1     1   4 use vars qw(%CLASS_HPLOO @ISA $VERSION) ;
  1         5  
  1         207  
35            
36             $VERSION = '0.06' ;
37            
38             @ISA = qw(Class::HPLOO::Base UNIVERSAL) ;
39            
40 0     0   0 my $CLASS = 'Date::Object' ; sub __CLASS__ { 'Date::Object' } ;
41            
42             sub new {
43 913 50 33 913 0 2655 if ( !defined &Object && @ISA > 1 ) {
44 0         0 foreach my $ISA_i ( @ISA ) {
45 0 0       0 return &{"$ISA_i\::new"}(@_) if defined &{"$ISA_i\::new"} ;
  0         0  
  0         0  
46 913         1125 } } my $class = shift ;
47 913 50       1766 $class = ref($class) if ref($class) ;
48 913         1604 my $this = new_call_BEGIN($class , @_) ;
49 913 50 33     3363 $this = bless({} , $class) if !ref($this) || !UNIVERSAL::isa($this,$class) ;
50 1     1   5 no warnings ;
  1         2  
  1         4655  
51 913         1088 my $undef = \'' ;
52 0     0 0 0 sub UNDEF {$undef} ;
53 913 50       1982 if ( $CLASS_HPLOO{ATTR} ) {
54 913 50       1369 CLASS_HPLOO_TIE_KEYS($this) } my $ret_this = defined &Object ? $this->Object(@_) : undef ;
  913         4761  
55 913 50 33     4951 if ( ref($ret_this) && UNIVERSAL::isa($ret_this,$class) ) {
    0          
56 913         1083 $this = $ret_this ;
57 913 50 33     4418 if ( $CLASS_HPLOO{ATTR} && UNIVERSAL::isa($this,'HASH') ) {
58 913         1451 CLASS_HPLOO_TIE_KEYS($this) } } elsif ( $ret_this == $undef ) {
59 0         0 $this = undef } new_call_END($this,@_) ;
  913         3328  
60 913         2868 return $this ;
61             } sub CLASS_HPLOO_TIE_KEYS {
62 1826     1826 0 2143 my $this = shift ;
63 1826 50       3805 if ( $CLASS_HPLOO{ATTR} ) {
64 1826         1748 foreach my $Key ( keys %{$CLASS_HPLOO{ATTR}} ) {
  1826         9328  
65 47476 100       203957 tie( $this->{$Key} => 'Date::Object::HPLOO_TIESCALAR' , $this , $Key , $CLASS_HPLOO{ATTR}{$Key}{tp} , $CLASS_HPLOO{ATTR}{$Key}{pr} , \$this->{CLASS_HPLOO_ATTR}{$Key} , \$this->{CLASS_HPLOO_CHANGED} , 'Date::Object' ) if !exists $this->{$Key} ;
66             } } } sub SUPER {
67 0         0 eval('package Class::HPLOO::Base ;
68 0 0   0 0 0 ') if !defined *{'Class::HPLOO::Base::'} ;
69 0         0 my ($prev_pack , undef , undef , $sub0) = caller(1) ;
70 0 0       0 $prev_pack = undef if $prev_pack eq 'Class::HPLOO::Base' ;
71 0         0 my ($pack,$sub) = ( $sub0 =~ /^(?:(.*?)::|)(\w+)$/ );
72 0 0       0 my $sub_is_new_hploo = $sub0 =~ /^(.*?(?:::)?$sub)\::$sub$/ ? 1 : undef ;
73 0 0 0     0 unshift(@_ , $prev_pack) if ( $sub_is_new_hploo && $prev_pack && ((!ref($_[0]) && $_[0] ne $prev_pack && !UNIVERSAL::isa($_[0] , $prev_pack)) || (ref($_[0]) && !UNIVERSAL::isa($_[0] , $prev_pack)) ) ) ;
      0        
      0        
74 0 0       0 if ( defined @{"$pack\::ISA"} ) {
  0         0  
75 0 0       0 my $isa_sub = ISA_FIND_NEW($pack, ($sub_is_new_hploo?'new':$sub) ,1) ;
76 0         0 my ($sub_name) = ( $isa_sub =~ /(\w+)$/gi );
77 0 0 0     0 if ( $sub0 ne $isa_sub && !ref($_[0]) && $isa_sub =~ /^(.*?(?:::)?$sub_name)\::$sub_name$/ ) {
      0        
78 0         0 @_ = ( bless({},$_[0]) , @_[1..$#_] ) ;
79 0 0 0     0 } if ( $sub0 eq $isa_sub && UNIVERSAL::isa($_[0] , $pack) ) {
80 0         0 my @isa = Class::HPLOO::Base::FIND_SUPER_WALK( ref($_[0]) , $pack ) ;
81 0         0 my $pk = $isa[-1] ;
82 0 0       0 if ( $sub_is_new_hploo ) {
83 0 0       0 if ( UNIVERSAL::isa($pk , 'Class::HPLOO::Base') ) {
84 0         0 ($sub) = ( $pk =~ /(\w+)$/gi );
85             } else {
86 0         0 $sub = 'new' ;
87 0         0 } } my $isa_sub = $pk->can($sub) ;
88 0 0       0 return &$isa_sub( ARGS_WRAPPER(@_) ) if $isa_sub ;
89 0 0 0     0 } return &$isa_sub(@_) if $isa_sub && defined &$isa_sub && $sub0 ne $isa_sub ;
      0        
90 0 0       0 } $sub = $sub_is_new_hploo ? 'new' : $sub ;
91 0 0       0 die("Can't find SUPER method for $sub0!") if "$pack\::$sub" eq $sub0 ;
92 0         0 return &{"$pack\::$sub"}(@_) ;
  0         0  
93             } sub FIND_SUPER_WALK {
94 0     0 0 0 my $class_main = shift ;
95 0         0 my $class_end = shift ;
96 0         0 my $only_stak = shift ;
97 0         0 my (@stack) ;
98 0   0     0 my $stack = $only_stak || {} ;
99 0         0 my $found ;
100 0         0 foreach my $isa_i ( @{"$class_main\::ISA"} ) {
  0         0  
101 0 0       0 next if $$stack{$isa_i}++ ;
102 0 0       0 $found = 1 if $isa_i eq $class_end ;
103 0         0 push(@stack , $isa_i , FIND_SUPER_WALK($isa_i , $class_end , $stack) );
104 0 0       0 } return ($found ? @stack : ()) if $only_stak ;
    0          
105 0         0 return @stack ;
106             } sub ISA_FIND_NEW {
107 0     0 0 0 my $pack = shift ;
108 0         0 my $sub = shift ;
109 0         0 my $look_deep = shift ;
110 0         0 my $count = shift ;
111 0 0       0 return if $count > 100 ;
112 0         0 my ($sub_name) ;
113 0 0       0 if ( UNIVERSAL::isa($pack , 'Class::HPLOO::Base') ) {
114 0 0       0 ($sub_name) = $sub eq 'new' ? ( $pack =~ /(\w+)$/ ) : ($sub) ;
115             } else {
116 0         0 $sub_name = $sub ;
117 0         0 } my $isa_sub = "$pack\::$sub_name" ;
118 0 0 0     0 if ( $look_deep || !defined &$isa_sub ) {
119 0         0 foreach my $isa_i ( @{"$pack\::ISA"} ) {
  0         0  
120 0 0 0     0 next if $isa_i eq $pack || $isa_i eq 'Class::HPLOO::Base' ;
121 0 0       0 last if $isa_i eq 'UNIVERSAL' ;
122 0         0 $isa_sub = ISA_FIND_NEW($isa_i , $sub , 0 , $count+1) ;
123 0 0       0 last if $isa_sub ;
124 0 0       0 } } $isa_sub = undef if !defined &$isa_sub ;
125 0         0 return $isa_sub ;
126             } sub new_call_BEGIN {
127 913     913 0 953 my $class = shift ;
128 913         963 my $this = $class ;
129 913         1366 foreach my $ISA_i ( @ISA ) {
130 913 50       2045 last if $ISA_i eq 'Class::HPLOO::Base' ;
131 0         0 my $ret ;
132 0         0 my ($sub) = ( $ISA_i =~ /(\w+)$/ );
133 0         0 $sub = "$ISA_i\::$sub\_BEGIN" ;
134 0 0       0 $ret = &$sub($this,@_) if defined &$sub ;
135 0 0       0 $this = $ret if UNIVERSAL::isa($ret,$class) ;
136 913         1583 } return $this ;
137             } sub new_call_END {
138 913     913 0 1052 my $class = shift ;
139 913         1443 foreach my $ISA_i ( @ISA ) {
140 913 50       6465 last if $ISA_i eq 'Class::HPLOO::Base' ;
141 0         0 my $ret ;
142 0         0 my ($sub) = ( $ISA_i =~ /(\w+)$/ );
143 0         0 $sub = "$ISA_i\::$sub\_END" ;
144 0 0       0 &$sub(@_) if defined &$sub ;
145 913         1135 } return ;
146             }
147            
148            
149             sub GET_CLASS_HPLOO_HASH {
150 13709     13709 0 19461 return \%CLASS_HPLOO } ;
151             sub ATTRS {
152 0     0 0 0 return @{[@{ $CLASS_HPLOO{ATTR_ORDER} }]} } ;
  0         0  
  0         0  
153             sub CLASS_HPLOO_ATTR {
154 1     1 0 44 my @attrs = split(/\s*,\s*/ , $_[0]) ;
155 1         5 foreach my $attrs_i ( @attrs ) {
156 26         54 $attrs_i =~ s/^\s+//s ;
157 26         54 $attrs_i =~ s/\s+$//s ;
158 26         88 my ($name) = ( $attrs_i =~ /(\w+)$/gi ) ;
159 26         83 my ($type) = ( $attrs_i =~ /^((?:\w+\s+)*?&?\w+|(?:\w+\s+)*?\w+(?:(?:::|\.)\w+)*)\s+\w+$/gi ) ;
160 26         27 my $type0 = $type ;
161 26         33 $type0 =~ s/\s+/ /gs ;
162 26         30 $type = lc($type) ;
163 26         24 $type =~ s/(?:^|\s*)bool$/boolean/gs ;
164 26         42 $type =~ s/(?:^|\s*)int$/integer/gs ;
165 26         28 $type =~ s/(?:^|\s*)float$/floating/gs ;
166 26         23 $type =~ s/(?:^|\s*)str$/string/gs ;
167 26         72 $type =~ s/(?:^|\s*)sub$/sub_$name/gs ;
168 26         33 $type =~ s/\s//gs ;
169 26 50       123 $type = 'any' if $type !~ /^(?:(?:ref)|(?:ref)?(?:array|hash)(?:boolean|integer|floating|string|sub_\w+|any|&\w+)|(?:ref)?(?:array|hash)|(?:array|hash)?(?:boolean|integer|floating|string|sub_\w+|any|&\w+))$/ ;
170 26 50 33     55 if ( $type eq 'any' && $type0 =~ /^((?:ref\s*)?(?:array|hash) )?(\w+(?:(?:::|\.)\w+)*)$/ ) {
171 0         0 my ($tp1 , $tp2) = ($1 , $2) ;
172 0         0 $tp1 =~ s/\s+//gs ;
173 0 0       0 $tp2 = 'UNIVERSAL' if $tp2 =~ /^(?:obj|object)$/i ;
174 0         0 $tp2 =~ s/\.+/::/gs ;
175 0         0 $type = "$tp1$tp2" ;
176 26 50       52 } my $parse_ref = $type =~ /^(?:array|hash)/ ? 1 : 0 ;
177 26 50       58 push(@{ $CLASS_HPLOO{ATTR_ORDER} } , $name) if !$CLASS_HPLOO{ATTR}{$name} ;
  26         52  
178 26         71 $CLASS_HPLOO{ATTR}{$name}{tp} = $type ;
179 26         35 $CLASS_HPLOO{ATTR}{$name}{pr} = $parse_ref ;
180 26         25 my $return ;
181 26 100       52 if ( $type =~ /^sub_(\w+)$/ ) {
182 15         27 my $sub = $1 ;
183 15         25 $return = qq~ return (&$sub(\$this,\@_))[0] if defined &$sub ;
184             return undef ;
185             ~ ;
186             } else {
187 11 50       23 $return = $parse_ref ? qq~ ref(\$this->{CLASS_HPLOO_ATTR}{$name}) eq 'ARRAY' ? \@{\$this->{CLASS_HPLOO_ATTR}{$name}} : ref(\$this->{CLASS_HPLOO_ATTR}{$name}) eq 'HASH' ? \%{\$this->{CLASS_HPLOO_ATTR}{$name}} : \$this->{CLASS_HPLOO_ATTR}{$name} ~ : "\$this->{CLASS_HPLOO_ATTR}{$name}" ;
188 26         2430 } eval(qq~ sub set_$name {
189             my \$this = shift ;
190             if ( !defined \$this->{$name} ) {
191             tie( \$this->{$name} => 'Date::Object::HPLOO_TIESCALAR' , \$this , '$name' , '$type' , $parse_ref , \\\$this->{CLASS_HPLOO_ATTR}{$name} , \\\$this->{CLASS_HPLOO_CHANGED} , 'Date::Object' ) ;
192             } \$this->{CLASS_HPLOO_CHANGED}{$name} = 1 ;
193             \$this->{CLASS_HPLOO_ATTR}{$name} = CLASS_HPLOO_ATTR_TYPE( ref(\$this) , '$type',\@_) ;
194 26 100   0 0 26 } ~) if !defined &{"set_$name"} ;
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0       0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
195 26         1318 eval(qq~ sub get_$name {
196             my \$this = shift ;
197             $return ;
198 26 50   0 0 102 } ~) if !defined &{"get_$name"} ;
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0 0   0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0     0 0 0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
  0         0  
199             } } { package Date::Object::HPLOO_TIESCALAR ;
200             sub TIESCALAR {
201 23738     23738   22480 shift ;
202 23738         25678 my $obj = shift ;
203 23738   50     156266 my $this = bless( {
204             nm => $_[0] , tp => $_[1] , pr => $_[2] , rf => $_[3] , rfcg => $_[4] , pk => ($_[5] || scalar caller) } , __PACKAGE__ ) ;
205 23738 100       71128 if ( $this->{tp} =~ /^sub_(\w+)$/ ) {
206 13695         22261 my $CLASS_HPLOO = Date::Object::GET_CLASS_HPLOO_HASH() ;
207 13695 100       26923 if ( !ref($$CLASS_HPLOO{OBJ_TBL}) ) {
208 1         5 eval {
209 1         1199 require Hash::NoRef } ;
210 1 50       15 if ( !$@ ) {
211 0         0 $$CLASS_HPLOO{OBJ_TBL} = {} ;
212 0         0 tie( %{$$CLASS_HPLOO{OBJ_TBL}} , 'Hash::NoRef') ;
  0         0  
213             } else {
214 1         3 $@ = undef } } $$CLASS_HPLOO{OBJ_TBL}{ ++$$CLASS_HPLOO{OBJ_TBL}{x} } = $obj ;
  13695         52612  
215 13695         30375 $this->{oid} = $$CLASS_HPLOO{OBJ_TBL}{x} ;
216 23738         66841 } return $this ;
217             } sub STORE {
218 11077     11077   12296 my $this = shift ;
219 11077         14072 my $ref = $this->{rf} ;
220 11077         12531 my $ref_changed = $this->{rfcg} ;
221 11077 50       20854 if ( $ref_changed ) {
222 11077 100       24255 if ( ref $$ref_changed ne 'HASH' ) {
223 912         1693 $$ref_changed = {} } $$ref_changed->{$this->{nm}} = 1 ;
  11077         22542  
224 11077 50       19682 } if ( $this->{pr} ) {
225 0 0       0 my $tp = $this->{tp} =~ /^ref/ ? $this->{tp} : 'ref' . $this->{tp} ;
226 0         0 $$ref = &{"$this->{pk}::CLASS_HPLOO_ATTR_TYPE"}($this->{pk} , $tp , @_) ;
  0         0  
227             } else {
228 11077         15729 $$ref = &{"$this->{pk}::CLASS_HPLOO_ATTR_TYPE"}($this->{pk} , $this->{tp} , @_) ;
  11077         37445  
229             } } sub FETCH {
230 4786     4786   5429 my $this = shift ;
231 4786         6681 my $ref = $this->{rf} ;
232 4786 100       9080 if ( $this->{tp} =~ /^sub_(\w+)$/ ) {
233 14         40 my $CLASS_HPLOO = Date::Object::GET_CLASS_HPLOO_HASH() ;
234 14         46 my $sub = $this->{pk} . '::' . $1 ;
235 14         35 my $obj = $$CLASS_HPLOO{OBJ_TBL}{ $this->{oid} } ;
236 14 50       86 return (&$sub($obj,@_))[0] if defined &$sub ;
237             } else {
238 4772 50       13999 if ( $this->{tp} =~ /^(?:ref)?(?:array|hash)/ ) {
239 0         0 my $ref_changed = $this->{rfcg} ;
240 0 0       0 if ( $ref_changed ) {
241 0 0       0 if ( ref $$ref_changed ne 'HASH' ) {
242 0         0 $$ref_changed = {} } $$ref_changed->{$this->{nm}} = 1 ;
  0         0  
243 4772         20158 } } return $$ref ;
244 0         0 } return undef ;
245 0     0   0 } sub UNTIE {} sub DESTROY {} } sub CLASS_HPLOO_ATTR_TYPE {
  0     0   0  
246 11077     11077 0 13628 my $class = shift ;
247 11077         13157 my $type = shift ;
248 11077 50       33644 if ($type eq 'any') {
    50          
    50          
    50          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
249 0         0 return $_[0] } elsif ($type eq 'string') {
250 0         0 return "$_[0]" ;
251             } elsif ($type eq 'boolean') {
252 0 0       0 return if $_[0] =~ /^(?:false|null|undef)$/i ;
253 0 0       0 return 1 if $_[0] ;
254 0         0 return ;
255             } elsif ($type eq 'integer') {
256 11077         13730 my $val = $_[0] ;
257 11077         16280 my ($sig) = ( $val =~ /^(-)/ );
258 11077         15289 $val =~ s/[^0-9]//gs ;
259 11077         15873 $val = "$sig$val" ;
260 11077         47964 return $val ;
261             } elsif ($type eq 'floating') {
262 0         0 my $val = $_[0] ;
263 0         0 $val =~ s/[\s_]+//gs ;
264 0 0       0 if ( $val !~ /^\d+\.\d+$/ ) {
265 0         0 ($val) = ( $val =~ /(\d+)/ ) ;
266 0         0 $val .= '.0' ;
267 0         0 } return $val ;
268             } elsif ($type =~ /^sub_(\w+)$/) {
269 0         0 my $sub = $1 ;
270 0 0       0 return (&$sub(@_))[0] if defined &$sub ;
271             } elsif ($type =~ /^&(\w+)$/) {
272 0         0 my $sub = $1 ;
273 0 0       0 return (&$sub(@_))[0] if defined &$sub ;
274             } elsif ($type eq 'ref') {
275 0         0 my $val = $_[0] ;
276 0 0       0 return $val if ref($val) ;
277             } elsif ($type eq 'array') {
278 0         0 my @val = @_ ;
279 0         0 return \@val ;
280             } elsif ($type eq 'hash') {
281 0         0 my %val = @_ ;
282 0         0 return \%val ;
283             } elsif ($type eq 'refarray') {
284 0         0 my $val = $_[0] ;
285 0 0       0 return $val if ref($val) eq 'ARRAY' ;
286             } elsif ($type eq 'refhash') {
287 0         0 my $val = $_[0] ;
288 0 0       0 return $val if ref($val) eq 'HASH' ;
289             } elsif ($type =~ /^array(&?[\w:]+)/ ) {
290 0         0 my $tp = $1 ;
291 0         0 my @val = @_ ;
292 0 0       0 my $accept_undef = $tp =~ /^(?:any|string|boolean|integer|floating|sub_\w+|&\w+)$/ ? 1 : undef ;
293 0 0       0 if ( $accept_undef ) {
294 0         0 return [map {
295 0         0 CLASS_HPLOO_ATTR_TYPE($class , $tp , $_) } @val] ;
296             } else {
297 0 0       0 return [map {
298 0         0 CLASS_HPLOO_ATTR_TYPE($class , $tp , $_) || () } @val] ;
299             } } elsif ($type =~ /^hash(&?[\w:]+)/ ) {
300 0         0 my $tp = $1 ;
301 0         0 my %val = @_ ;
302 0         0 foreach my $Key ( keys %val ) {
303 0         0 $val{$Key} = CLASS_HPLOO_ATTR_TYPE($class , $tp , $val{$Key}) ;
304 0         0 } return \%val ;
305             } elsif ($type =~ /^refarray(&?[\w:]+)/ ) {
306 0         0 my $tp = $1 ;
307 0 0       0 return undef if ref($_[0]) ne 'ARRAY' ;
308 0         0 my $ref = CLASS_HPLOO_ATTR_TYPE($class , "array$tp" , @{$_[0]}) ;
  0         0  
309 0         0 @{$_[0]} = @{$ref} ;
  0         0  
  0         0  
310 0         0 return $_[0] ;
311             } elsif ($type =~ /^refhash(&?[\w:]+)/ ) {
312 0         0 my $tp = $1 ;
313 0 0       0 return undef if ref($_[0]) ne 'HASH' ;
314 0         0 my $ref = CLASS_HPLOO_ATTR_TYPE($class , "hash$tp" , %{$_[0]}) ;
  0         0  
315 0         0 %{$_[0]} = %{$ref} ;
  0         0  
  0         0  
316 0         0 return $_[0] ;
317             } elsif ($type =~ /^\w+(?:::\w+)*$/ ) {
318 0 0       0 return( UNIVERSAL::isa($_[0] , $type) ? $_[0] : undef ) ;
319 0         0 } return undef ;
320             }
321            
322 1     1   13 no warnings ;
  1         2  
  1         60  
323            
324             use overload (
325 1         5 '""' => '_OVER_string' ,
326             '0+' => '_OVER_number' ,
327             'fallback' => 1 ,
328 1     1   1672 ) ;
  1         947  
329            
330 19 50 50 19   800 sub _OVER_string { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->date ;}
  19         42  
  19         197  
331 30 50 50 30   115 sub _OVER_number { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->time ;}
  30         65  
  30         52  
332            
333             CLASS_HPLOO_ATTR('
334             int time , int sec , int min , int hour , int day , int month , int year , int wday , int yday , int isdst , int zone ,
335             sub zone_gmt ,
336             sub s , sub m , sub h , sub d , sub mo , sub y , sub z ,
337             sub serial ,
338             sub date , sub date_zone ,
339             sub hms , sub ymd , sub mdy , sub dmy ') ;
340            
341             my @MONTHS_DAYS = ('',31,28,31,30,31,30,31,31,30,31,30,31) ;
342            
343             sub Object {
344 913 50   913 1 1921 my $this = ref($_[0]) ? shift : undef ;
345 913   50     1795 my $CLASS = ref($this) || __PACKAGE__ ;
346            
347 913         855 my ( $year , $month , $day , $hour , $min , $sec , $zone , $time ) ;
348            
349 913 100 100     4570 if ( $#_ == 0 && ref($_[0]) eq 'ARRAY' ) {
350 861         1370 ($zone , @_) = @{$_[0]} ;
  861         3073  
351             }
352            
353 913         1232 my $time ;
354 913 100 100     4913 if ( !@_ ) { $time = time ;}
  10 100       15  
355             elsif ( $#_ == 0 || $#_ == 1 ) {
356 31 100 66     335 if ( ref($_[0]) && UNIVERSAL::isa($_[0],'Date::Object') ) {
    100 100        
    100          
    50          
357 10         26 $time = $_[0]->time ;
358 10 100       38 $zone = $_[0]->zone if $zone eq '' ;
359             }
360             elsif ( length($_[0]) >= 14 && $_[0] =~ /^\d+$/ ) {
361 1         5 return new_serial('Date::Object',$_[0]) ;
362             }
363             elsif ( $_[0] =~ /^\s*(\d+)\D+(\d+)\D+(\d+)(?:\s+(\d\d?)\D+(\d\d?)(?:\D+(\d\d?))?)?/ ) {
364 1         2 my ( $d , $m , $y , $h , $min , $s ) ;
365 1         11 my @match = ($1 , $2 , $3 , $4 , $5 , $6) ;
366            
367 1 50       12 if ( $_[1] =~ /mdy/i ) {
    50          
    50          
368 0         0 ( $m , $d , $y , $h , $min , $s ) = @match ;
369             }
370             elsif ( $_[1] =~ /dmy/i ) {
371 0         0 ( $d , $m , $y , $h , $min , $s ) = @match ;
372             }
373             elsif ( $_[1] =~ /ymd/i ) {
374 1         4 ( $y , $m , $d , $h , $min , $s ) = @match ;
375             }
376             else {
377 0         0 ( $y , $m , $d , $h , $min , $s ) = @match ;
378             }
379            
380 1         5 $time = $this->timelocal($y , $m , $d , $h , $min , $s , 0 ) ;
381             }
382 19         67 elsif ( $_[0] >= 0 ) { $time = $_[0] ;}
383 0         0 else { $time = 0 ;}
384             }
385             else {
386 872 50       1778 if ($zone eq '') { $zone = $#_ >= 6 ? $_[6] : 0 ;}
  21 100       49  
387 872         2638 $time = $this->timelocal(@_[0..5] , $zone) ;
388             }
389            
390 912 50       1966 return UNDEF if $time == undef ;
391            
392 912         2944 $this->{time} = $time ;
393            
394 912 100       1583 if ( $zone ne '' ) { $this->set_zone($zone) ;}
  889         1951  
395 23         83 else { $this->set_gmt($time) ;}
396             }
397            
398             sub new_gmt {
399 839 50   839 1 1475 my $this = ref($_[0]) ? shift : undef ;
400 839   50     2574 my $CLASS = ref($this) || __PACKAGE__ ;
401            
402 839         1333 my $class = shift ;
403 839         2390 new($class , [0,@_]) ;
404             }
405            
406             sub new_local {
407 8 50   8 1 285 my $this = ref($_[0]) ? shift : undef ;
408 8   50     64 my $CLASS = ref($this) || __PACKAGE__ ;
409            
410 8         13 my $class = shift ;
411 8         23 my $zone = _calc_timezone() ;
412 8         36 my $obj = new($class , [$zone , @_]) ;
413 8         45 return $obj ;
414             }
415            
416             sub new_zone {
417 13 50   13 1 44 my $this = ref($_[0]) ? shift : undef ;
418 13   50     52 my $CLASS = ref($this) || __PACKAGE__ ;
419            
420 13         27 my $class = shift ;
421 13         16 my $zone = shift ;
422 13         47 my $obj = new($class , [$zone , @_]) ;
423 13         65 return $obj ;
424             }
425            
426             sub new_serial {
427 1 50   1 1 4 my $this = ref($_[0]) ? shift : undef ;
428 1   50     6 my $CLASS = ref($this) || __PACKAGE__ ;
429            
430 1         2 my $class = shift ;
431 1         2 my $serial = shift ;
432            
433 1         7 my ($time , $zone) = ( $serial =~ /^(\d+)(\d{4})$/ );
434            
435 1 50       13 if ( $zone > 1200 ) { $zone -= 1200 ;}
  0 50       0  
436 1         3 elsif ( $zone == 1200 ) { $zone = 0 ;}
437 0         0 else { $zone *= -1 ;}
438            
439 1         2 $zone =~ s/(\d\d)$/\.$1/ ;
440 1         2 $zone =~ s/\.00$// ;
441 1         2 $zone *= 1 ;
442            
443 1         4 my $obj = new($class , [$zone , $time]) ;
444 1         9 return $obj ;
445             }
446            
447             sub clone {
448 1 50   1 1 10 my $this = ref($_[0]) ? shift : undef ;
449 1   50     5 my $CLASS = ref($this) || __PACKAGE__ ;
450            
451 1         6 my $clone = Date::Object->new_zone($this->zone , $this) ;
452 1         7 return $clone ;
453             }
454            
455             sub set_gmt {
456 23 50   23 1 61 my $this = ref($_[0]) ? shift : undef ;
457 23   50     60 my $CLASS = ref($this) || __PACKAGE__ ;
458 23         42 my $time = shift(@_) ;
459            
460 23         63 ($this->{sec} , $this->{min} , $this->{hour} , $this->{day} , $this->{month} , $this->{year} , $this->{wday} , $this->{yday} , $this->{isdst} ) = $this->gmtime($time) ;
461 23         108 $this->{zone} = 0 ;
462 23         72 $this->{time} = $time ;
463 23         75 return $this ;
464             }
465            
466             sub set_local {
467 2 50   2 1 11 my $this = ref($_[0]) ? shift : undef ;
468 2   50     7 my $CLASS = ref($this) || __PACKAGE__ ;
469 2         3 my $time = shift(@_) ;
470 2         4 my $local_zone = shift(@_) ;
471            
472 2         17 ($this->{sec} , $this->{min} , $this->{hour} , $this->{day} , $this->{month} , $this->{year} , $this->{wday} , $this->{yday} , $this->{isdst} ) = $this->localtime($time) ;
473 2 50       15 $this->{zone} = $this->_calc_timezone if $local_zone eq '' ;
474 2         26 $this->{time} = $this->timelocal($this->{year} , $this->{month} , $this->{day} , $this->{hour} , $this->{min} , $this->{sec} , $this->{zone} ) ;
475 2         12 return $this ;
476             }
477            
478             sub set_zone {
479 899 50   899 1 1807 my $this = ref($_[0]) ? shift : undef ;
480 899   50     1785 my $CLASS = ref($this) || __PACKAGE__ ;
481 899         1004 my $zone = shift(@_) ;
482 899         980 my $time = shift(@_) ;
483            
484 899 100       1503 $zone = $this->_format_zone($zone) if $zone ;
485            
486 899   50     2738 $zone ||= $this->zone || 0 ;
      66        
487 899   66     2441 $time ||= $this->time ;
488            
489 899         2062 $this->{zone} = $zone ;
490            
491 899         1741 my $time_gmt = $time + (60*60*$zone) ;
492            
493 899         1760 ($this->{sec} , $this->{min} , $this->{hour} , $this->{day} , $this->{month} , $this->{year} , $this->{wday} , $this->{yday} , $this->{isdst} ) = $this->gmtime($time_gmt) ;
494            
495 899 100       2839 if ( $zone ) {
496 8         95 my $local_zone = $this->_calc_timezone ;
497 8 50       22 if ( $zone == $local_zone ) {
498 0         0 ( $this->{isdst} ) = ($this->localtime($time))[8] ;
499             }
500 8         26 else { $this->{isdst} = 0 ;}
501             }
502            
503 899         2239 $this->{time} = $time ;
504 899         3350 return $this ;
505             }
506            
507             sub set_serial {
508 4 50   4 0 40 my $this = ref($_[0]) ? shift : undef ;
509 4   50     14 my $CLASS = ref($this) || __PACKAGE__ ;
510 4         8 my $serial = shift(@_) ;
511            
512 4         30 my ($time , $zone) = ( $serial =~ /^(\d+)(\d{4})$/ );
513            
514 4 50       21 if ( $zone > 1200 ) { $zone -= 1200 ;}
  0 50       0  
515 4         6 elsif ( $zone == 1200 ) { $zone = 0 ;}
516 0         0 else { $zone *= -1 ;}
517            
518 4         8 $zone =~ s/(\d\d)$/\.$1/ ;
519 4         6 $zone =~ s/\.00$// ;
520 4         6 $zone *= 1 ;
521            
522 4         14 $this->set_zone($zone , $time) ;
523            
524 4         8 return $this ;
525             }
526            
527             sub set {
528 2 50   2 1 53 my $this = ref($_[0]) ? shift : undef ;
529 2   50     8 my $CLASS = ref($this) || __PACKAGE__ ;
530 2         4 my $y = shift(@_) ;
531 2         5 my $mo = shift(@_) ;
532 2         4 my $d = shift(@_) ;
533 2         3 my $h = shift(@_) ;
534 2         5 my $m = shift(@_) ;
535 2         3 my $s = shift(@_) ;
536            
537 2 50       12 $y = $this->{y} if !defined $y ;
538 2 50       11 $mo = $this->{mo} if !defined $mo ;
539 2 50       6 $d = $this->{d} if !defined $d ;
540 2 50       9 $h = $this->{h} if !defined $h ;
541 2 50       10 $m = $this->{m} if !defined $m ;
542 2 50       10 $s = $this->{s} if !defined $s ;
543            
544 2 100       8 if ( $d > $this->check($mo) ) { $d = $this->check($mo) ;}
  1         4  
545            
546 2         6 my $new_date = Date::Object->new_zone( $this->zone , $y , $mo , $d , $h , $m , $s ) ;
547 2         12 $this->set_serial( $new_date->serial ) ;
548            
549 2         10 return $this ;
550             }
551            
552             sub _format_zone {
553 886 100   886   1518 my $this = ref($_[0]) ? shift : undef ;
554 886   100     2573 my $CLASS = ref($this) || __PACKAGE__ ;
555 886         1224 my $zone = shift(@_) ;
556            
557 886   100     2435 $zone ||= 0 ;
558 886 50       1544 if ( $zone > 12 ) { $zone = 12 ;}
  0         0  
559 886 50       1625 if ( $zone < -12 ) { $zone = -12 ;}
  0         0  
560 886         1505 $zone =~ s/(\.\d{1,2})\d*/$1/ ;
561 886         2037 return $zone ;
562             }
563            
564             sub _calc_timezone {
565 18 100   18   54 my $this = ref($_[0]) ? shift : undef ;
566 18   100     55 my $CLASS = ref($this) || __PACKAGE__ ;
567            
568 18         74 my $d0 = Date::Object->new(time) ;
569            
570 18         59 my ($sec,$min,$hour,$mday,$mon,$year) = $d0->localtime ;
571 18         82 my $d1 = Date::Object->new($year , $mon , $mday , $hour , $min ,$sec) ;
572            
573 18         42 my $zone = $d1->time - $d0->time ;
574 18         43 $zone /= 60*60 ;
575            
576 18         28 $zone =~ s/(\.\d\d)\d*/$1/ ;
577            
578 18         936 return $zone ;
579             }
580            
581 904 50 50 904 1 1516 sub zone { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{zone} ;}
  904         1704  
  904         1928  
582            
583             sub zone_gmt {
584 13 50   13 1 34 my $this = ref($_[0]) ? shift : undef ;
585 13   50     33 my $CLASS = ref($this) || __PACKAGE__ ;
586            
587 13         45 my ($sign,$h,$m) = ( $this->{zone} =~ /^([\+\-]?)(\d{1,2})\d*(?:\.(\d{1,2})\d*)?$/ );
588            
589 13   100     59 $sign ||= '+' ;
590            
591 13         54 $h = "0$h" while length($h) < 2 ;
592 13         87 $m = "0$m" while length($m) < 2 ;
593            
594 13         27 my $z = "$sign$h$m" ;
595 13         36 return $z ;
596             }
597            
598 1819 50 50 1819 1 5298 sub time { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{time} ;}
  1819         3947  
  1819         3701  
599            
600 0 0 0 0 1 0 sub sec { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{sec} ;}
  0         0  
  0         0  
601 0 0 0 0 1 0 sub min { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{min} ;}
  0         0  
  0         0  
602             sub hour { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{hour} ;}
603 0 0 0 0 1 0 sub day { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{day} ;}
  0         0  
  0         0  
604 0 0 0 0 1 0 sub month { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{month} ;}
  0         0  
  0         0  
605 0 0 0 0 1 0 sub year { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{year} ;}
  0         0  
  0         0  
606 0 0 0 0 1 0 sub wday { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{wday} ;}
  0         0  
  0         0  
607 0 0 0 0 1 0 sub yday { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{yday} ;}
  0         0  
  0         0  
608 0 0 0 0 1 0 sub isdst { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{isdst} ;}
  0         0  
  0         0  
609            
610 5 50 50 5 1 13 sub s { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{sec} ;}
  5         24  
  5         11  
611 5 50 50 5 1 13 sub m { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{min} ;}
  5         14  
  5         11  
612 5 50 50 5 1 13 sub h { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{hour} ;}
  5         16  
  5         11  
613 3 50 50 3 1 12 sub d { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{day} ;}
  3         10  
  3         8  
614 6 50 50 6 1 19 sub mo { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{month} ;}
  6         17  
  6         23  
615 6 50 50 6 1 21 sub y { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{year} ;}
  6         156  
  6         22  
616 3 50 50 3 1 10 sub z { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->{zone} ;}
  3         8  
  3         9  
617            
618             sub serial {
619 7 50   7 1 71 my $this = ref($_[0]) ? shift : undef ;
620 7   50     26 my $CLASS = ref($this) || __PACKAGE__ ;
621            
622 7         23 my $z = $this->zone_gmt ;
623 7 50       46 if ( $z =~ /^-(\d+)/ ) { $z = $1 ;}
  0 50       0  
624 7         25 elsif ( $z =~ /^[\+]?(\d+)/ ) { $z = $1 + 1200 ;}
625 7         112 my $serial = $this->time . $z ;
626 7         23 while( length($serial) < 14 ) { $serial = "0$serial" ;}
  0         0  
627 7         190 return $serial ;
628             }
629            
630             sub add_sec {
631 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
632 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
633 0         0 my $secs = shift(@_) ;
634            
635 0   0     0 $secs ||= 1 ;
636 0         0 $this->{time} += $secs ;
637 0         0 $this->set_zone ;
638             }
639            
640             sub add_min {
641 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
642 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
643 0         0 my $mins = shift(@_) ;
644            
645 0   0     0 $mins ||= 1 ;
646 0         0 $this->{time} += 60*$mins ;
647 0         0 $this->set_zone ;
648             }
649            
650             sub add_hour {
651 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
652 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
653 0         0 my $hours = shift(@_) ;
654            
655 0   0     0 $hours ||= 1 ;
656 0         0 $this->{time} += 60*60*$hours ;
657 0         0 $this->set_zone ;
658             }
659            
660             sub add_day {
661 1 50   1 1 3 my $this = ref($_[0]) ? shift : undef ;
662 1   50     4 my $CLASS = ref($this) || __PACKAGE__ ;
663 1         1 my $days = shift(@_) ;
664            
665 1   50     3 $days ||= 1 ;
666 1         4 $this->{time} += 60*60*24*$days ;
667 1         3 $this->set_zone ;
668             }
669            
670             sub add_week {
671 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
672 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
673 0         0 my $weeks = shift(@_) ;
674            
675 0   0     0 $weeks ||= 1 ;
676 0         0 $this->add_day(7*$weeks) ;
677             }
678            
679             sub add_month {
680 3 50   3 1 15 my $this = ref($_[0]) ? shift : undef ;
681 3   50     18 my $CLASS = ref($this) || __PACKAGE__ ;
682 3         6 my $months = shift(@_) ;
683            
684 3   100     11 $months ||= 1 ;
685            
686 3 100       8 if ( $months < 0 ) { return $this->sub_month($months*-1) ;}
  1         5  
687            
688 2         9 my $y = $this->y ;
689 2         7 my $mo = $this->mo ;
690            
691 2         8 for my $i (1..$months) {
692 13         12 ++$mo ;
693 13 100       31 if ( $mo > 12 ) { $mo = 1 ; ++$y ;}
  1         2  
  1         3  
694             }
695            
696 2         8 $this->{time} = $this->timelocal( $y , $mo , $this->d , $this->h , $this->m , $this->s , $this->z ) ;
697 2         11 $this->set_zone ;
698             }
699            
700             sub sub_month {
701 1 50   1 1 9 my $this = ref($_[0]) ? shift : undef ;
702 1   50     22 my $CLASS = ref($this) || __PACKAGE__ ;
703 1         3 my $months = shift(@_) ;
704            
705 1   50     3 $months ||= 1 ;
706            
707 1 50       4 if ( $months < 0 ) { return $this->add_month($months*-1) ;}
  0         0  
708            
709 1         5 my $y = $this->y ;
710 1         22 my $mo = $this->mo ;
711            
712 1         4 for my $i (1..$months) {
713 12         13 --$mo ;
714 12 100       21 if ( $mo < 1 ) { $mo = 12 ; --$y ;}
  1         2  
  1         2  
715             }
716            
717 1         5 $this->{time} = $this->timelocal( $y , $mo , $this->d , $this->h , $this->m , $this->s , $this->z ) ;
718 1         5 $this->set_zone ;
719             }
720            
721             sub add_year {
722 2 50   2 1 15 my $this = ref($_[0]) ? shift : undef ;
723 2   50     7 my $CLASS = ref($this) || __PACKAGE__ ;
724 2         5 my $years = shift(@_) ;
725            
726 2   50     5 $years ||= 1 ;
727 2         10 $this->add_month(12*$years) ;
728             }
729            
730 0 0 0 0 1 0 sub sub_sec { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_sec( $n*-1 ) ;}
  0   0     0  
  0         0  
  0         0  
  0         0  
731 0 0 0 0 1 0 sub sub_min { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_min( $n*-1 ) ;}
  0   0     0  
  0         0  
  0         0  
  0         0  
732 0 0 0 0 1 0 sub sub_hour { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_hour( $n*-1 ) ;}
  0   0     0  
  0         0  
  0         0  
  0         0  
733 1 50 50 1 1 9 sub sub_day { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_day( $n*-1 ) ;}
  1   50     6  
  1         2  
  1         6  
  1         4  
734 0 0 0 0 1 0 sub sub_week { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_week( $n*-1 ) ;}
  0   0     0  
  0         0  
  0         0  
  0         0  
735 1 50 50 1 1 6 sub sub_year { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ;my $n = shift(@_) ; $n ||= 1 ; $this->add_year( $n*-1 ) ;}
  1   50     5  
  1         2  
  1         4  
  1         4  
736            
737             sub gmtime {
738 1800 50   1800 1 3303 my $this = ref($_[0]) ? shift : undef ;
739 1800   50     3581 my $CLASS = ref($this) || __PACKAGE__ ;
740 1800         1848 my $time = shift(@_) ;
741            
742 1800   66     5284 $time ||= $this->{time} || time ;
      66        
743 1800         5394 return _fix_vars_time( gmtime($time) ) ;
744             }
745            
746             sub localtime {
747 20 50   20 1 52 my $this = ref($_[0]) ? shift : undef ;
748 20   50     49 my $CLASS = ref($this) || __PACKAGE__ ;
749 20         33 my $time = shift(@_) ;
750            
751 20   33     90 $time ||= $this->{time} || time ;
      33        
752 20         2572 return _fix_vars_time( localtime($time) ) ;
753             }
754            
755             sub _fix_vars_time {
756 1820 50   1820   2952 my $this = ref($_[0]) ? shift : undef ;
757 1820   50     5233 my $CLASS = ref($this) || __PACKAGE__ ;
758 1820         2014 my $sec = shift(@_) ;
759 1820         1772 my $min = shift(@_) ;
760 1820         2160 my $hour = shift(@_) ;
761 1820         1663 my $mday = shift(@_) ;
762 1820         1959 my $mon = shift(@_) ;
763 1820         1790 my $year = shift(@_) ;
764 1820         2303 my $wday = shift(@_) ;
765 1820         1561 my $yday = shift(@_) ;
766 1820         1633 my $isdst = shift(@_) ;
767            
768 1820         1727 ++$mon ;
769 1820         2034 $year += 1900 ;
770 1820         1513 ++$yday ;
771            
772 1820 100       3726 $sec = "0$sec" if $sec < 10 ;
773 1820 100       3638 $min = "0$min" if $min < 10 ;
774 1820 100       3214 $hour = "0$hour" if $hour < 10 ;
775 1820 100       3670 $mday = "0$mday" if $mday < 10 ;
776 1820 100       3485 $mon = "0$mon" if $mon < 10 ;
777            
778 1820         14864 return ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) ;
779             }
780            
781             sub timelocal {
782 878 50   878 1 1811 my $this = ref($_[0]) ? shift : undef ;
783 878   50     1759 my $CLASS = ref($this) || __PACKAGE__ ;
784 878         972 my $year = shift(@_) ;
785 878         881 my $mon = shift(@_) ;
786 878         839 my $day = shift(@_) ;
787 878         1046 my $hour = shift(@_) ;
788 878         807 my $min = shift(@_) ;
789 878         865 my $sec = shift(@_) ;
790 878         945 my $zone = shift(@_) ;
791            
792            
793 878         1656 $zone = _format_zone($zone) ;
794            
795 878         2691 my $year_0 = (gmtime(1))[5] + 1900 ;
796            
797 878         1731 my ($now_sec,$now_min,$now_hour,$now_mday,$now_mon,$now_year) = $this->gmtime ;
798            
799 878 50 33     5414 if (!$year || $year eq '*' || $year < $year_0) { $year = $now_year ;}
  0   33     0  
800            
801 878         902 my $year_bisexto = 0 ;
802 878 100       1925 if ( $this->is_leap_year($year) ) { $year_bisexto = 1 ;}
  230         289  
803            
804 878 50 33     21400 if (!$mon || $mon eq '*') { $mon = $now_mon }
  0 50 33     0  
    50 33        
    50 33        
    100 100        
    50          
805 0         0 elsif ($mon < 1 || $mon > 12 ) { return }
806            
807 0         0 elsif (!$day || $day eq '*') { $day = $now_mday }
808 0         0 elsif ($day < 1 || $day > 31 ) { return }
809             elsif ($mon == 2 && $day > 28) {
810 5 100       22 $day = 28 if !$this->check($year,$mon,$day) ;
811             }
812 0         0 elsif ($day > $this->check($mon) ) { return }
813            
814 878 100 33     4483 if ($hour eq '') { $hour = 0 }
  11 50       18  
    50          
    50          
815 0         0 elsif ($hour eq '*') { $hour = $now_hour }
816 0         0 elsif ($hour == 24) { $hour = 0 }
817 0         0 elsif ($hour < 0 || $hour > 24 ) { return }
818            
819 878 100 33     4503 if ($min eq '') { $min = 0 }
  11 50       30  
    50          
    50          
820 0         0 elsif ($min eq '*') { $min = $now_min }
821 0         0 elsif ($min == 60) { $min = 59 }
822 0         0 elsif ($min < 0 || $min > 60 ) { return }
823            
824 878 100 33     4400 if ($sec eq '') { $sec = 0 }
  18 50       25  
    50          
    50          
825 0         0 elsif ($sec eq '*') { $sec = $now_sec }
826 0         0 elsif ($sec == 60) { $sec = 59 }
827 0         0 elsif ($sec < 0 || $sec > 60 ) { return }
828            
829 878         866 my $timelocal ;
830            
831 878         1034 my $time_day = 60*60*24 ;
832 878         955 my $time_year = $time_day * 365 ;
833            
834 878         1658 for my $y ($year_0..($year-1)) {
835 29646         29122 $timelocal += $time_year ;
836 29646 100       44986 if ( $this->is_leap_year($y) ) { $timelocal += $time_day ;}
  7297         9463  
837             }
838            
839 878         1693 for my $m (1..($mon-1)) {
840 4792         6387 my $month_days = &check($m) ;
841 4792         7477 $timelocal += $month_days * $time_day ;
842             }
843            
844 878 100 100     2353 if ($year_bisexto == 1 && $mon > 2) { $timelocal += $time_day ;}
  185         279  
845            
846 878         1012 $timelocal += $time_day * ($day-1) ;
847            
848 878         944 $timelocal += 60*60 * $hour ;
849 878         779 $timelocal += 60 * $min ;
850 878         800 $timelocal += $sec ;
851            
852 878 100       1516 $timelocal += 60*60*($zone*-1) if $zone ;
853            
854 878         1938 return $timelocal ;
855             }
856            
857             sub check {
858 5673 100   5673 1 8503 my $this = ref($_[0]) ? shift : undef ;
859 5673   100     14957 my $CLASS = ref($this) || __PACKAGE__ ;
860            
861 5673 50       17633 shift if $_[0] !~ /^\d+$/ ;
862            
863 5673         5417 my ( $year , $month , $day ) ;
864            
865 5673 100       11328 if ($#_ == 2) { ( $year , $month , $day ) = @_ ;}
  5         20  
866 5673 50       9484 if ($#_ == 1) { ( $month , $day ) = @_ ;}
  0         0  
867 5673 100       8711 if ($#_ == 0) { ( $month ) = @_ ;}
  5668         7704  
868            
869 5673 100       13613 if ($#_ > 0) {
    50          
870 5 50       22 if ($year eq '') { $year = 1970 }
  0         0  
871 5 50       19 if ($month eq '') { $month = 1 }
  0         0  
872 5 50       12 if ($day eq '') { $day = 1 }
  0         0  
873            
874 5         22 my @months_days = @MONTHS_DAYS ;
875            
876 5 100       14 if ( $this->is_leap_year($year) ) { $months_days[2] = 29 ;}
  4         5  
877            
878 5 100       13 if ($day <= $months_days[$month]) { return 1 ;}
  4         17  
879 1         5 else { return ;}
880             }
881             elsif ($#_ == 0) {
882 5668 50       8630 if ($month eq '') { return ; }
  0         0  
883 5668         16385 return $MONTHS_DAYS[$month] ;
884             }
885            
886 0         0 return undef ;
887             }
888            
889             # The Egyptians called it 365 and left it at that. But their calendar got out of step with the seasons, so that
890             # after around 750 years of this they were celebrating The Fourth of July in the middle of the winter.
891             #
892             # The Romans wised up and added the leap day every four years to get the 365.25 day Julian year. Much better,
893             # but notice that this time the year is longer than it ought to be. The small difference between this and the
894             # true length of the year caused the seasons to creep through the calendar once again, only slower and in the
895             # other direction. After about 23000 years of this, July Fourth would once again fall in mid-winter.
896             #
897             # Fortunately things never reached that sad state. By 1582 the calendar was about ten days out of whack, so
898             # Pope Gregory XIII included the correction that's still in use today.
899             #
900             # "If the year is divisible by 100, it's not a leap year UNLESS it is also divisible by 400."
901             #
902             # More recently, proposals for fixes have gotten even better than that. One suggested change is to add on "if
903             # the year is also divisible by 4000, it's not a leap year."
904            
905             sub is_leap_year {
906 30529 50   30529 0 44474 my $this = ref($_[0]) ? shift : undef ;
907 30529   50     49249 my $CLASS = ref($this) || __PACKAGE__ ;
908 30529         29626 my $year = shift(@_) ;
909            
910 30529 50       53545 $year = $this->{year} if $year eq '' ;
911            
912 30529 50       101070 if ($year == 0) { return 1 ;}
  0 50       0  
    100          
    50          
    100          
913 0         0 elsif (($year % 4000) == 0) { return 0 ;}
914 512         1137 elsif (($year % 400) == 0) { return 1 ;}
915 0         0 elsif (($year % 100) == 0) { return 0 ;}
916 7019         15999 elsif (($year % 4) == 0) { return 1 ;}
917 22998         51003 return 0 ;
918             }
919            
920             sub secs_from {
921 6 50   6 1 22 my $this = ref($_[0]) ? shift : undef ;
922 6   50     12 my $CLASS = ref($this) || __PACKAGE__ ;
923            
924 6         13 my $time_0 = $this->time ;
925 6         22 my $time_1 = Date::Object->new(@_)->time ;
926            
927 6         17 my $delay = $time_0 - $time_1 ;
928 6         11 return $delay ;
929             }
930            
931             sub min_from {
932 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
933 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
934            
935 0         0 my $delay = $this->secs_from(@_) ;
936 0         0 my $min = int($delay / (60)) ;
937 0         0 return $min ;
938             }
939            
940             sub hours_from {
941 6 50   6 1 30 my $this = ref($_[0]) ? shift : undef ;
942 6   50     15 my $CLASS = ref($this) || __PACKAGE__ ;
943            
944 6         16 my $delay = $this->secs_from(@_) ;
945 6         58 my $hours = int($delay / (60*60)) ;
946 6         34 return $hours ;
947             }
948            
949             sub days_from {
950 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
951 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
952            
953 0         0 my $delay = $this->secs_from(@_) ;
954 0         0 my $days = int($delay / (60*60*24)) ;
955 0         0 return $days ;
956             }
957            
958             sub weeks_from {
959 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
960 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
961            
962 0         0 my $days = $this->days_from(@_) ;
963 0         0 my $weeks = int($days / 7) ;
964 0         0 return $weeks ;
965             }
966            
967             sub months_from {
968 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
969 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
970            
971 0         0 my $days = $this->days_from(@_) ;
972 0         0 my $months = int($days / 30) ;
973 0         0 return $months ;
974             }
975            
976             sub years_from {
977 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
978 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
979            
980 0         0 my $days = $this->days_from(@_) ;
981 0         0 my $years = int($days / 365) ;
982 0         0 return $years ;
983             }
984            
985 0 0 0 0 1 0 sub secs_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->secs_from(@_) * -1 ;}
  0         0  
  0         0  
986 0 0 0 0 1 0 sub min_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->min_from(@_) * -1 ;}
  0         0  
  0         0  
987 2 50 50 2 1 46 sub hours_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->hours_from(@_) * -1 ;}
  2         10  
  2         6  
988 0 0 0 0 1 0 sub days_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->days_from(@_) * -1 ;}
  0         0  
  0         0  
989 0 0 0 0 1 0 sub weeks_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->weeks_from(@_) * -1 ;}
  0         0  
  0         0  
990 0 0 0 0 1 0 sub months_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->months_from(@_) * -1 ;}
  0         0  
  0         0  
991 0 0 0 0 1 0 sub years_until { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->years_from(@_) * -1 ;}
  0         0  
  0         0  
992            
993 0 0 0 0 1 0 sub secs_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->secs_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
994 0 0 0 0 1 0 sub min_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->min_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
995 2 50 50 2 1 9 sub hours_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->hours_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  2 100       7  
  2         7  
  2         13  
996 0 0 0 0 1 0 sub days_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->days_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
997 0 0 0 0 1 0 sub weeks_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->weeks_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
998 0 0 0 0 1 0 sub months_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->months_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
999 0 0 0 0 1 0 sub years_between { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; my $r = $this->years_from(@_) ; $r < 0 ? ($r*-1) : $r ;}
  0 0       0  
  0         0  
  0         0  
1000            
1001             sub date {
1002 27 50   27 1 76 my $this = ref($_[0]) ? shift : undef ;
1003 27   50     60 my $CLASS = ref($this) || __PACKAGE__ ;
1004            
1005 27         98 my $date = "$this->{year}-$this->{month}-$this->{day} $this->{hour}:$this->{min}:$this->{sec}" ;
1006 27         124 return $date ;
1007             }
1008            
1009             sub date_zone {
1010 5 50   5 1 23 my $this = ref($_[0]) ? shift : undef ;
1011 5   50     14 my $CLASS = ref($this) || __PACKAGE__ ;
1012            
1013 5         15 my $z = $this->zone_gmt ;
1014 5         13 my $date = "$this->{year}-$this->{month}-$this->{day} $this->{hour}:$this->{min}:$this->{sec} $z" ;
1015 5         42 return $date ;
1016             }
1017            
1018             sub hour {
1019 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
1020 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
1021            
1022 0         0 my $date = "$this->{hour}:$this->{min}:$this->{sec}" ;
1023 0         0 return $date ;
1024             }
1025            
1026 0 0 0 0 1 0 sub hms { my $this = ref($_[0]) ? shift : undef ;my $CLASS = ref($this) || __PACKAGE__ ; $this->hour }
  0         0  
  0         0  
1027            
1028             sub ymd {
1029 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
1030 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
1031            
1032 0         0 my $date = "$this->{year}-$this->{month}-$this->{day}" ;
1033 0         0 return $date ;
1034             }
1035            
1036             sub mdy {
1037 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
1038 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
1039            
1040 0         0 my $date = "$this->{month}-$this->{day}-$this->{year}" ;
1041 0         0 return $date ;
1042             }
1043            
1044             sub dmy {
1045 0 0   0 1 0 my $this = ref($_[0]) ? shift : undef ;
1046 0   0     0 my $CLASS = ref($this) || __PACKAGE__ ;
1047            
1048 0         0 my $date = "$this->{day}-$this->{month}-$this->{year}" ;
1049 0         0 return $date ;
1050             }
1051            
1052             sub STORABLE_freeze {
1053 1 50   1 0 59 my $this = ref($_[0]) ? shift : undef ;
1054 1   50     39 my $CLASS = ref($this) || __PACKAGE__ ;
1055 1         2 my $cloning = shift(@_) ;
1056            
1057 1         6 return $this->serial ;
1058             }
1059            
1060             sub STORABLE_thaw {
1061 1 50   1 0 36 my $this = ref($_[0]) ? shift : undef ;
1062 1   50     9 my $CLASS = ref($this) || __PACKAGE__ ;
1063 1         2 my $cloning = shift(@_) ;
1064 1         2 my $serial = shift(@_) ;
1065            
1066 1         6 $this->set_serial($serial) ;
1067 1         85 return ;
1068             }
1069            
1070            
1071             }
1072            
1073            
1074            
1075             1;
1076            
1077             __END__