.\" Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .if !\nF .nr F 0 .if \nF>0 \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} .\} .\" ======================================================================== .\" .IX Title "Types::DateTime 3pm" .TH Types::DateTime 3pm "2017-06-21" "perl v5.24.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Types::DateTime \- type constraints and coercions for datetime objects .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& package FroobleGala; \& \& use Moose; \& use Types::DateTime \-all; \& \& has start_date => ( \& is => \*(Aqro\*(Aq, \& isa => DateTimeUTC\->plus_coercions( Format[\*(AqISO8601\*(Aq] ), \& coerce => 1, \& ); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Types::DateTime is a type constraint library suitable for use with Moo/Moose attributes, Kavorka sub signatures, and so forth. .SS "Types" .IX Subsection "Types" This module provides some type constraints broadly compatible with those provided by MooseX::Types::DateTime, plus a couple of extra type constraints. .ie n .IP """DateTime""" 4 .el .IP "\f(CWDateTime\fR" 4 .IX Item "DateTime" A class type for DateTime. Coercions from: .RS 4 .ie n .IP "from ""Num""" 4 .el .IP "from \f(CWNum\fR" 4 .IX Item "from Num" Uses \*(L"from_epoch\*(R" in DateTime. Floating values will be used for sub-second precision, see DateTime for details. .ie n .IP "from ""HashRef""" 4 .el .IP "from \f(CWHashRef\fR" 4 .IX Item "from HashRef" Calls \*(L"new\*(R" in DateTime or \*(L"from_epoch\*(R" in DateTime as appropriate, passing the hash as arguments. .ie n .IP "from ""Now""" 4 .el .IP "from \f(CWNow\fR" 4 .IX Item "from Now" Uses \*(L"now\*(R" in DateTime. .ie n .IP "from ""InstanceOf[\*(AqDateTime::Tiny\*(Aq]""" 4 .el .IP "from \f(CWInstanceOf[\*(AqDateTime::Tiny\*(Aq]\fR" 4 .IX Item "from InstanceOf[DateTime::Tiny]" Inflated using \*(L"DateTime\*(R" in DateTime::Tiny. .RE .RS 4 .RE .ie n .IP """Duration""" 4 .el .IP "\f(CWDuration\fR" 4 .IX Item "Duration" A class type for DateTime::Duration. Coercions from: .RS 4 .ie n .IP "from ""Num""" 4 .el .IP "from \f(CWNum\fR" 4 .IX Item "from Num" Uses \*(L"new\*(R" in DateTime::Duration and passes the number as the \f(CW\*(C`seconds\*(C'\fR argument. .ie n .IP "from ""HashRef""" 4 .el .IP "from \f(CWHashRef\fR" 4 .IX Item "from HashRef" Calls \*(L"new\*(R" in DateTime::Duration with the hash entries as arguments. .RE .RS 4 .RE .ie n .IP """Locale""" 4 .el .IP "\f(CWLocale\fR" 4 .IX Item "Locale" A class type for DateTime::Locale. Coercions from: .RS 4 .ie n .IP "from ""Str""" 4 .el .IP "from \f(CWStr\fR" 4 .IX Item "from Str" The string is treated as a language tag (e.g. \f(CW\*(C`en\*(C'\fR or \f(CW\*(C`he_IL\*(C'\fR) and given to \*(L"load\*(R" in DateTime::Locale. .ie n .IP "from ""InstanceOf[\*(AqLocale::Maketext\*(Aq]""" 4 .el .IP "from \f(CWInstanceOf[\*(AqLocale::Maketext\*(Aq]\fR" 4 .IX Item "from InstanceOf[Locale::Maketext]" The \f(CW\*(C`Locale::Maketext/language_tag\*(C'\fR attribute will be used with \&\*(L"load\*(R" in DateTime::Locale. .RE .RS 4 .RE .ie n .IP """TimeZone""" 4 .el .IP "\f(CWTimeZone\fR" 4 .IX Item "TimeZone" A class type for DateTime::TimeZone. Coercions from: .RS 4 .ie n .IP "from ""Str""" 4 .el .IP "from \f(CWStr\fR" 4 .IX Item "from Str" Treated as a time zone name or offset. See \*(L"\s-1USAGE\*(R"\s0 in DateTime::TimeZone for more details on the allowed values. .Sp Delegates to \*(L"new\*(R" in DateTime::TimeZone with the string as the \f(CW\*(C`name\*(C'\fR argument. .RE .RS 4 .RE .ie n .IP """Now""" 4 .el .IP "\f(CWNow\fR" 4 .IX Item "Now" Type constraint with only one allowed value, the string \*(L"now\*(R". .Sp This is exported for compatibility with MooseX::Types::DateTime, which exports such a constraint, even though it is not documented. .ie n .IP """DateTimeWithZone""" 4 .el .IP "\f(CWDateTimeWithZone\fR" 4 .IX Item "DateTimeWithZone" A subtype of \f(CW\*(C`DateTime\*(C'\fR for objects with a defined (non-floating) time zone. .Sp This type constraint inherits its coercions from \f(CW\*(C`DateTime\*(C'\fR. .ie n .IP """DateTimeWithZone[\`a]""" 4 .el .IP "\f(CWDateTimeWithZone[\`a]\fR" 4 .IX Item "DateTimeWithZone[a]" The \f(CW\*(C`DateTimeWithZone\*(C'\fR type constraint may be parameterized with a DateTime::TimeZone object, or a string that can be coerced into one. .Sp .Vb 5 \& has start_date => ( \& is => \*(Aqro\*(Aq, \& isa => DateTimeWithZone[\*(AqEurope/London\*(Aq], \& coerce => 1, \& ); .Ve .Sp This type constraint inherits its coercions from \f(CW\*(C`DateTime\*(C'\fR, and will additionally call \*(L"set_time_zone\*(R" in DateTime to shift objects into the correct timezone. .ie n .IP """DateTimeUTC""" 4 .el .IP "\f(CWDateTimeUTC\fR" 4 .IX Item "DateTimeUTC" Shortcut for \f(CW\*(C`DateTimeWithZone["UTC"]\*(C'\fR. .SS "Named Coercions" .IX Subsection "Named Coercions" 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: .PP .Vb 7 \& has start_date => ( \& is => \*(Aqro\*(Aq, \& isa => DateTime\->plus_coercions( \& InstanceOf[\*(AqMyApp::DT\*(Aq] => sub { $_\->to_DateTime } \& ), \& coerce => 1, \& ); .Ve .PP Even easier, this module exports some named coercions. .ie n .IP """Format[\`a]""" 4 .el .IP "\f(CWFormat[\`a]\fR" 4 .IX Item "Format[a]" May be passed an object providing a \f(CW\*(C`parse_datetime\*(C'\fR method, or a class name from the \f(CW\*(C`DateTime::Format::\*(C'\fR namespace (upon which \&\f(CW\*(C`new\*(C'\fR will be called). .Sp For example: .Sp .Vb 1 \& DateTime\->plus_coercions( Format[\*(AqISO8601\*(Aq] ) .Ve .Sp Or: .Sp .Vb 5 \& DateTimeUTC\->plus_coercions( \& Format[ \& DateTime::Format::Natural\->new(lang => \*(Aqen\*(Aq) \& ] \& ) .Ve .ie n .IP """Strftime[\`a]""" 4 .el .IP "\f(CWStrftime[\`a]\fR" 4 .IX Item "Strftime[a]" A pattern for serializing a DateTime object into a string using \&\*(L"strftime\*(R" in DateTime. .Sp .Vb 1 \& Str\->plus_coercions( Strftime[\*(Aq%a %e %b %Y\*(Aq] ); .Ve .ie n .IP """ToISO8601""" 4 .el .IP "\f(CWToISO8601\fR" 4 .IX Item "ToISO8601" A coercion for serializing a DateTime object into a string using \&\*(L"iso8601\*(R" in DateTime. .Sp .Vb 1 \& Str\->plus_coercions( ToISO8601 ); .Ve .SH "BUGS" .IX Header "BUGS" Please report any bugs to . .SH "SEE ALSO" .IX Header "SEE ALSO" MooseX::Types::DateTime, Type::Tiny::Manual, DateTime, DateTime::Duration, DateTime::Locale, DateTime::TimeZone. .SH "AUTHOR" .IX Header "AUTHOR" Toby Inkster . .SH "COPYRIGHT AND LICENCE" .IX Header "COPYRIGHT AND LICENCE" This software is copyright (c) 2014, 2017 by Toby Inkster. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. .SH "DISCLAIMER OF WARRANTIES" .IX Header "DISCLAIMER OF WARRANTIES" \&\s-1THIS PACKAGE IS PROVIDED \*(L"AS IS\*(R" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.\s0