Types::DateTime(3pm)
π Types::DateTime π
okay bestie, so this is Types::DateTime β it lives in the User Contributed Perl Documentation section of your man pages, and it is literally the type-constraint-and-coercion glow-up for datetime objects. it's giving "your Moose attributes finally got taste" β¨
πΈ NAME πΈ
Types::DateTime β type constraints and coercions for datetime objects π
π SYNOPSIS π
package FroobleGala;
use Moose;
use Types::DateTime -all;
has start_date => (
is => 'ro',
isa => DateTimeUTC->plus_coercions( Format['ISO8601'] ),
coerce => 1,
);
β¨ DESCRIPTION β¨
okay so Types::DateTime is a type constraint library, and it's built for use with Moo/Moose attributes, Kavorka sub signatures, and so forth. she's versatile, she's booked, she's everywhere π¦
π Types
this module provides some type constraints that are broadly compatible with the ones MooseX::Types::DateTime hands out, plus a couple of extra type constraints. bonus content, no cap.
DateTime
a class type for DateTime. and she coerces from:
- from
Numβ usesfrom_epochin DateTime. floating values will be used for sub-second precision, see DateTime for the details. yes, sub-second. we're precise here π - from
HashRefβ callsnewin DateTime orfrom_epochin DateTime as appropriate, passing the hash as arguments. - from
Nowβ usesnowin DateTime. - from
InstanceOf['DateTime::Tiny']β inflated usingDateTimein DateTime::Tiny.
Duration
a class type for DateTime::Duration. coerces from:
- from
Numβ usesnewin DateTime::Duration and passes the number as thesecondsargument. - from
HashRefβ callsnewin DateTime::Duration with the hash entries as arguments.
Locale
a class type for DateTime::Locale. coerces from:
- from
Strβ the string is treated as a language tag (e.g.enorhe_IL) and given toloadin DateTime::Locale. - from
InstanceOf['Locale::Maketext']β theLocale::Maketext/language_tagattribute will be used withloadin DateTime::Locale.
TimeZone
a class type for DateTime::TimeZone. coerces from:
- from
Strβ treated as a time zone name or offset. seeUSAGEin DateTime::TimeZone for more details on the allowed values.
delegates to new in DateTime::TimeZone with the string as the name argument.
Now
type constraint with only one allowed value, the string now.
this is exported for compatibility with MooseX::Types::DateTime, which exports such a constraint, even though it is not documented. π (yes bestie, undocumented. we're just being polite about it.)
DateTimeWithZone
a subtype of DateTime for objects with a defined (non-floating) time zone.
this type constraint inherits its coercions from DateTime. π
DateTimeWithZone[a]`
the DateTimeWithZone type constraint may be parameterized with a DateTime::TimeZone object, or a string that can be coerced into one.
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. moving you to London, metaphorically π¦
DateTimeUTC
shortcut for DateTimeWithZone["UTC"]. that's it. that's the whole vibe. β¨
π 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. (we do not need a hundred of those, bestie, we need β¨oneβ¨.) 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. π
Format[a]`
may be passed an object providing a parse_datetime method, or a class name from the DateTime::Format:: namespace (upon which new will be called).
for example:
DateTime->plus_coercions( Format['ISO8601'] )
or:
DateTimeUTC->plus_coercions(
Format[
DateTime::Format::Natural->new(lang => 'en')
]
)
Strftime[a]`
a pattern for serializing a DateTime object into a string using strftime in DateTime.
Str->plus_coercions( Strftime['%a %e %b %Y'] );
ToISO8601
a coercion for serializing a DateTime object into a string using iso8601 in DateTime.
Str->plus_coercions( ToISO8601 );
π BUGS π
please report any bugs to <http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime>. bestie if something's broken, tell the internet, not me π
π SEE ALSO π
MooseX::Types::DateTime, Type::Tiny::Manual, DateTime, DateTime::Duration, DateTime::Locale, DateTime::TimeZone.
π«Ά AUTHOR π«Ά
Toby Inkster <tobyink@cpan.org>. an icon, an absolute legend π
π COPYRIGHT AND LICENCE π
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.
π DISCLAIMER OF WARRANTIES π
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.
okay so this is the part where we all pretend we're chill about it: no warranties, periodt. merchantability? fitness for a particular purpose? not promised, bestie. it's giving "you get what you get and you don't get upset." π
and that's the whole page!! π this lil doc was rendered from perl v5.34.0 and dated 2022-06-28 β so if you're reading this from the future, hiii, hope the datetime types still slay. bye bestie!! ππ¦β¨
π¦ where this page comes from
- debian bookworm: libtypes-datetime-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtypes-datetime-perl 0.002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms