MooseX...ateTime(3pm)

πŸ’– MooseX::Types::DateTime πŸ’–

okay so bestie, this is the MooseX::Types::DateTime page β€” (3pm) energy, straight outta the User Contributed Perl Documentation section. Pull up a chair, we're doing DateTime types together 🫢


✨ NAME ✨

MooseX::Types::DateTime β€” DateTime related constraints and coercions for Moose. that's it, that's the whole vibe πŸ’…


🌈 VERSION 🌈

version 0.14 β€” yeah she's on 0.14, and she's iconic for it ✨


πŸŽ€ SYNOPSIS πŸŽ€

Export Example β€” when you just wanna pull the type in by name:

use MooseX::Types::DateTime qw(TimeZone);

has time_zone => (
    isa => TimeZone,
    is => "rw",
    coerce => 1,
);

Class->new( time_zone => "Africa/Timbuktu" );

like, that's literally it. Africa/Timbuktu goes in, a whole time zone comes out. no cap πŸ¦‹


🧚 DESCRIPTION 🧚

So the tea is: this module packages several Moose::Util::TypeConstraints with coercions, and the whole point of them is to play nice with the DateTime suite of objects. that's the main character premise, periodt.

Namespaced Example β€” same idea, but you're not exporting anything and you just write the class name out in full:

use MooseX::Types::DateTime;

has time_zone => (
    isa => 'DateTime::TimeZone',
    is => "rw",
    coerce => 1,
);

Class->new( time_zone => "Africa/Timbuktu" );

see how it just slaps? both ways work, pick your fighter πŸ’–


πŸ‘‘ CONSTRAINTS πŸ‘‘

literally the whole point of this page, bestie. this is where the type constraints live.

πŸ’œ DateTime

A class type for DateTime.

  • from Num β€” Uses from_epoch in DateTime. Floating values will be used for sub-second precision, see DateTime for details. yes, you read that right, floats are getting you sub-second precision, she's fancy like that ⭐
  • from HashRef β€” Calls new in DateTime with the hash entries as arguments. cute, direct, no notes.

πŸ“ Duration

A class type for DateTime::Duration.

  • from Num β€” Uses new in DateTime::Duration and passes the number as the seconds argument.
😭 okay listen up because this one bites people: due to leap seconds, DST changes etc this may not do what you expect. For instance passing in 86400 is not always equivalent to one day, although there are that many seconds in a day. See "How Date Math is Done" in DateTime for more details. fr fr, don't get got by the clocks, they're lowkey shady.
  • from HashRef β€” Calls new in DateTime::Duration with the hash entries as arguments. this one's the safe cozy path πŸ’…

🌸 DateTime::Locale

A class type for DateTime::Locale::root with the name DateTime::Locale.

  • from Str β€” The string is treated as a language tag (e.g. "en" or "he_IL") and given to load in DateTime::Locale. it's giving very international of you ✈️
  • from Locale::Maktext β€” The Locale::Maketext/language_tag attribute will be used with load in DateTime::Locale. (yes bestie, that spelling is exactly what the docs say, we do not fix, we report 🫑)

πŸ¦‹ DateTime::TimeZone

A class type for DateTime::TimeZone.

  • from Str β€” Treated as a time zone name or offset. See "USAGE" in DateTime::TimeZone for more details on the allowed values.

Delegates to new in DateTime::TimeZone with the string as the name argument.

so "Africa/Timbuktu" comes in as a string and gets handed straight to new as name. delegated, done, slayed πŸ‘‘


πŸ’Œ SEE ALSO πŸ’Œ

go read these too, they're the friends of the family:

  • MooseX::Types::DateTime::MoreCoercions
  • DateTime, DateTimeX::Easy

🫢 GIVING THANKS 🫢

If you found this module to be useful, please show your appreciation by:

seriously, a lil +1 and a star? that's it. that's the whole ask. it fuels us πŸ₯Ήβœ¨


πŸ’¬ SUPPORT πŸ’¬

Bugs may be submitted through the RT bug tracker at https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-Types-DateTime (or bug-MooseX-Types-DateTime@rt.cpan.org).

There is also a mailing list available for users of this distribution, at http://lists.perl.org/list/moose.html.

There is also an irc channel available for users of this distribution, at #moose on irc.perl.org (irc://irc.perl.org/#moose).

come say hi in #moose, the group chat is always open 🫢


🧚 AUTHOR 🧚

Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman) nothingmuch@woobling.org


⭐ CONTRIBUTORS ⭐

  • Karen Etheridge ether@cpan.org
  • Dagfinn Ilmari MannsΓ₯ker ilmari@ilmari.org
  • Florian Ragwitz rafl@debian.org
  • John Napiorkowski jjnapiork@cpan.org
  • Dave Rolsky autarch@urth.org
  • Shawn M Moore sartak@gmail.com

these are the icons who helped build the house, show respect πŸ’…


This software is copyright (c) 2008 by Χ™Χ•Χ‘Χœ Χ§Χ•Χ’'מן (Yuval Kogman).

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the page bestie πŸŽ€ generated for perl v5.40.1, dated 2026-01-18, under the MooseX...ateTime(3pm) manual name β€” go forth, coerce some time zones, and remember: floats for sub-second precision, and 86400 seconds is not always a day. πŸŒˆπŸ’–βœ¨

πŸ“¦ where this page comes from