- my $self = shift;
- my $val = shift or return undef;
- my $dformat = $self->{'dateformat'} or return undef;
- my $re = $self->regexp();
- my $xsub = $dmy_subs{$dformat};
- $debug and print STDERR "xsub: $xsub \n";
- if ($val =~ /$re/) {
- my $aref = eval $xsub;
- return @{$aref};
- }
- # $debug and
- carp "Illegal Date '$val' does not match '$dformat' format: " . $self->visual() . "\n";
- return 0;
+ my $self = shift;
+ my $val = shift or return undef;
+ my $dformat = $self->{'dateformat'} or return undef;
+ my $re = $self->regexp();
+ my $xsub = $dmy_subs{$dformat};
+ $debug and print STDERR "xsub: $xsub \n";
+ if ( $val =~ /$re/ ) {
+ my $aref = eval $xsub;
+ if ($dformat eq 'rfc822') {
+ $aref = _abbr_to_numeric($aref, $dformat);
+ pop(@{$aref}); #pop off tz offset because we are not setup to handle tz conversions just yet
+ }
+ _check_date_and_time($aref);
+ push @{$aref}, (-1,-1,1); # for some reason unknown to me, setting isdst to -1 or undef causes strftime to fail to return the tz offset which is required in RFC822 format -chris_n
+ return @{$aref};
+ }
+
+ # $debug and
+ carp "Illegal Date '$val' does not match '$dformat' format: " . $self->visual();
+ return 0;
+}
+
+sub _abbr_to_numeric {
+ my $aref = shift;
+ my $dformat = shift;
+ my ($month_abbr, $day_abbr) = ($aref->[4], $aref->[3]) if $dformat eq 'rfc822';
+
+ for( my $i = 0; $i < scalar(@months); $i++ ) {
+ if ( $months[$i] =~ /$month_abbr/ ) {
+ $aref->[4] = $i-1;
+ last;
+ }
+ };
+
+ for( my $i = 0; $i < scalar(@days); $i++ ) {
+ if ( $days[$i] =~ /$day_abbr/ ) {
+ $aref->[3] = $i;
+ last;
+ }
+ };
+ return $aref;
+}
+
+sub _check_date_and_time {
+ my $chron_ref = shift;
+ my ( $year, $month, $day ) = _chron_to_ymd($chron_ref);
+ unless ( check_date( $year, $month, $day ) ) {
+ carp "Illegal date specified (year = $year, month = $month, day = $day)";
+ }
+ my ( $hour, $minute, $second ) = _chron_to_hms($chron_ref);
+ unless ( check_time( $hour, $minute, $second ) ) {
+ carp "Illegal time specified (hour = $hour, minute = $minute, second = $second)";
+ }
+}
+
+sub _chron_to_ymd {
+ my $chron_ref = shift;
+ return ( $chron_ref->[5] + 1900, $chron_ref->[4] + 1, $chron_ref->[3] );
+}
+
+sub _chron_to_hms {
+ my $chron_ref = shift;
+ return ( $chron_ref->[2], $chron_ref->[1], $chron_ref->[0] );