Jeff Walters design@nospam.jjw.cc Code Changes for Extropia::Core::DataHandler::Date ************************************************ **** 40, 1 Add **** -IS_TIME_IN_RANGE => [$self,\&isTimeInRange], **** 305, 1 Add **** # isTimeInRange checks to see if the passed time data is within a # valid time range. # sub isTimeInRange { my $self = shift; @_ = _rearrange([-FIELD_VALUE,-FIELD_NAME, -MIN_TIME, -MAX_TIME, -ERROR_MESSAGE, -ADD_ERROR], [],@_); my $field = shift; $field = "" if (!defined($field)); my $field_name = shift || "unknown"; # no date time field entered... use -IS_FILLED_IN to detect required fields. if (!$field) { return 1; } my $min_time = shift || '00:00'; my $max_time = shift || '23:59'; my $error_msg = shift || "The time you passed is not within the valid range: "; my $add_error = shift; $add_error = 1 if (!defined($add_error)); my $field_hour; my $field_minute; if ($field =~ /(\d{1,2})\s*:\s*(\d{1,2})\s*:\s*(\d{1,2})/) { $field_hour = $1; $field_minute = $2; } elsif ($field =~ /(\d{1,2})\s*:\s*(\d{1,2})/) { $field_hour = $1; $field_minute = $2; } my ($min_hour, $min_minute, $min_second) = split(/[\s:]/, $min_time); my ($max_hour, $max_minute, $max_second) = split(/[\s:]/, $max_time); if ($field_hour*3600+$field_minute*60 < $min_hour*3600+$min_minute*60 || $field_hour*3600+$field_minute*60 > $max_hour*3600+$max_minute*60) { if ($add_error) { $self->addError( new Extropia::Core::Error( -MESSAGE => $self->_getMessage( [-FIELD_NAME => $field_name], [-FIELD => $field], $error_msg ) ) ); } return undef; } return 1; } # end of isTimeInRange **** Example Datahandler in webcal.cgi **** -IS_TIME_IN_RANGE => [ # Fields are expected to be in the standard 'y-m-d H:M:S' format. -FIELDS => [qw( start_date end_date )], -MIN_TIME => '6:00', # Expects 'H:M:S' format. -MAX_TIME => '18:00', # Expects 'H:M:S' format. -ERROR_MESSAGE => "The time you selected for the %FIELD_NAME% " . "is not within the valid range of 6 AM to 6 PM.", ]