Peter Conrey wrote:
I have written a new module that simply parses dates in several different
formats. The reason I have written this on is that every existing parser from
this project that I've tried has fallen short in one area or another,
particularly in parsing our most commonly used format, "MM/dd/yyyy".

I've some glue that I've called "DateTime::Format::TimeParseDate" that glues Time::ParseDate to DateTime. I love it because it normally does-what-you-mean to the point of understanding "Yesterday at 2pm" or "Midnight next Wednesday".

I haven't released it because it isn't documented at all and I've not written any tests. I've attached it in case it helps.

Cheers!
Rick Measham
package DateTime::Format::TimeParseDate;

use strict;
use warnings;

use DateTime;
use Time::ParseDate qw//;
use Params::Validate qw/validate BOOLEAN/;

sub parse_datetime {
	my $class = shift;
	my $date  = shift;

	my %inarg = @_;
	my %arg;
	foreach ( keys %inarg ) {
		$arg{ uc( $_ ) } = $inarg{ $_ };
	}

	my $epoch = Time::ParseDate::parsedate( $date, %arg );

	my $dt = DateTime->from_epoch(epoch => $epoch);

	if ($arg{TZ}) {
		$dt->set_time_zone( $arg{TZ} );
	}
	return $dt;
}
#print STDERR "Loaded DateTime::Format::TimeParseDate 0.0001_01";
1;

Reply via email to