X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FTypes%2FDateTimeX.pm;h=ca21a9b41f5b22f2fbe10d708552f21f2102d4b0;hb=6903978cb24cbb86600dd0d2361057cae35f76fe;hp=19c37e6fd45687223990997a08ff4eb180d8b3c6;hpb=a3f4ab7163afcfbb6945a5a804511e183437afda;p=gitmo%2FMooseX-Types-DateTime.git diff --git a/lib/MooseX/Types/DateTimeX.pm b/lib/MooseX/Types/DateTimeX.pm index 19c37e6..ca21a9b 100755 --- a/lib/MooseX/Types/DateTimeX.pm +++ b/lib/MooseX/Types/DateTimeX.pm @@ -3,15 +3,17 @@ package MooseX::Types::DateTimeX; use strict; use warnings; -our $VERSION = "0.02"; +our $VERSION = "0.03"; our $AUTHORITY = 'cpan:JJNAPIORK'; use DateTime; +use DateTime::Duration; use DateTimeX::Easy; +use Time::Duration::Parse (); use MooseX::Types::DateTime; use MooseX::Types::Moose qw/Num HashRef Str/; -use MooseX::Types - -declare => [qw( DateTime )]; +use MooseX::Types -declare => [qw( DateTime Duration)]; + =head1 NAME @@ -71,13 +73,36 @@ coerce DateTime, via { DateTimeX::Easy->new($_, default_time_zone=>'UTC') }; +=head2 Duration + +Subtype of 'DateTime::Duration' that coerces from a string. We use the module +L to attempt this. + +=cut + +subtype Duration, + as 'DateTime::Duration'; ## From MooseX::Types::Duration + +coerce Duration, + from Num, + via { DateTime::Duration->new( seconds => $_ ) }, + from HashRef, + via { DateTime::Duration->new( %$_ ) }, + from Str, + via { + DateTime::Duration->new( + seconds => Time::Duration::Parse::parse_duration($_) + )}; + + =head1 AUTHOR John Napiorkowski Ejjn1056 at yahoo.comE -=head1 COPYRIGHT +=head1 LICENSE - Copyright (c) 2008 John Napiorkowski. All rights reserved + Copyright (c) 2008 John Napiorkowski. + This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.