logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

MooseX::Types::DateTime::MoreCoercions - Extensions to MooseX::Types::DateTime

Author

       John Napiorkowski <jjn1056 at yahoo.com>

       Broken into a separate package from MooseX::Types::DateTime by Evan Carroll.

       Forked  from  MooseX::Types::DateTimeX  and  ported back to use MooseX::Types::DateTime by Dagfinn Ilmari
       Mannsaaker <ilmari@ilmari.org>.

Authors

       •   John Napiorkowski <jjn1056@yahoo.com>

       •   Dagfinn Ilmari Mannsaaker <ilmari@ilmari.org>

Caveats

       Firstly, this module uses DateTimeX::Easy which is way more DWIM than any sane person would desire.
       DateTimeX::Easy works by falling back until something makes sense, this is variable. Furthermore, all the
       modules that DateTimeX::Easy *can* use aren't required for "proper" function of DateTimeX::Easy. What
       does this mean? Simple, your mileage may vary in your coercions because DateTimeX::Easy is installation
       specific.

Contributors

       •   Karen Etheridge <ether@cpan.org>

       •   Evan Carroll <me+cpan@evancarroll.com>

       •   gregor herrmann <gregoa@debian.org>

Description

       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.

Name

       MooseX::Types::DateTime::MoreCoercions - Extensions to MooseX::Types::DateTime

See Also

       •   MooseX::Types::DateTime Replacement for this module -- coercions with less voodoo

       •   DateTimeX::Easy Backend of this module

       •   Time::Duration::Parse Duration parsing backend for this module

Subtypes

       This module defines the following additional subtypes.

   DateTime
       Subtype of "DateTime" in MooseX::Types::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 "Duration" in MooseX::Types::DateTime that coerces from a string.  We use the module
       Time::Duration::Parse to attempt this.

Synopsis

           package MyApp::MyClass;

           use MooseX::Types::DateTime::MoreCoercions 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.

Version

       version 0.15

See Also