COPYRIGHT000664001750001750 256513121774461 14421 0ustar00taitai000000000000Types-DateTime-0.002Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: Types-DateTime Upstream-Contact: Toby Inkster (TOBYINK) Source: https://metacpan.org/release/Types-DateTime Files: Changes META.json META.yml doap.ttl Copyright: Copyright 2017 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: COPYRIGHT CREDITS SIGNATURE Copyright: None License: public-domain Files: t/01basic.t t/03format.t t/04tostr.t Copyright: This software is copyright (c) 2014 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: README lib/Types/DateTime.pm Copyright: This software is copyright (c) 2014, 2017 by Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: INSTALL LICENSE Copyright: Unknown License: Unknown Files: Makefile.PL Copyright: Copyright 2013 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 Files: t/02mxtdt.t Copyright: Copyright (c) 2008-2014 Yuval Kogman. License: GPL-1.0+ or Artistic-1.0 Files: dist.ini Copyright: Copyright 2014 Toby Inkster. License: GPL-1.0+ or Artistic-1.0 License: Artistic-1.0 This software is Copyright (c) 2017 by the copyright holder(s). This is free software, licensed under: The Artistic License 1.0 License: GPL-1.0 This software is Copyright (c) 2017 by the copyright holder(s). This is free software, licensed under: The GNU General Public License, Version 1, February 1989 CREDITS000664001750001750 25113121774460 14113 0ustar00taitai000000000000Types-DateTime-0.002Maintainer: - Toby Inkster (TOBYINK) Contributor: - Dagfinn Ilmari MannsÃ¥ker (ILMARI) - Dave Rolsky (DROLSKY) Changes000664001750001750 115313121774460 14410 0ustar00taitai000000000000Types-DateTime-0.002Types-DateTime ============== Created: 2014-03-16 Home page: Bug tracker: Maintainer: Toby Inkster (TOBYINK) 0.002 2017-06-19 - Updated: Compatibility fixed for newer DateTime::Locale. Dagfinn Ilmari MannsÃ¥ker++ Dave Rolsky++ 0.001 2014-04-03 [ Documentation ] - Minor improvements to the documentation. [ Test Suite ] - Improvements to test cases for Format. [ Other ] - Allow DateTime to be coerced from a hashref { epoch => $t }. 0.000_01 2014-03-17 Preview INSTALL000664001750001750 170413121774460 14150 0ustar00taitai000000000000Types-DateTime-0.002 Installing Types-DateTime should be straightforward. INSTALLATION WITH CPANMINUS If you have cpanm, you only need one line: % cpanm Types::DateTime If you are installing into a system-wide directory, you may need to pass the "-S" flag to cpanm, which uses sudo to install the module: % cpanm -S Types::DateTime INSTALLATION WITH THE CPAN SHELL Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan Types::DateTime MANUAL INSTALLATION As a last resort, you can manually install it. Download the tarball and unpack it. Consult the file META.json for a list of pre-requisites. Install these first. To build Types-DateTime: % perl Makefile.PL % make && make test Then install it: % make install If you are installing into a system-wide directory, you may need to run: % sudo make install LICENSE000664001750001750 4365513121774460 14157 0ustar00taitai000000000000Types-DateTime-0.002This software is copyright (c) 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. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2017 by Toby Inkster. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2017 by Toby Inkster. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. 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. The End MANIFEST000664001750001750 27413121774461 14232 0ustar00taitai000000000000Types-DateTime-0.002COPYRIGHT CREDITS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README SIGNATURE dist.ini doap.ttl lib/Types/DateTime.pm t/01basic.t t/02mxtdt.t t/03format.t t/04tostr.t META.json000664001750001750 446313121774461 14546 0ustar00taitai000000000000Types-DateTime-0.002{ "abstract" : "type constraints and coercions for datetime objects", "author" : [ "Toby Inkster (TOBYINK) " ], "dynamic_config" : 0, "generated_by" : "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150005", "keywords" : [], "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "Types-DateTime", "no_index" : { "directory" : [ "eg", "examples", "inc", "t", "xt" ] }, "optional_features" : {}, "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "6.17" } }, "develop" : { "recommends" : { "Dist::Inkt" : "0.001" } }, "runtime" : { "requires" : { "DateTime" : "0", "DateTime::Duration" : "0", "DateTime::Locale" : "0", "DateTime::TimeZone" : "0", "Module::Runtime" : "0", "Type::Tiny" : "0.041", "perl" : "5.008" } }, "test" : { "recommends" : { "DateTime::Format::ISO8601" : "0.06", "Moose" : "2.06" }, "requires" : { "Test::Modern" : "0" } } }, "provides" : { "Types::DateTime" : { "file" : "lib/Types/DateTime.pm", "version" : "0.002" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime" }, "homepage" : "https://metacpan.org/release/Types-DateTime", "license" : [ "http://dev.perl.org/licenses/" ], "repository" : { "type" : "git", "url" : "git://github.com/tobyink/p5-types-datetime.git", "web" : "https://github.com/tobyink/p5-types-datetime" }, "x_identifier" : "http://purl.org/NET/cpan-uri/dist/Types-DateTime/project" }, "version" : "0.002", "x_contributors" : [ "Dave Rolsky (DROLSKY) ", "Dagfinn Ilmari MannsÃ¥ker (ILMARI) " ], "x_serialization_backend" : "JSON::PP version 2.27300_01", "x_static_install" : 1 } META.yml000664001750001750 247013121774461 14372 0ustar00taitai000000000000Types-DateTime-0.002--- abstract: 'type constraints and coercions for datetime objects' author: - 'Toby Inkster (TOBYINK) ' build_requires: Test::Modern: '0' configure_requires: ExtUtils::MakeMaker: '6.17' dynamic_config: 0 generated_by: 'Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150005' keywords: [] license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Types-DateTime no_index: directory: - eg - examples - inc - t - xt optional_features: {} provides: Types::DateTime: file: lib/Types/DateTime.pm version: '0.002' requires: DateTime: '0' DateTime::Duration: '0' DateTime::Locale: '0' DateTime::TimeZone: '0' Module::Runtime: '0' Type::Tiny: '0.041' perl: '5.008' resources: Identifier: http://purl.org/NET/cpan-uri/dist/Types-DateTime/project bugtracker: http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime homepage: https://metacpan.org/release/Types-DateTime license: http://dev.perl.org/licenses/ repository: git://github.com/tobyink/p5-types-datetime.git version: '0.002' x_contributors: - 'Dave Rolsky (DROLSKY) ' - 'Dagfinn Ilmari MannsÃ¥ker (ILMARI) ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_static_install: 1 Makefile.PL000664001750001750 1346413121774461 15120 0ustar00taitai000000000000Types-DateTime-0.002use strict; use ExtUtils::MakeMaker 6.17; my $EUMM = eval( $ExtUtils::MakeMaker::VERSION ); my $meta = { "abstract" => "type constraints and coercions for datetime objects", "author" => ["Toby Inkster (TOBYINK) "], "dynamic_config" => 0, "generated_by" => "Dist::Inkt::Profile::TOBYINK version 0.024, CPAN::Meta::Converter version 2.150005", "keywords" => [], "license" => ["perl_5"], "meta-spec" => { url => "http://search.cpan.org/perldoc?CPAN::Meta::Spec", version => 2, }, "name" => "Types-DateTime", "no_index" => { directory => ["eg", "examples", "inc", "t", "xt"] }, "prereqs" => { configure => { requires => { "ExtUtils::MakeMaker" => 6.17 } }, develop => { recommends => { "Dist::Inkt" => 0.001 } }, runtime => { requires => { "DateTime" => 0, "DateTime::Duration" => 0, "DateTime::Locale" => 0, "DateTime::TimeZone" => 0, "Module::Runtime" => 0, "perl" => 5.008, "Type::Tiny" => 0.041, }, }, test => { recommends => { "DateTime::Format::ISO8601" => 0.06, "Moose" => 2.06 }, requires => { "Test::Modern" => 0 }, }, }, "provides" => { "Types::DateTime" => { file => "lib/Types/DateTime.pm", version => 0.002 }, }, "release_status" => "stable", "resources" => { bugtracker => { web => "http://rt.cpan.org/Dist/Display.html?Queue=Types-DateTime", }, homepage => "https://metacpan.org/release/Types-DateTime", license => ["http://dev.perl.org/licenses/"], repository => { type => "git", url => "git://github.com/tobyink/p5-types-datetime.git", web => "https://github.com/tobyink/p5-types-datetime", }, x_identifier => "http://purl.org/NET/cpan-uri/dist/Types-DateTime/project", }, "version" => 0.002, "x_contributors" => [ "Dave Rolsky (DROLSKY) ", "Dagfinn Ilmari Manns\xE5ker (ILMARI) ", ], "x_static_install" => 1, }; my %dynamic_config; my %WriteMakefileArgs = ( ABSTRACT => $meta->{abstract}, AUTHOR => ($EUMM >= 6.5702 ? $meta->{author} : $meta->{author}[0]), DISTNAME => $meta->{name}, VERSION => $meta->{version}, EXE_FILES => [ map $_->{file}, values %{ $meta->{x_provides_scripts} || {} } ], NAME => do { my $n = $meta->{name}; $n =~ s/-/::/g; $n }, test => { TESTS => "t/*.t" }, %dynamic_config, ); $WriteMakefileArgs{LICENSE} = $meta->{license}[0] if $EUMM >= 6.3001; sub deps { my %r; for my $stage (@_) { for my $dep (keys %{$meta->{prereqs}{$stage}{requires}}) { next if $dep eq 'perl'; my $ver = $meta->{prereqs}{$stage}{requires}{$dep}; $r{$dep} = $ver if !exists($r{$dep}) || $ver >= $r{$dep}; } } \%r; } my ($build_requires, $configure_requires, $runtime_requires, $test_requires); if ($EUMM >= 6.6303) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{TEST_REQUIRES} ||= deps('test'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.5503) { $WriteMakefileArgs{BUILD_REQUIRES} ||= deps('build', 'test'); $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime'); } elsif ($EUMM >= 6.52) { $WriteMakefileArgs{CONFIGURE_REQUIRES} ||= deps('configure'); $WriteMakefileArgs{PREREQ_PM} ||= deps('runtime', 'build', 'test'); } else { $WriteMakefileArgs{PREREQ_PM} ||= deps('configure', 'build', 'test', 'runtime'); } { my ($minperl) = reverse sort( grep defined && /^[0-9]+(\.[0-9]+)?$/, map $meta->{prereqs}{$_}{requires}{perl}, qw( configure build runtime ) ); if (defined($minperl)) { die "Installing $meta->{name} requires Perl >= $minperl" unless $] >= $minperl; $WriteMakefileArgs{MIN_PERL_VERSION} ||= $minperl if $EUMM >= 6.48; } } sub FixMakefile { return unless -d 'inc'; my $file = shift; local *MAKEFILE; open MAKEFILE, "< $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; my $makefile = do { local $/; }; close MAKEFILE or die $!; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; open MAKEFILE, "> $file" or die "FixMakefile: Couldn't open $file: $!; bailing out"; print MAKEFILE $makefile or die $!; close MAKEFILE or die $!; } my $mm = WriteMakefile(%WriteMakefileArgs); FixMakefile($mm->{FIRST_MAKEFILE} || 'Makefile'); exit(0); README000664001750001750 1234513121774460 14022 0ustar00taitai000000000000Types-DateTime-0.002NAME 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 Types::DateTime is a type constraint library suitable for use with Moo/Moose attributes, Kavorka sub signatures, and so forth. Types This module provides some type constraints broadly compatible with those provided by MooseX::Types::DateTime, plus a couple of extra type constraints. `DateTime` A class type for DateTime. Coercions from: from `Num` Uses "from_epoch" in DateTime. Floating values will be used for sub-second precision, see DateTime for details. from `HashRef` Calls "new" in DateTime or "from_epoch" in DateTime as appropriate, passing the hash as arguments. from `Now` Uses "now" in DateTime. from `InstanceOf['DateTime::Tiny']` Inflated using "DateTime" in DateTime::Tiny. `Duration` A class type for DateTime::Duration. Coercions from: from `Num` Uses "new" in DateTime::Duration and passes the number as the `seconds` argument. from `HashRef` Calls "new" in DateTime::Duration with the hash entries as arguments. `Locale` A class type for DateTime::Locale. Coercions from: from `Str` The string is treated as a language tag (e.g. `en` or `he_IL`) and given to "load" in DateTime::Locale. from `InstanceOf['Locale::Maketext']` The `Locale::Maketext/language_tag` attribute will be used with "load" in DateTime::Locale. `TimeZone` A class type for DateTime::TimeZone. Coercions from: 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. `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. `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. `DateTimeUTC` Shortcut for `DateTimeWithZone["UTC"]`. 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: 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 . SEE ALSO MooseX::Types::DateTime, Type::Tiny::Manual, DateTime, DateTime::Duration, DateTime::Locale, DateTime::TimeZone. AUTHOR Toby Inkster . 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. SIGNATURE000664001750001750 321313121774461 14401 0ustar00taitai000000000000Types-DateTime-0.002This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.81. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 SHA1 75cd0693b538da1de2aa1c1fad3b3057eccb5a45 COPYRIGHT SHA1 0ff88c3a59765303bf4b480ca4446760385e3e0a CREDITS SHA1 a14e3aed0b476f88ff7a7b0c2f8d19eb403b0e75 Changes SHA1 8205166de30e46af63f8addb45335367f5a8fdc5 INSTALL SHA1 c4c1e6c578edcfd14d13eadebc8f56dd9ca46821 LICENSE SHA1 9260b868a57c706ee1400ce02648e9a8825538df MANIFEST SHA1 55e09555a99945cf64b4e58a57beac49026f2b88 META.json SHA1 6e633077130206a0262e57e3d6a5e2bfd9a4541e META.yml SHA1 e864002251d2dac4b4e1ef628bba9d2c4bf4425c Makefile.PL SHA1 0c37902e707dbf93787c0fc74c5cf2009443893b README SHA1 2aa8c9b23e4d1f91d1694e4f23610b089cf9999d dist.ini SHA1 abeb469656d437b12dd3c3164a5323fed0446b26 doap.ttl SHA1 e19d2f71a10889e4c9ef475dda7c3f911f4e9cba lib/Types/DateTime.pm SHA1 b5ec0227c62abdbddb54a74077e2b5c6c07e664e t/01basic.t SHA1 30cde33803e1310ae6f32d7d0f85c8162c70ea10 t/02mxtdt.t SHA1 84390e366e544b0cec5b57df975b3bcd7ae8b6aa t/03format.t SHA1 a0195a92175042dfedb18e42e9ddcc5eb58359b9 t/04tostr.t -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iEYEARECAAYFAllH+TEACgkQzr+BKGoqfTmiGwCdGX9g+zC2xG352ORbFizPTCLY XR4An3fMAdxbJZx0Rn0rmtyKkxO4HY18 =T3Wc -----END PGP SIGNATURE----- dist.ini000664001750001750 10013121774460 14530 0ustar00taitai000000000000Types-DateTime-0.002;;class='Dist::Inkt::Profile::TOBYINK' ;;name='Types-DateTime' doap.ttl000664001750001750 1164113121774461 14611 0ustar00taitai000000000000Types-DateTime-0.002@prefix cpan-uri: . @prefix dc: . @prefix doap: . @prefix doap-changeset: . @prefix doap-deps: . @prefix foaf: . @prefix rdfs: . @prefix xsd: . dc:title "the same terms as the perl 5 programming language system itself". a doap:Project; dc:contributor ; doap-deps:develop-recommendation [ doap-deps:on "Dist::Inkt 0.001"^^doap-deps:CpanId ]; doap-deps:runtime-requirement [ doap-deps:on "perl 5.008"^^doap-deps:CpanId ], [ doap-deps:on "Type::Tiny 0.041"^^doap-deps:CpanId ], [ doap-deps:on "DateTime"^^doap-deps:CpanId ], [ doap-deps:on "DateTime::Duration"^^doap-deps:CpanId ], [ doap-deps:on "DateTime::Locale"^^doap-deps:CpanId ], [ doap-deps:on "DateTime::TimeZone"^^doap-deps:CpanId ], [ doap-deps:on "Module::Runtime"^^doap-deps:CpanId ]; doap-deps:test-recommendation [ doap-deps:on "Moose 2.06"^^doap-deps:CpanId ], [ doap-deps:on "DateTime::Format::ISO8601 0.06"^^doap-deps:CpanId; ]; doap-deps:test-requirement [ doap-deps:on "Test::Modern"^^doap-deps:CpanId ]; doap:bug-database ; doap:created "2014-03-16"^^xsd:date; doap:developer ; doap:download-page ; doap:homepage ; doap:license ; doap:maintainer ; doap:name "Types-DateTime"; doap:programming-language "Perl"; doap:release , , ; doap:repository [ a doap:GitRepository; doap:browse ; ]; doap:shortdesc "type constraints and coercions for datetime objects". a cpan-uri:DeveloperRelease, doap:Version; rdfs:label "Preview"; dc:identifier "Types-DateTime-0.000_01"^^xsd:string; dc:issued "2014-03-17"^^xsd:date; doap-changeset:released-by ; doap:file-release ; doap:revision "0.000_01"^^xsd:string. a doap:Version; dc:identifier "Types-DateTime-0.001"^^xsd:string; dc:issued "2014-04-03"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Tests; rdfs:label "Improvements to test cases for Format."; ], [ a doap-changeset:Change; rdfs:label "Allow DateTime to be coerced from a hashref { epoch => $t }."; ], [ a doap-changeset:Documentation; rdfs:label "Minor improvements to the documentation."; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.001"^^xsd:string. a doap:Version; dc:identifier "Types-DateTime-0.002"^^xsd:string; dc:issued "2017-06-19"^^xsd:date; doap-changeset:changeset [ doap-changeset:item [ a doap-changeset:Update; rdfs:label "Compatibility fixed for newer DateTime::Locale."; doap-changeset:blame , ; ]; ]; doap-changeset:released-by ; doap:file-release ; doap:revision "0.002"^^xsd:string. a foaf:Person; foaf:name "Dave Rolsky"; foaf:nick "DROLSKY"; foaf:page . a foaf:Person; foaf:name "Dagfinn Ilmari Mannsåker"; foaf:nick "ILMARI"; foaf:page . a foaf:Person; foaf:mbox ; foaf:name "Toby Inkster"; foaf:nick "TOBYINK"; foaf:page . 01basic.t000664001750001750 67713121774460 14761 0ustar00taitai000000000000Types-DateTime-0.002/t=pod =encoding utf-8 =head1 PURPOSE Test that Types::DateTime compiles. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2014 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. =cut use Test::Modern qw( use_ok done_testing ); use_ok('Types::DateTime'); done_testing; 02mxtdt.t000664001750001750 651313121774460 15054 0ustar00taitai000000000000Types-DateTime-0.002/t=pod =encoding utf-8 =head1 PURPOSE Tests stolen from L, and slighty adapted to L. =head1 AUTHOR Yuval Kogman Enothingmuch@woobling.orgE John Napiorkowski Ejjn1056 at yahoo.comE =head1 COPYRIGHT AND LICENCE Copyright (c) 2008-2014 Yuval Kogman. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut use Test::Modern -requires => { Moose => '2.0600' }; use Moose::Util::TypeConstraints; { { package Foo; use Moose; use Types::DateTime qw(DateTime); has date => ( isa => DateTime, is => "rw", coerce => 1, ); } my $epoch = time; my $coerced = Foo->new( date => $epoch )->date; isa_ok( $coerced, "DateTime", "coerced epoch into datetime" ); is( $coerced->epoch, $epoch, "epoch is correct" ); isa_ok( Foo->new( date => { year => 2000, month => 1, day => 1 } )->date, "DateTime" ); isa_ok( Foo->new( date => 'now' )->date, "DateTime" ); like(exception { Foo->new( date => "junk1!!" ) }, qr/DateTime/, "constraint"); } { { package Quxx; use Moose; use Types::DateTime qw(Duration); has duration => ( isa => Duration, is => "rw", coerce => 1, ); } my $coerced = Quxx->new( duration => 10 )->duration; isa_ok( $coerced, "DateTime::Duration", "coerced from seconds" ); my $time = time; my $now = DateTime->from_epoch( epoch => $time ); my $future = $now + $coerced; is( $future->epoch, ( $time + 10 ), "coerced value" ); isa_ok( Quxx->new( duration => { minutes => 2 } )->duration, "DateTime::Duration", "coerced from hash" ); like(exception { Quxx->new( duration => "ahdstkljhat" ) }, qr/DateTime/, "constraint"); } { { package Bar; use Moose; use Types::DateTime qw(TimeZone); has time_zone => ( isa => TimeZone, is => "rw", coerce => 1, ); } my $tz = Bar->new( time_zone => "Africa/Timbuktu" )->time_zone; isa_ok( $tz, "DateTime::TimeZone", "coerced string into time zone object" ); like( $tz->name, qr/^Africa/, "correct time zone" ); like(exception { Bar->new( time_zone => "Space/TheMoon" ) }, qr{The timezone 'Space/TheMoon' could not be loaded}, "bad time zone"); } { { package Gorch; use Moose; use Types::DateTime qw(Locale); has loc => ( isa => Locale, is => "rw", coerce => 1, ); } my $loc = Gorch->new( loc => "he_IL" )->loc; like( $loc->id, qr/he[_\-]IL/, "coerced from string" ); like(exception { Gorch->new( loc => "not_a_place_or_a_locale" ) }, qr/Invalid locale/, "bad locale name"); SKIP: { skip "No Locale::Maketext", 2 unless eval { require Locale::Maketext }; { package Some::L10N; our @ISA = qw(Locale::Maketext); package Some::L10N::ja; our @ISA = qw(Some::L10N); our %Lexicon = ( goodbye => "sayonara", ); } my $handle = Some::L10N->get_handle("ja"); isa_ok( $handle, "Some::L10N", "maketext handle" ); is( Gorch->new( loc => $handle )->loc->id, "ja", "coerced from maketext" );; } } { { package Gondor; use Moose; use Types::DateTime qw(DateTime Duration); has 'date' => (is=>'rw', isa=>DateTime, coerce=>1); has 'duration' => (is=>'rw', isa=>Duration, coerce=>1); } my $epoch = time; ok my $gondor = Gondor->new(date=>$epoch, duration=>10) => 'Instantiated object using export types'; } done_testing; 03format.t000664001750001750 773313121774460 15212 0ustar00taitai000000000000Types-DateTime-0.002/t=pod =encoding utf-8 =head1 PURPOSE Test that C<< Format[`a] >> works. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2014 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. =cut use Test::Modern -requires => { 'DateTime::Format::ISO8601' => '0.06' }; use Types::DateTime -all; object_ok( sub { DateTime->plus_fallback_coercions(Format['ISO8601']) }, '$type', isa => ['Type::Tiny'], can => ['coerce'], more => sub { my $type = shift; is_deeply( $type->coerce(['x', 'y', 'z']), ['x', 'y', 'z'], 'cannot coerce from arrayref', ); object_ok( sub { $type->coerce('now') }, '$dt_from_now', isa => 'DateTime', more => sub { my $self = shift; my $diff = 'DateTime'->now() - $self; cmp_ok($diff->in_units('seconds'), '<', 60, 'looks recent'); }, ); object_ok( sub { $type->coerce('2001-02-03T04:05:06') }, '$dt_from_iso', isa => 'DateTime', more => sub { my $self = shift; is($self->year, 2001, 'year'); is($self->month, 2, 'month'); is($self->day, 3, 'day'); is($self->hour, 4, 'hour'); is($self->minute, 5, 'minute'); is($self->second, 6, 'second'); object_ok( $self->time_zone, '$time_zone', isa => 'DateTime::TimeZone', more => sub { my $time_zone = shift; ok($time_zone->is_floating, 'floating'); }, ); }, ); object_ok( sub { $type->coerce('2001-02-03T04:05:06+08:00') }, '$dt_from_iso_tz', isa => 'DateTime', more => sub { my $self = shift; is($self->year, 2001, 'year'); is($self->month, 2, 'month'); is($self->day, 3, 'day'); is($self->hour, 4, 'hour'); is($self->minute, 5, 'minute'); is($self->second, 6, 'second'); object_ok( $self->time_zone, '$time_zone', isa => 'DateTime::TimeZone', more => sub { my $time_zone = shift; is($time_zone->name, '+0800', 'name'); is($time_zone->offset_for_datetime($self), 8*3600, 'offset_for_datetime'); }, ); }, ); }, ); object_ok( sub { DateTimeUTC->plus_fallback_coercions(Format['ISO8601']) }, '$utc_type', isa => ['Type::Tiny'], can => ['coerce'], more => sub { my $utc_type = shift; is_deeply( $utc_type->coerce(['x', 'y', 'z']), ['x', 'y', 'z'], 'cannot coerce from arrayref', ); object_ok( sub { $utc_type->coerce('now') }, '$dt_from_now', isa => 'DateTime', more => sub { my $self = shift; my $diff = 'DateTime'->now() - $self; cmp_ok($diff->in_units('seconds'), '<', 60, 'looks recent'); }, ); object_ok( sub { $utc_type->coerce('2001-02-03T04:05:06') }, '$dt_from_iso', isa => 'DateTime', more => sub { my $self = shift; is($self->year, 2001, 'year'); is($self->month, 2, 'month'); is($self->day, 3, 'day'); is($self->hour, 4, 'hour'); is($self->minute, 5, 'minute'); is($self->second, 6, 'second'); object_ok( $self->time_zone, '$time_zone', isa => 'DateTime::TimeZone', more => sub { my $time_zone = shift; is($time_zone->name, 'UTC', 'name'); is($time_zone->offset_for_datetime($self), 0, 'offset_for_datetime'); }, ); }, ); object_ok( sub { $utc_type->coerce('2001-02-03T04:05:06+08:00') }, '$dt_from_iso_tz', isa => 'DateTime', more => sub { my $self = shift; is($self->year, 2001, 'year'); is($self->month, 2, 'month'); is($self->day, 2, 'day'); is($self->hour, 20, 'hour'); is($self->minute, 5, 'minute'); is($self->second, 6, 'second'); object_ok( $self->time_zone, '$time_zone', isa => 'DateTime::TimeZone', more => sub { my $time_zone = shift; is($time_zone->name, 'UTC', 'name'); is($time_zone->offset_for_datetime($self), 0, 'offset_for_datetime'); }, ); }, ); }, ); done_testing; 04tostr.t000664001750001750 217313121774460 15067 0ustar00taitai000000000000Types-DateTime-0.002/t=pod =encoding utf-8 =head1 PURPOSE Test that C<< Strftime[`a] >> and C<< ToISO8601 >> work. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 COPYRIGHT AND LICENCE This software is copyright (c) 2014 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. =cut use Test::Modern -requires => { 'Types::Standard' => '0.041' }; use Types::Standard qw( Str ); use Types::DateTime qw( -all ); my $dt = object_ok( sub { DateTimeUTC->coerce(1_000_000_000) }, '$dt', isa => 'DateTime', more => sub { my $dt = shift; is($dt->year, 2001); is($dt->month, 9); is($dt->day, 9); }, ); object_ok( sub { Str->plus_coercions(Strftime['%a %e %b %Y']) }, '$type', isa => 'Type::Tiny', can => [qw/ check coerce /], more => sub { my $type = shift; is($type->coerce($dt), 'Sun 9 Sep 2001'); }, ); object_ok( sub { Str->plus_coercions(ToISO8601) }, '$type', isa => 'Type::Tiny', can => [qw/ check coerce /], more => sub { my $type = shift; is($type->coerce($dt), '2001-09-09T01:46:40'); }, ); done_testing; DateTime.pm000664001750001750 2041213121774460 17040 0ustar00taitai000000000000Types-DateTime-0.002/lib/Typesuse 5.008; use strict; use warnings; package Types::DateTime; our $AUTHORITY = 'cpan:TOBYINK'; our $VERSION = '0.002'; use DateTime; use DateTime::Duration; use DateTime::Locale; use DateTime::TimeZone; use Module::Runtime qw( use_module ); use Type::Library -base, -declare => qw( DateTime Duration TimeZone Locale Now DateTimeWithZone DateTimeUTC ); use Types::Standard qw( Num Str HashRef InstanceOf ); use Type::Utils; # This stuff for compat with MooseX::Types::DateTime class_type(DateTime, { class => 'DateTime' }); class_type(Duration, { class => 'DateTime::Duration' }); class_type(TimeZone, { class => 'DateTime::TimeZone' }); declare Locale, as InstanceOf['DateTime::Locale::root','DateTime::Locale::FromData']; enum(Now, ['now']); coerce DateTime, from Num, q{ 'DateTime'->from_epoch(epoch => $_) }, from HashRef, q{ exists($_->{epoch}) ? 'DateTime'->from_epoch(%$_) : 'DateTime'->new(%{$_}) }, from Now, q{ 'DateTime'->now }, from InstanceOf['DateTime::Tiny'], q{ $_->DateTime }; coerce Duration, from Num, q{ 'DateTime::Duration'->new(seconds => $_) }, from HashRef, q{ 'DateTime::Duration'->new(%{$_}) }; coerce TimeZone, from Str, q{ 'DateTime::TimeZone'->new(name => $_) }; coerce Locale, from InstanceOf['Locale::Maketext'], q{ 'DateTime::Locale'->load($_->language_tag) }, from Str, q{ 'DateTime::Locale'->load($_) }; # Time zone stuff declare DateTimeWithZone, as DateTime, coercion => 1, # inherit coercions where { not($_ ->time_zone->is_floating) }, inline_as { (undef, "not($_\->time_zone->is_floating)") }, constraint_generator => sub { my $zone = TimeZone->assert_coerce(shift); sub { $_[0]->time_zone eq $zone }; }, coercion_generator => sub { my $parent = shift; my $child = shift; my $zone = TimeZone->assert_coerce(shift); my $c = 'Type::Coercion'->new(type_constraint => $child); $c->add_type_coercions( $parent->coercibles, sub { my $dt = DateTime->coerce($_); return $_ unless DateTime->check($dt); $dt->set_time_zone($zone); return $dt; }, ); $c; }; declare DateTimeUTC, as DateTimeWithZone['UTC'], coercion => 1; # Stringy coercions. No sugar for this stuff ;-) __PACKAGE__->meta->add_coercion({ name => 'Format', type_constraint => DateTime, coercion_generator => sub { my ($self, $target, $format) = @_; $format = use_module("DateTime::Format::$format")->new unless ref($format); my $timezone; if ($target->is_a_type_of(DateTimeWithZone)) { my ($paramd_type) = grep { $_->is_parameterized and $_->parent==DateTimeWithZone } ($target, $target->parents); $timezone = TimeZone->assert_coerce($paramd_type->type_parameter) if $paramd_type; } return ( Str, sub { my $dt = eval { $format->parse_datetime($_) }; return $_ unless $dt; $dt->set_time_zone($timezone) if $timezone; $dt; }, ); }, }); __PACKAGE__->meta->add_coercion({ name => 'Strftime', type_constraint => Str, coercion_generator => sub { my ($self, $target, $format) = @_; my $format_quoted = B::perlstring($format); return ( DateTime->coercibles, qq{\$_->strftime($format_quoted)}, ); }, }); __PACKAGE__->meta->add_coercion({ name => 'ToISO8601', type_constraint => Str, type_coercion_map => [ DateTime->coercibles, q{$_->iso8601}, ], }); 1; __END__ =pod =encoding utf-8 =for stopwords datetime timezone =head1 NAME Types::DateTime - type constraints and coercions for datetime objects =head1 SYNOPSIS package FroobleGala; use Moose; use Types::DateTime -all; has start_date => ( is => 'ro', isa => DateTimeUTC->plus_coercions( Format['ISO8601'] ), coerce => 1, ); =head1 DESCRIPTION L is a type constraint library suitable for use with L/L attributes, L sub signatures, and so forth. =head2 Types This module provides some type constraints broadly compatible with those provided by L, plus a couple of extra type constraints. =over =item C A class type for L. Coercions from: =over =item from C Uses L. Floating values will be used for sub-second precision, see L for details. =item from C Calls L or L as appropriate, passing the hash as arguments. =item from C Uses L. =item from C<< InstanceOf['DateTime::Tiny'] >> Inflated using L. =back =item C A class type for L. Coercions from: =over =item from C Uses L and passes the number as the C argument. =item from C Calls L with the hash entries as arguments. =back =item C A class type for L. Coercions from: =over =item from C The string is treated as a language tag (e.g. C or C) and given to L. =item from C<< InstanceOf['Locale::Maketext'] >> The C attribute will be used with L. =back =item C A class type for L. Coercions from: =over =item from C Treated as a time zone name or offset. See L for more details on the allowed values. Delegates to L with the string as the C argument. =back =item C Type constraint with only one allowed value, the string "now". This is exported for compatibility with L, which exports such a constraint, even though it is not documented. =item C A subtype of C for objects with a defined (non-floating) time zone. This type constraint inherits its coercions from C. =item C<< DateTimeWithZone[`a] >> The C type constraint may be parameterized with a L 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 C, and will additionally call L to shift objects into the correct timezone. =item C Shortcut for C<< DateTimeWithZone["UTC"] >>. =back =head2 Named Coercions It is hoped that Type::Tiny will help avoid the proliferation of modules like L, L, and L. 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. =over =item C<< Format[`a] >> May be passed an object providing a C method, or a class name from the C<< DateTime::Format:: >> namespace (upon which C will be called). For example: DateTime->plus_coercions( Format['ISO8601'] ) Or: DateTimeUTC->plus_coercions( Format[ DateTime::Format::Natural->new(lang => 'en') ] ) =item C<< Strftime[`a] >> A pattern for serializing a DateTime object into a string using L. Str->plus_coercions( Strftime['%a %e %b %Y'] ); =item C A coercion for serializing a DateTime object into a string using L. Str->plus_coercions( ToISO8601 ); =back =head1 BUGS Please report any bugs to L. =head1 SEE ALSO L, L, L, L, L, L. =head1 AUTHOR Toby Inkster Etobyink@cpan.orgE. =head1 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. =head1 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.