Data::FormValidator::Constraints::DateTime - D::FV constraints for dates and times
The package provides constraint routines for Data::FormValidator for dealing with dates and times. It provides an easy mechanism for validating dates of any format (using strptime(3)) and transforming those dates into valid DateTime objects, or into strings that would be properly formatted for various database engines.
use Data::FormValidator; use Data::FormValidator::Constraints::DateTime qw(:all); # create our profile my $profile = { validator_packages => [qw(Data::FormValidator::Constraints::DateTime)], required => [qw(my_date)], constraints => { # my_date is in the format MM/DD/YYYY my_date => { constraint_method => 'to_datetime', params => [\'%D'], # some valid strptime format string }, untaint_all_constraints => 1, }; # validate 'my_date' my $results = Data::FormValidator->check($my_input, $profile); unless( $results->has_missing || $results->has_invalid ) { # if we got here then $results->valid('my_date') # is a valid DateTime object }
All of the validation routines exported by this module use strptime(3) format strings to know what format your date string is in before we can process it. You specify this format foreach date you want to validate using the 'params' array ref (see the example above).
We use DateTime::Format::Strptime for this transformation. If you need a list of these formats (if you haven't yet committed them to memory) you can see the strptime(3) man page (if you are on a *nix system) or you can see the DateTime::Format::Strptime documentation.
By default, this module does not export any validation routines. You should export the group of methods that you are going to use.
to_mysql_datetime
to_mysql_date
to_mysql_timestamp
to_pg_datetime
Following is a list of validation subroutines that can be exported by this module.
The routine will change the date string into a DateTime object
The routine will change the date string into a DATETIME datatype suitable for MySQL
The routine will change the date string into a DATE datatype suitable for MySQL
The routine will change the date string into a TIMESTAMP datatype suitable for MySQL
The routine will change the date string into a DATETIME datatype suitable for PostgreSQL
Michael Peters <mpeters@plusthree.com>
Thanks to Plus Three, LP (http://www.plusthree.com) for sponsoring my work on this module
This module is a part of the large Data::FormValidator project. If you have questions, comments, bug reports or feature requests, please join the Data::FormValidator's mailing list.
Data::FormValidator, DateTime. DateTime::Format::Strptime, DateTime::Format::MySQL, DateTime::Format::Pg
To install Data::FormValidator::Constraints::DateTime, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::FormValidator::Constraints::DateTime
CPAN shell
perl -MCPAN -e shell install Data::FormValidator::Constraints::DateTime
For more information on module installation, please visit the detailed CPAN module installation guide.