The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

DateTime::Format::Flexible - DateTime::Format::Flexible - Flexibly parse strings and turn them into DateTime objects.

SYNOPSIS

use DateTime::Format::Flexible;
my $dt = DateTime::Format::Flexible->build( 'January 8, 1999' );
# $dt = a DateTime object set at 1999-01-08T00:00:00

DESCRIPTION

If you have ever had to use a program that made you type in the date a certain way and thought "Why can't the computer just figure out what date I wanted?", this module is for you.

It attempts to take any string you give it and parse it into a DateTime object.

For supported string formats, see the test file. If you can think of any that I do not cover, please let me know.

USAGE

This module uses DateTime::Format::Builder under the covers. It only has one method (build).

build

my $dt = DateTime::Format::Flexible->build( $date );

A small list of supported formats: YYYYMMDDTHHMMSS YYYYMMDDTHHMM YYYYMMDDTHH YYYYMMDD YYYYMM MM-DD-YYYY MM-D-YYYY MM-DD-YY M-DD-YY YYYY/DD/MM YYYY/M/DD YYYY/MM/D M-D MM-D M-D-Y Month D, YYYY Mon D, YYYY Mon D, YYYY HH:MM:SS ...

there are 2800+ variations that are detected correctly in the test file.

BUGS

You cannot use a 1 or 2 digit year as the first field:

YY-MM-DD # not supported
Y-MM-DD  # not supported

It would get confused with MM-DD-YY

It also prefers the US format of MM-DD over the European DD-MM.

AUTHOR

Tom Heady
CPAN ID: thinc
Punch, Inc.
cpan@punch.net
http://www.punch.net/

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

SEE ALSO

perl(1). DateTime::Format::Builder