1 package MooseX::Types::DateTimeX;
7 our $AUTHORITY = 'cpan:JJNAPIORK';
11 use MooseX::Types::DateTime;
12 use MooseX::Types::Moose qw/Num HashRef Str/;
14 -declare => [qw( DateTime )];
18 MooseX::Types::DateTimeX - Extensions to L<MooseX::Types::DateTime>
22 package MyApp::MyClass;
24 use MooseX::Types::DateTimeX qw( DateTime );
32 my $instance = MyApp::MyClass->new(created=>'January 1, 1980');
33 print $instance->created->year; # is 1980
35 ## Coercions from the base type continue to work as normal.
36 my $instance = MyApp::MyClass->new(created=>{year=>2000,month=>1,day=>10});
38 Please see the test case for more example usage.
42 This module builds on L<MooseX::Types::DateTime> to add additional custom
43 types and coercions. Since it builds on an existing type, all coercions and
44 constraints are inherited.
48 This module defines the following additional subtypes.
52 Subtype of 'DateTime'. Adds an additional coercion from strings.
54 Uses L<DateTimeX::Easy> to try and convert strings, like "yesterday" into a
55 valid L<DateTime> object. Please note that due to ambiguity with how different
56 systems might localize their timezone, string parsing may not always return
57 the most expected value. IN general we try to localize to UTC whenever
58 possible. Feedback welcomed!
63 as 'DateTime'; ## From MooseX::Types::DateTime
67 via { 'DateTime'->from_epoch( epoch => $_ ) },
69 via { 'DateTime'->new( %$_ ) },
71 via { DateTimeX::Easy->new($_, default_time_zone=>'UTC') };
76 John Napiorkowski E<lt>jjn1056 at yahoo.comE<gt>
80 Copyright (c) 2008 John Napiorkowski. All rights reserved
81 This program is free software; you can redistribute
82 it and/or modify it under the same terms as Perl itself.