Types::DateTime(3pm) | User Contributed Perl Documentation | Types::DateTime(3pm) |
Types::DateTime - type constraints and coercions for datetime objects
package FroobleGala; use Moose; use Types::DateTime -all; has start_date => ( is => 'ro', isa => DateTimeUTC->plus_coercions( Format['ISO8601'] ), coerce => 1, );
Types::DateTime is a type constraint library suitable for use with Moo/Moose attributes, Kavorka sub signatures, and so forth.
This module provides some type constraints broadly compatible with those provided by MooseX::Types::DateTime, plus a couple of extra type constraints.
Delegates to "new" in DateTime::TimeZone with the string as the "name" argument.
This is exported for compatibility with MooseX::Types::DateTime, which exports such a constraint, even though it is not documented.
This type constraint inherits its coercions from "DateTime".
has start_date => ( is => 'ro', isa => DateTimeWithZone['Europe/London'], coerce => 1, );
This type constraint inherits its coercions from "DateTime", and will additionally call "set_time_zone" in DateTime to shift objects into the correct timezone.
It is hoped that Type::Tiny will help avoid the proliferation of modules like MooseX::Types::DateTimeX, MooseX::Types::DateTime::ButMaintained, and MooseX::Types::DateTime::MoreCoercions. It makes it very easy to add coercions to a type constraint at the point of use:
has start_date => ( is => 'ro', isa => DateTime->plus_coercions( InstanceOf['MyApp::DT'] => sub { $_->to_DateTime } ), coerce => 1, );
Even easier, this module exports some named coercions.
For example:
DateTime->plus_coercions( Format['ISO8601'] )
Or:
DateTimeUTC->plus_coercions( Format[ DateTime::Format::Natural->new(lang => 'en') ] )
Str->plus_coercions( Strftime['%a %e %b %Y'] );
Str->plus_coercions( ToISO8601 );
Please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime>.
MooseX::Types::DateTime, Type::Tiny::Manual, DateTime, DateTime::Duration, DateTime::Locale, DateTime::TimeZone.
Toby Inkster <tobyink@cpan.org>.
This software is copyright (c) 2014, 2017 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2017-06-21 | perl v5.24.1 |