MooseX::Types::DateTimeX3pm
Extensions to moosex::types::datetime
Usage
package MyApp::MyClass;use MooseX::Types::DateTimeX qw( DateTime );has created => (isa => DateTime,is => "rw",coerce => 1,);my $instance = MyApp::MyClass->new(created=>'January 1, 1980');print $instance->created->year; # is 1980## Coercions from the base type continue to work as normal.my $instance = MyApp::MyClass->new(created=>{year=>2000,month=>1,day=>10});
Please see the test case for more example usage.
Overview
This module builds on MooseX::Types::DateTime to add additional custom types and coercions. Since it builds on an existing type, all coercions and constraints are inherited.
Subtypes
This module defines the following additional subtypes.
DateTime
Subtype of 'DateTime'. Adds an additional coercion from strings.
Uses DateTimeX::Easy to try and convert strings, like "yesterday" into a valid DateTime object. Please note that due to ambiguity with how different systems might localize their timezone, string parsing may not always return the most expected value. IN general we try to localize to UTC whenever possible. Feedback welcomed!
Duration
Subtype of 'DateTime::Duration' that coerces from a string. We use the module Time::Duration::Parse to attempt this.