BusyBird-DateTime-Format
view release on metacpan or search on metacpan
lib/BusyBird/DateTime/Format.pm view on Meta::CPAN
package BusyBird::DateTime::Format;
use strict;
use warnings;
use DateTime::Format::Strptime;
use Try::Tiny;
our $VERSION = "0.05";
our $preferred = 0;
my %OPT_DEFAULT = (
locale => 'en_US',
on_error => 'undef',
);
my @FORMATS = (
DateTime::Format::Strptime->new(
%OPT_DEFAULT,
pattern => '%a %b %d %T %z %Y',
),
DateTime::Format::Strptime->new(
%OPT_DEFAULT,
pattern => '%a, %d %b %Y %T %z',
),
);
sub new {
my ($class) = @_;
return bless {}, $class;
}
sub parse_datetime {
my ($class_self, $string) = @_;
my $parsed;
return undef if not defined $string;
foreach my $f (@FORMATS) {
$parsed = try {
$f->parse_datetime($string);
}catch {
undef;
};
last if defined($parsed);
}
return $parsed;
}
sub format_datetime {
my ($class_self, $datetime) = @_;
return $FORMATS[$preferred]->format_datetime($datetime);
}
1;
__END__
=pod
=head1 NAME
BusyBird::DateTime::Format - DateTime::Format for BusyBird
=head1 SYNOPSIS
use BusyBird::DateTime::Format;
( run in 2.275 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )