DateTime-Incomplete-0.08/000755 000767 000024 00000000000 12620365420 016677 5ustar00flavioglockstaff000000 000000 DateTime-Incomplete-0.08/Changes000644 000767 000024 00000006523 12620365301 020176 0ustar00flavioglockstaff000000 000000 Changes file for DateTime::Incomplete 0.08 2015-11-10 - use DateTime::Locale->load() - [rt.cpan.org #108637] Fails with DateTime-Locale-1.01 0.07 2012-08-24 - 5.16 deprecated the use of braces in regexes without escaping them - bug #78914 by garu 0.06 2011-04-01 - next() and previous() work with time zones - bug #67064 0.05 2011-03-31 - removed tests for obsolete format "am_pm" - bug #67041 0.04 2009-07-08 - to_datetime() failed when the current year is a non-leap year and the incomplete date is a leap day, bug reported by Alexandre Masselot. 0.0301 2008-06-21 - updated strftime tests, again. 0.03 2008-01-18 - updated strftime tests, bug reported by cpan testers. 0.02 2004-09-21 - fixed to_spanset(), bug reported by Joshua Hoblitt. 0.0104 2003-11-10 - to_spanset 0.0103 2003-11-06 - start, end, to_span - requires DateTime::Set 0.1401 0.0102 2003-11-06 - to_datetime() uses "today" as a base date, if none was given. The following methods are affected by this change: epoch, hires_epoch, is_dst, utc_rd_values, utc_rd_as_seconds, sprintf("%s") - can_be_datetime() - has_date(), has_time() - defined_fields() method, contributed by Rick Measham - to_datetime() sets fields in a known order, instead of hash-order. Based on a patch by Rick Measham - Included has() method, contributed by Rick Measham 0.0101 2003-11-03 - runs in Perl 5.00503. Dave Rolsky & Flavio S. Glock, creating a cvs conflict :) - there is no set_locale() in DateTime. Modified from a patch by Rick Measham - fixed an infinite loop in _format_nanoseconds. Patch by Rick Measham 0.01 2003-11-01 - documentation revision, by Dave Rolsky - documented the error handling: mutators die / accesors return undef - from_day_of_year does not define "time" by default - DateTime methods: epoch hires_epoch is_dst utc_rd_values utc_rd_as_seconds local_rd_as_seconds - "Storable" hooks - "contains" takes the time_zone into account - fixed "strftime" of incomplete datetimes, epoch 0.00_07 2003-07-25 - set_time_zone / set_locale test for undef args - strftime - time_zone_long_name - today / now / from_epoch / from_object / from_day_of_year 0.00_06 2003-07-25 - DateTime methods: week week_year week_number week_of_month day_name day_abbr day_of_week wday dow day_of_year doy quarter day_of_quarter doq weekday_of_month jd mjd is_leap_year ce_year era year_with_era last_day_of_month month_name month_abbr hour_1 hour_12 hour_12_0 fractional_second millisecond microsecond offset time_zone_short_name - base_class / has_base - added example on how to use "truncate" to generate smaller recurrence sets. 0.00_05 2003-07-24 - next/previous "february" problem fixed. - set( day => undef ) would break if there was a base date. Reported by Dave Rolsky - t/02incomplete.t SKIPs tests properly, when DT::Recurrence is not installed - locale, set_locale - some aliases added, for DateTime compatibility 0.00_04 2003-07-22 - base - next / previous / closest - has_hour, has_month, ... - has(), get() 0.00_03 2003-07-21 - New API: new( ..., base => $dt ) set_base( $dt ) to_datetime() without base - Implemented to_recurrence - Implemented is_undef, to_datetime, contains - All methods in DATETIME-LIKE section are implemented. Most are tested. 0.00_02 2003-07-19 - POD, makefile and CVS upload. 0.00_01 2003-07-17 - 02incomplete.t created. DateTime-Incomplete-0.08/lib/000755 000767 000024 00000000000 12620365420 017445 5ustar00flavioglockstaff000000 000000 DateTime-Incomplete-0.08/LICENSE000644 000767 000024 00000050101 12620364225 017703 0ustar00flavioglockstaff000000 000000 Terms of Perl 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 General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU 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. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), 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 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 show them these terms so they know 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. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. 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 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 derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 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 License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. 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. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary 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 License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 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 Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing 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 for copying, distributing or modifying the Program or works based on it. 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. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. 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 this 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 this License, you may choose any version ever published by the Free Software Foundation. 10. 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 11. 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. 12. 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 --------------------------------------------------------------------------- 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. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. 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 DateTime-Incomplete-0.08/Makefile.PL000644 000767 000024 00000001035 12620364225 020652 0ustar00flavioglockstaff000000 000000 use strict; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'DateTime::Incomplete', VERSION_FROM => 'lib/DateTime/Incomplete.pm', AUTHOR => 'Flavio S. Glock ', ABSTRACT => 'Incomplete DateTime objects', PREREQ_PM => { 'DateTime' => 0, 'DateTime::Set' => 0.1401, 'DateTime::Event::Recurrence' => 0, 'Test::More' => 0, }, ); DateTime-Incomplete-0.08/MANIFEST000644 000767 000024 00000000526 12620365420 020033 0ustar00flavioglockstaff000000 000000 Makefile.PL lib/DateTime/Incomplete.pm TODO LICENSE MANIFEST MANIFEST.SKIP README Changes t/02incomplete.t t/03base.t t/04base_overflow.t t/05datetime.t t/06next.t t/13strftime.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) DateTime-Incomplete-0.08/MANIFEST.SKIP000644 000767 000024 00000000244 12620364225 020577 0ustar00flavioglockstaff000000 000000 ^blib/ ^Makefile$ ^Makefile\.[a-z]+$ ^pm_to_blib$ CVS/.* ,v$ ^tmp/ \.old$ \.bak$ ~$ ^# \.shar$ \.tar$ \.tgz$ \.tar\.gz$ \.zip$ _uu$ t/zz.* test\.[co] benchmarks/.* DateTime-Incomplete-0.08/META.json000644 000767 000024 00000001755 12620365420 020330 0ustar00flavioglockstaff000000 000000 { "abstract" : "Incomplete DateTime objects", "author" : [ "Flavio S. Glock " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001", "license" : [ "unknown" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "DateTime-Incomplete", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "DateTime" : "0", "DateTime::Event::Recurrence" : "0", "DateTime::Set" : "0.1401", "Test::More" : "0" } } }, "release_status" : "stable", "version" : "0.08" } DateTime-Incomplete-0.08/META.yml000644 000767 000024 00000001113 12620365420 020144 0ustar00flavioglockstaff000000 000000 --- abstract: 'Incomplete DateTime objects' author: - 'Flavio S. Glock ' build_requires: ExtUtils::MakeMaker: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.0401, CPAN::Meta::Converter version 2.150001' license: unknown meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: DateTime-Incomplete no_index: directory: - t - inc requires: DateTime: '0' DateTime::Event::Recurrence: '0' DateTime::Set: '0.1401' Test::More: '0' version: '0.08' DateTime-Incomplete-0.08/README000644 000767 000024 00000001344 12620364225 017563 0ustar00flavioglockstaff000000 000000 OVERVIEW The DateTime::Incomplete module aims to complement the complete, correct, and easy date/time object implementation (DateTime). Currently it handles many date calculations, provides no date math (addition and subtraction), and provides many convenient methods for retrieving portions of a date/time. This module properly supports the Olson time zone database, meaning that historical time zone information, and more importantly, daylight saving time rules, can be handled transparently, simply by setting the correct time zone. This is done by using the DateTime::TimeZone module. INSTALLATION To install this module type the following in the distribution directory: perl Makefile.PL make make test make install DateTime-Incomplete-0.08/t/000755 000767 000024 00000000000 12620365420 017142 5ustar00flavioglockstaff000000 000000 DateTime-Incomplete-0.08/TODO000644 000767 000024 00000001756 12620364225 017402 0ustar00flavioglockstaff000000 000000 TODO file for DateTime::Incomplete - Add new methods from DateTime - truncate( to => 'week' ) - test Storable hooks perl -Ilib -MStorable -MDateTime::Incomplete -MData::Dumper -e '$dt=DateTime->new(year=>1970);$dti=DateTime::Incomplete->new( year => 2003, base=>$dt, time_zone => "America/Chicago" );$freeze = Storable::nfreeze( $dti );print "$freeze\n"; ' - more tests for next/previous/closest with year and nanosecond - use $FIELDS[0] instead of 'year'; $FIELDS[-2] instead of nanosecond - change @FIELDS to a "class" constant (instead of "package") - locale and time_zone tests: mixing string and object time_zones; time_zone-only and locale-only DT::I objects. IDEAS * 'undef_char' could be configurable. * add_datetime Just like to_datetime, but adds the field values. * compare or is that simply not defined? * join( $dti ) join the "defined" keys of two DT::Incomplete objects * set_week $dti->set( week => 10 ) * is_incomplete/is_complete How do we know it is complete? DateTime-Incomplete-0.08/t/02incomplete.t000644 000767 000024 00000023264 12620364225 021641 0ustar00flavioglockstaff000000 000000 #!/usr/bin/perl -w use strict; use Test::More tests => 59; use DateTime; use DateTime::Incomplete; use constant INFINITY => 100 ** 100 ** 100 ; use constant NEG_INFINITY => -1 * (100 ** 100 ** 100); my $UNDEF_CHAR = 'x'; my $UNDEF4 = $UNDEF_CHAR x 4; my $UNDEF2 = $UNDEF_CHAR x 2; { # Tests for new(), set(), datetime() my $dti; my $dt = DateTime->new( year => 2003 ); my $str = $dt->datetime; my $dti_clone; my $str_clone; my $dti_half; my $dti_complete; my $str_complete; $dti = DateTime::Incomplete->new( year => $dt->year, month => $dt->month, day => $dt->day, hour => $dt->hour, minute => $dt->minute, second => $dt->second, nanosecond => $dt->nanosecond, ); $dti_complete = $dti->clone; # a fully-defined datetime $str_complete = $dti->datetime; is( $dti->datetime , $dt->datetime, 'new() matches DT->new' ); is( $dti->has_year , 1, 'has year' ); $dti->set( year => undef ); $str =~ s/^2003/$UNDEF4/; is( $dti->datetime , $str, 'undef year' ); is( $dti->has_year , 0, 'has no year' ); $dti->set( month => undef ); $str =~ s/-01-/-$UNDEF2-/; is( $dti->datetime , $str, 'undef month' ); # Tests clone() $dti_clone = $dti->clone; $str_clone = $str; $dti->set( day => undef ); $str =~ s/-01/-$UNDEF2/; is( $dti->datetime , $str, 'undef day' ); is( $dti_clone->datetime , $str_clone, 'clone has day' ); # end: Tests clone() # Tests is_undef, false is( $dti->is_undef , 0, 'not undef' ); # Tests to_datetime $dti_half = $dti->clone; # a half-defined datetime my $dt2 = $dti_half->to_datetime( base => $dt ); is( $dt->datetime , $dt2->datetime, 'to_datetime' ); my $dti2 = $dti_half->clone; $dti2->set_base( $dt ); $dt2 = $dti2->to_datetime; is( $dt->datetime , $dt2->datetime, 'to_datetime + set_base' ); # Tests contains is( $dti->contains( $dt2 ), 1, 'contains' ); $dt2->add( hours => 1 ); is( $dti->contains( $dt2 ), 0, 'does not contain' ); # undef time $dti->set( hour => undef ); $str =~ s/00:/$UNDEF2:/; is( $dti->datetime , $str, 'undef hour' ); $dti->set( minute => undef ); $str =~ s/:00:/:$UNDEF2:/; is( $dti->datetime , $str, 'undef minute' ); $dti->set( second => undef ); $str =~ s/:00/:$UNDEF2/; is( $dti->datetime , $str, 'undef second' ); is( $dti->nanosecond , $dt->nanosecond, 'def nanosecond' ); $dti->set( nanosecond => undef ); ok( ! defined( $dti->nanosecond ), 'undef nanosecond' ); # Tests is_undef, true is( $dti->is_undef , 1, 'is undef' ); # Tests can_be_datetime { is( $dti_complete->can_be_datetime, 1, 'can be datetime' ); my $dt = $dti_complete->clone; $dt->set( year => undef ); is( $dt->can_be_datetime, 0, 'can not be datetime' ); $dt = $dti_complete->clone; $dt->set( nanosecond => undef ); is( $dt->can_be_datetime, 1, 'can be datetime' ); $dt->set( second => undef ); is( $dt->can_be_datetime, 1, 'can be datetime' ); #is( $dt->to_datetime->datetime, '2003-01-01T00:00:00', # 'be datetime' ); $dt->set( month => undef ); is( $dt->can_be_datetime, 0, 'can not be datetime' ); #is( $dt->to_datetime->datetime, '2003-01-01T00:00:00', # 'force to be datetime' ); { $dt->set( second => 30 ); my $dt_start = $dt->start; is( $dt_start->datetime, '2003-01-01T00:00:30', 'start datetime' ); my $dt_end = $dt->end; is( $dt_end->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2003-12-01T00:00:31.000000000', 'end datetime' ); } { $dt->set( second => undef ); is( $dt->start->datetime, '2003-01-01T00:00:00', 'start datetime' ); is( $dt->end->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2003-12-01T00:01:00.000000000', 'end datetime' ); is( "".$dt->to_span->{set}, '[2003-01-01T00:00:00..2003-12-01T00:01:00)', 'span' ); $dt->set( nanosecond => 0 ); # $dt->set( second => 0 ); is( $dt->end->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2003-12-01T00:00:59.000000000', 'end datetime' ); is( "".$dt->to_span->{set}, '[2003-01-01T00:00:00..2003-12-01T00:00:59]', 'span' ); $dt->set( year => undef ); is( "".$dt->to_span->{set}, '('. NEG_INFINITY . '..' . INFINITY . ')', 'span' ); } } # TESTS TODO: # set_time_zone, time_zone # -- together with contains() and to_datetime() # Tests to_recurrence() my $set; # a complete definition yields a DT::Set with one element $set = $dti_complete->to_recurrence; is( $set->min->datetime , $str_complete, 'complete definition gives a single date' ); # no day my $dti_no_day = $dti_complete->clone; $dti_no_day->set( day => undef ); # 2003-01-xxT00:00:00 $set = $dti_no_day->to_recurrence; is( $set->min->datetime , '2003-01-01T00:00:00', 'first day in 2003-01' ); is( $set->max->datetime , '2003-01-31T00:00:00', 'last day in 2003-01' ); SKIP: { skip "This is not an error - this test would take too much resources to complete", 2 if 0; # no day, no minute # Note: this test takes a lot of time to complete, because # the _finite_ set is quite big (31 * 60 datetimes) $dti_no_day->set( minute => undef ); # 2003-01-xxT00:xx:00 $set = $dti_no_day->to_recurrence; is( $set->min->datetime , '2003-01-01T00:00:00', 'first day/minute in 2003-01' ); is( $set->max->datetime , '2003-01-31T00:59:00', 'last day/minute in 2003-01' ); }; # no year, no day, no minute { $dti_no_day = $dti_complete->clone; $dti_no_day->set( year => undef ); $dti_no_day->set( month => 12 ); $dti_no_day->set( day => 24 ); # xx-12-24T00:00:00 $dti_no_day->set( minute => undef ); # xx-12-24T00:xx:00 # has my @fields = $dti_no_day->defined_fields; is( "@fields", "month day hour second nanosecond", "fields it has" ); is( $dti_no_day->has( 'year' ) , 0, 'has no year' ); is( $dti_no_day->has( 'month' ), 1, 'has month' ); # to_recurrence $set = $dti_no_day->to_recurrence; my $dt = DateTime->new( year => 2003 ); is( $set->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas - recurrence' ); is( $set->previous( $dt )->datetime , '2002-12-24T00:59:00', 'last xmas - recurrence' ); # next is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas' ); $dt->subtract( seconds => 10 ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas again' ); $dt = $dti_no_day->next( $dt ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas with "equal" value' ); $dt->add( seconds => 20 ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:01:00', 'next xmas with "during" value' ); $dt->add( days => 1 ); is( $dti_no_day->next( $dt )->datetime , '2004-12-24T00:00:00', 'next xmas with "after" value' ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:59:00', 'previous xmas '.$dt->datetime.' with "after" value' ); $dt->subtract( days => 1 ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:00:00', 'previous xmas '.$dt->datetime.' with "during" value' ); $dt->subtract( seconds => 10 ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:00:00', 'previous xmas '.$dt->datetime.' with "equal" value' ); $dt->subtract( hours => 1 ); is( $dti_no_day->previous( $dt )->datetime , '2002-12-24T00:59:00', 'previous xmas '.$dt->datetime.' with "before" value' ); is( $dti_no_day->closest( $dt )->datetime , '2003-12-24T00:00:00', 'closest xmas '.$dt->datetime.'' ); $dt->subtract( months => 10 ); is( $dti_no_day->closest( $dt )->datetime , '2002-12-24T00:59:00', 'closest xmas '.$dt->datetime.'' ); { # to_spanset $set = $dti_no_day->to_spanset; my $dt = DateTime->new( year => 2003 ); is( $set->next( $dt )->{set}."" , '[2003-12-24T00:00:00..2003-12-24T00:00:01)', 'next xmas - span recurrence' ); $dti_no_day->set( second => undef, minute => undef ); $set = $dti_no_day->to_spanset; is( $set->next( $dt )->{set}."" , '[2003-12-24T00:00:00..2003-12-24T01:00:00)', 'next xmas - span recurrence' ); is( $dti_no_day->datetime."T". $dti_no_day->hms, "xxxx-12-24T00:xx:xxT00:xx:xx", "dti was not modified" ); } # End: Tests to_recurrence() }; } { my $dt = DateTime->new( year => 2003 ); my $dti = DateTime::Incomplete->new; is( $dti->datetime."T". $dti->hms, "xxxx-xx-xxTxx:xx:xxTxx:xx:xx", "dti is not defined" ); my $span = $dti->to_span; is( $span->{set}."" , '('.NEG_INFINITY.'..'.INFINITY.')', 'infinite span' ); my $set = $dti->to_recurrence; is( $set->next( $dt )->datetime , '2003-01-01T00:00:01', 'next "after" value' ); my $spanset = $dti->to_spanset; is( $spanset->{set}."" , '('.NEG_INFINITY.'..'.INFINITY.')', 'single infinite span' ); } 1; DateTime-Incomplete-0.08/t/03base.t000644 000767 000024 00000013267 12620364225 020417 0ustar00flavioglockstaff000000 000000 #!/usr/bin/perl -w use strict; use Test::More tests => 34; use DateTime; use DateTime::Incomplete; my $UNDEF_CHAR = 'x'; my $UNDEF4 = $UNDEF_CHAR x 4; my $UNDEF2 = $UNDEF_CHAR x 2; { # Tests for new(), set(), datetime() my $base = DateTime->new( year => 1970 ); my $dti; my $dt = DateTime->new( year => 2003 ); my $str = $dt->datetime; my $dti_clone; my $str_clone; my $dti_half; my $dti_complete; my $str_complete; $dti = DateTime::Incomplete->new( year => $dt->year, month => $dt->month, day => $dt->day, hour => $dt->hour, minute => $dt->minute, second => $dt->second, nanosecond => $dt->nanosecond, base => $base, ); $dti_complete = $dti->clone; # a fully-defined datetime $str_complete = $dti->datetime; is( $dti->datetime , $dt->datetime, 'new() matches DT->new' ); is( $dti->has_year , 1, 'has year' ); $dti->set( year => undef ); $str =~ s/^2003/$UNDEF4/; is( $dti->datetime , $str, 'undef year' ); is( $dti->has_year , 0, 'has no year' ); $dti->set( month => undef ); $str =~ s/-01-/-$UNDEF2-/; is( $dti->datetime , $str, 'undef month' ); # Tests clone() $dti_clone = $dti->clone; $str_clone = $str; $dti->set( day => undef ); $str =~ s/-01/-$UNDEF2/; is( $dti->datetime , $str, 'undef day' ); is( $dti_clone->datetime , $str_clone, 'clone has day' ); # end: Tests clone() # Tests is_undef, false is( $dti->is_undef , 0, 'not undef' ); # Tests to_datetime $dti_half = $dti->clone; # a half-defined datetime my $dt2 = $dti_half->to_datetime( base => $dt ); is( $dt->datetime , $dt2->datetime, 'to_datetime' ); my $dti2 = $dti_half->clone; $dti2->set_base( $dt ); $dt2 = $dti2->to_datetime; is( $dt->datetime , $dt2->datetime, 'to_datetime + set_base' ); # Tests contains is( $dti->contains( $dt2 ), 1, 'contains' ); $dt2->add( hours => 1 ); is( $dti->contains( $dt2 ), 0, 'does not contain' ); # undef time $dti->set( hour => undef ); $str =~ s/00:/$UNDEF2:/; is( $dti->datetime , $str, 'undef hour' ); $dti->set( minute => undef ); $str =~ s/:00:/:$UNDEF2:/; is( $dti->datetime , $str, 'undef minute' ); $dti->set( second => undef ); $str =~ s/:00/:$UNDEF2/; is( $dti->datetime , $str, 'undef second' ); is( $dti->nanosecond , $dt->nanosecond, 'def nanosecond' ); $dti->set( nanosecond => undef ); ok( ! defined( $dti->nanosecond ), 'undef nanosecond' ); # Tests is_undef, true is( $dti->is_undef , 1, 'is undef' ); # TESTS TODO: # set_time_zone, time_zone # -- together with contains() and to_datetime() # Tests to_recurrence() my $set; # a complete definition yields a DT::Set with one element $set = $dti_complete->to_recurrence; is( $set->min->datetime , $str_complete, 'complete definition gives a single date' ); # no day my $dti_no_day = $dti_complete->clone; $dti_no_day->set( day => undef ); # 2003-01-xxT00:00:00 $set = $dti_no_day->to_recurrence; is( $set->min->datetime , '2003-01-01T00:00:00', 'first day in 2003-01' ); is( $set->max->datetime , '2003-01-31T00:00:00', 'last day in 2003-01' ); # no year, no day, no minute { $dti_no_day = $dti_complete->clone; $dti_no_day->set( year => undef ); $dti_no_day->set( month => 12 ); $dti_no_day->set( day => 24 ); # xx-12-24T00:00:00 $dti_no_day->set( minute => undef ); # xx-12-24T00:xx:00 # to_recurrence $set = $dti_no_day->to_recurrence; my $dt = DateTime->new( year => 2003 ); is( $set->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas - recurrence' ); is( $set->previous( $dt )->datetime , '2002-12-24T00:59:00', 'last xmas - recurrence' ); # next is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas' ); $dt->subtract( seconds => 10 ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas again' ); $dt = $dti_no_day->next( $dt ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:00:00', 'next xmas with "equal" value' ); $dt->add( seconds => 20 ); is( $dti_no_day->next( $dt )->datetime , '2003-12-24T00:01:00', 'next xmas with "during" value' ); $dt->add( days => 1 ); is( $dti_no_day->next( $dt )->datetime , '2004-12-24T00:00:00', 'next xmas with "after" value' ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:59:00', 'previous xmas '.$dt->datetime.' with "after" value' ); $dt->subtract( days => 1 ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:00:00', 'previous xmas '.$dt->datetime.' with "during" value' ); $dt->subtract( seconds => 10 ); is( $dti_no_day->previous( $dt )->datetime , '2003-12-24T00:00:00', 'previous xmas '.$dt->datetime.' with "equal" value' ); $dt->subtract( hours => 1 ); is( $dti_no_day->previous( $dt )->datetime , '2002-12-24T00:59:00', 'previous xmas '.$dt->datetime.' with "before" value' ); is( $dti_no_day->closest( $dt )->datetime , '2003-12-24T00:00:00', 'closest xmas '.$dt->datetime.'' ); $dt->subtract( months => 10 ); is( $dti_no_day->closest( $dt )->datetime , '2002-12-24T00:59:00', 'closest xmas '.$dt->datetime.'' ); # End: Tests to_recurrence() }; } 1; DateTime-Incomplete-0.08/t/04base_overflow.t000644 000767 000024 00000005320 12620364225 022332 0ustar00flavioglockstaff000000 000000 #!/usr/bin/perl -w use strict; use Test::More tests => 12; use DateTime; use DateTime::Incomplete; # Test: require "february" { my $base = DateTime->new( year => 1970 ); my $dt_19700131 = $base->clone; $dt_19700131->set( month => 1, day => 31 ); my $dti; $dti = DateTime::Incomplete->new( month => 2, ); my $dt1; $dt1 = $dti->next( $dt_19700131 ); is( $dt1->datetime , '1970-02-01T00:00:00', 'next - first date in february is ok' ); $dt1->set( month => 3, day => 31 ); eval { $dt1 = $dti->previous( $dt1 ) }; ok( $dt1 && ( $dt1->datetime eq '1970-02-28T23:59:59' ), 'previous - last day in february' ); } # bug reported by Alexandre Masselot # 29 feb 2009 -> to_datetime fails... { my $dti = DateTime::Incomplete->new( month => 2, day => 29, year=>2000); ok($dti->ymd(), "2000-02-29"); ok($dti->to_datetime(), "29 feb 2000"); } # Test: require day=30 { my $base = DateTime->new( year => 1970 ); my $dt_19700131 = $base->clone; $dt_19700131->set( day => 31 ); my $dt_19700129 = $base->clone; $dt_19700129->set( day => 29 ); my $dt_19700128 = $base->clone; $dt_19700128->set( day => 28 ); my $dti; $dti = DateTime::Incomplete->new( day => 30, ); my $dt1; { $dt1 = $dti->next( $dt_19700131 ) }; is( $dt1->datetime , '1970-03-30T00:00:00', 'next - skips invalid date (01-31)' ); { $dt1 = $dti->next( $dt_19700129 ) }; is( $dt1->datetime , '1970-01-30T00:00:00', 'next - skips invalid date (01-29)' ); { $dt1 = $dti->next( $dt_19700128 ) }; is( $dt1->datetime , '1970-01-30T00:00:00', 'next - skips invalid date (01-28)' ); $dt1->set( month => 3, day => 10 ); $dt1 = $dti->previous( $dt1 ); is( $dt1->datetime , '1970-01-30T23:59:59', 'previous - skips invalid date' ); my $dt_19700220 = $base->clone; $dt_19700220->set( month => 2, day => 20 ); eval { $dt1 = $dti->next( $dt_19700220 ) }; is( $dt1->datetime , '1970-03-30T00:00:00', 'next - skips invalid date (02-20)' ); $dti = DateTime::Incomplete->new( month => 2, day => 30, ); eval { $dt1 = $dti->next( $base ) }; ok( ! defined $dt1 , 'next - invalid incomplete datetime (02-30)' ); warn "# ".$dt1->datetime if defined $dt1; eval { $dt1 = $dti->previous( $base ) }; ok( ! defined $dt1 , 'previous - invalid incomplete datetime (02-30)' ); warn "# ".$dt1->datetime if defined $dt1; eval { $dt1 = $dti->closest( $base ) }; ok( ! defined $dt1 , 'closest - invalid incomplete datetime (02-30)' ); warn "# ".$dt1->datetime if defined $dt1; } 1; DateTime-Incomplete-0.08/t/05datetime.t000644 000767 000024 00000003242 12620364225 021273 0ustar00flavioglockstaff000000 000000 #!/usr/bin/perl -w use strict; use Test::More tests => 9; use DateTime; use DateTime::Incomplete; my $UNDEF_CHAR = 'x'; my $UNDEF4 = $UNDEF_CHAR x 4; my $UNDEF2 = $UNDEF_CHAR x 2; { my $dti; my $dt = DateTime->new( year => 2003 ); my $error; $dti = DateTime::Incomplete->new( year => $dt->year, month => $dt->month, day => $dt->day, hour => $dt->hour, minute => $dt->minute, second => $dt->second, nanosecond => $dt->nanosecond, ); is( $dti->day_name , $dt->day_name, 'DTI->day_name matches DT->day_name' ); $dti->set( year => undef ); ok( ! defined $dti->day_name , 'day_name checks for valid parameter' ); is( $dti->offset , $dt->offset, 'DTI->offset matches DT->offset' ); $dt->set_time_zone( 'America/Chicago' ); $dti->set_time_zone( 'America/Chicago' ); is( $dti->offset , $dt->offset, 'DTI->offset matches DT->offset' ); $dti->set( year => undef ); ok( ! defined $dti->is_leap_year , 'is_leap_year checks for valid parameter' ); } { my $dti; $dti = DateTime::Incomplete->now; ok( defined $dti , "now() doesn't die: ".$dti->datetime ); $dti = DateTime::Incomplete->today; my $str_today = $dti->datetime; ok( defined $dti , "today() doesn't die: ".$str_today ); $str_today =~ s/$UNDEF2:$UNDEF2$/00:00/; $dti->truncate( to => 'hour' ); is( $dti->datetime , $str_today , "truncate() defines min:sec ".$str_today ); $dti = DateTime::Incomplete->from_epoch( epoch => 0 ); ok( defined $dti , "from_epoch() doesn't die: ".$dti->datetime ); } 1; DateTime-Incomplete-0.08/t/06next.t000644 000767 000024 00000002542 12620364225 020460 0ustar00flavioglockstaff000000 000000 # bug #67064 use strict; use warnings; use DateTime; use DateTime::Incomplete; use Test::More; # 7am in America/Sao_Paulo (UTC-03) # Note we need to specify up to nanosecond - otherwise previous() will return an hour like 07:59:59.999999 my $dti = DateTime::Incomplete->new( hour => 7, minute => 0, second => 0, nanosecond => 0, time_zone => 'America/Sao_Paulo' ); # 2011-03-29T00:00:00 UTC my $dt = DateTime->new( year => 2011, month => 03, day => 29, time_zone => 'UTC' ); { # when is it next 7am in Brazil? ... should be 10am UTC. my $next = $dti->next($dt); my $dt_str = $next->datetime . " " . $next->time_zone->name; print "# $dt_str\n"; is( $dt_str, "2011-03-29T10:00:00 UTC", 'result timezone is UTC' ); $dt_str = $dt->datetime . " " . $dt->time_zone->name; print "# $dt_str\n"; is( $dt_str, "2011-03-29T00:00:00 UTC", '$dt is the same' ); } { # when is it previous 7am in Brazil? ... should be 10am UTC. my $previous = $dti->previous($dt); my $dt_str = $previous->datetime . " " . $previous->time_zone->name; print "# $dt_str\n"; is( $dt_str, "2011-03-28T10:00:00 UTC", 'result timezone is UTC' ); $dt_str = $dt->datetime . " " . $dt->time_zone->name; print "# $dt_str\n"; is( $dt_str, "2011-03-29T00:00:00 UTC", '$dt is the same' ); } done_testing; DateTime-Incomplete-0.08/t/13strftime.t000644 000767 000024 00000011062 12620365165 021336 0ustar00flavioglockstaff000000 000000 #!/usr/bin/perl -w # test suite stolen shamelessly from TimeDate distro # re-stolen from DateTime BEGIN { return unless $] >= 5.006; require utf8; import utf8; } use strict; use Test::More tests => 100; use DateTime::Incomplete; use DateTime; my $locale = 'en_US'; # ?? "Can't locate DateTime/Locale/en_US.pm in @INC" $locale = 'undef'; my $dt; my $params; while () { chomp; next if /^#/; if (/^year =>/) { $params = $_; $dt = eval "DateTime::Incomplete->new( $params, time_zone => undef, locale => $locale )"; next; } elsif (/^(\w+)/) { $locale = $1; eval "use DateTime::Locale; DateTime::Locale->load('$1');"; die $@ if $@; # Test::More::diag("New locale: $locale\n"); $dt = eval "DateTime::Incomplete->new( $params, time_zone => 'UTC', locale => '$locale' )"; next; } my ($fmt, $res) = split /\t/, $_; my $broken = 'marted' . chr(195); if ( $fmt eq '%A' && $locale eq 'it' && $] >= 5.006 && $] <= 5.008 ) { ok( 1, "Perl 5.6.0 & 5.6.1 cannot handle Unicode characters in the DATA filehandle properly" ); next; } is( $dt->strftime($fmt), $res, "$fmt" ); } # test use of strftime with multiple params - in list and scalar # context { my $dt = DateTime::Incomplete->new( year => 1800, month => 1, day => 10, time_zone => 'UTC', locale => 'en', ); my ($y, $d) = $dt->strftime( '%Y', '%d' ); is( $y, 1800, 'first value is year' ); is( $d, 10, 'second value is day' ); $y = $dt->strftime( '%Y', '%d' ); is( $y, 1800, 'scalar context returns year' ); } { my $dt = DateTime::Incomplete->new( year => 2003, hour => 0, minute => 0, locale => 'en', ) ; # is( $dt->strftime('%I %M %p'), '12 00 AM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), '12 00 AM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 1) ; # is( $dt->strftime('%I %M %p'), '01 00 AM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), ' 1 00 AM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 11) ; # is( $dt->strftime('%I %M %p'), '11 00 AM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), '11 00 AM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 12) ; # is( $dt->strftime('%I %M %p'), '12 00 PM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), '12 00 PM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 13) ; # is( $dt->strftime('%I %M %p'), '01 00 PM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), ' 1 00 PM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 23) ; # is( $dt->strftime('%I %M %p'), '11 00 PM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), '11 00 PM', 'formatting of hours as 1-12' ); # # $dt->set(hour => 0) ; # is( $dt->strftime('%I %M %p'), '12 00 AM', 'formatting of hours as 1-12' ); # is( $dt->strftime('%l %M %p'), '12 00 AM', 'formatting of hours as 1-12' ); } # add these if we do roman-numeral stuff # %Od VII # %Oe VII # %OH XIII # %OI I # %Oj CCL # %Ok XIII # %Ol I # %Om IX # %OM II # %Oq III # %OY MCMXCIX # %Oy XCIX __DATA__ year => undef %y xx %Y xxxx %% % %a xxx %A xxxxx %b xxx %B xxxxx %C xx %d xx %e x %D xx/xx/xx %h xxx %H xx %I xx %j xxx %k xx %l x %m xx %M xx %N xxxxxxxxx %3N xxx %6N xxxxxx %10N xxxxxxxxxx # %p xx # %r xx:xx:xx xx %R xx:xx # %s xxxxxx - epoch returns today() %S xx %T xx:xx:xx %U xx %w x %W xx %y xx %Y xxxx %Z xxxxx %z xxxxx %{month} xx %{year} xxxx %x xxxx-xx-xx %X xx:xx:xx %c xxxx-xx-xxTxx:xx:xx year => 1999, month => 9, day => 7, hour => 13, minute => 2, second => 42, nanosecond => 123456789.123456 de %y 99 %Y 1999 %% % # %a Di. %A Dienstag # %b Sep. %B September %C 19 %d 07 %e 7 %D 09/07/99 # %h Sep. %H 13 %I 01 %j 250 %k 13 %l 1 %m 09 %M 02 # %p nachm. # %r 01:02:42 nachm. %R 13:02 # %s 936709362 -- epoch is not implemented %S 42 %T 13:02:42 %U 36 %w 2 %W 36 %y 99 %Y 1999 %Z UTC %z +0000 %{month} 9 %{year} 1999 it %y 99 %Y 1999 %% % %a mar %A martedì %b set %B settembre %C 19 %d 07 %e 7 %D 09/07/99 %h set %H 13 %I 01 %j 250 %k 13 %l 1 %m 09 %M 02 # %p p. # %r 01:02:42 p. %R 13:02 # %s 936709362 -- epoch is not implemented %S 42 %T 13:02:42 %U 36 %w 2 %W 36 %y 99 %Y 1999 %Z UTC %z +0000 %{month} 9 %{year} 1999 DateTime-Incomplete-0.08/lib/DateTime/000755 000767 000024 00000000000 12620365420 021141 5ustar00flavioglockstaff000000 000000 DateTime-Incomplete-0.08/lib/DateTime/Incomplete.pm000644 000767 000024 00000114273 12620365315 023611 0ustar00flavioglockstaff000000 000000 package DateTime::Incomplete; use strict; use DateTime::Set 0.0901; use DateTime::Event::Recurrence; use Params::Validate qw( validate ); use vars qw( $VERSION ); my $UNDEF_CHAR; my ( @FIELDS, %FIELD_LENGTH, @TIME_FIELDS, @FIELDS_SORTED ); BEGIN { $VERSION = '0.08'; $UNDEF_CHAR = 'x'; @FIELDS = ( year => 0, month => 1, day => 1, hour => 0, minute => 0, second => 0, nanosecond => 0 ); %FIELD_LENGTH = ( year => 4, month => 2, day => 2, hour => 2, minute => 2, second => 2, nanosecond => 9, time_zone => 0, locale => 0 ); @TIME_FIELDS = qw( hour minute second nanosecond ); @FIELDS_SORTED = qw( year month day hour minute second nanosecond time_zone locale ); # Generate named accessors for my $field ( @FIELDS_SORTED ) { no strict 'refs'; *{$field} = sub { $_[0]->_get($field) }; *{"has_$field"} = sub { $_[0]->_has($field) }; next if $field eq 'nanosecond'; my $length = $FIELD_LENGTH{$field}; next unless $length; *{"_$field"} = sub { defined $_[0]->$field() ? sprintf( "%0.${length}d", $_[0]->$field() ) : $UNDEF_CHAR x $length }; } # Generate DateTime read-only functions for my $meth ( qw/ epoch hires_epoch is_dst utc_rd_values utc_rd_as_seconds / ) { no strict 'refs'; *{$meth} = sub { # to_datetime() dies if there is no "base" # we get 'undef' if this happens eval { (shift)->to_datetime( @_ )->$meth() }; }; } for my $meth ( qw/ week week_year week_number week_of_month day_name day_abbr day_of_week wday dow day_of_year doy quarter day_of_quarter doq weekday_of_month jd mjd / ) { no strict 'refs'; *{$meth} = sub { $_[0]->_datetime_method( $meth, 'year', 'month', 'day' ) }; } for my $meth ( qw/ is_leap_year ce_year era year_with_era / ) { no strict 'refs'; *{$meth} = sub { $_[0]->_datetime_method( $meth, 'year' ) }; } for my $meth ( qw/ month_name month_abbr / ) { no strict 'refs'; *{$meth} = sub { $_[0]->_datetime_method( $meth, 'month' ) }; } for my $meth ( qw/ hour_1 hour_12 hour_12_0 / ) { no strict 'refs'; *{$meth} = sub { $_[0]->_datetime_method( $meth, 'hour' ) }; } for my $meth ( qw/ millisecond microsecond / ) { no strict 'refs'; *{$meth} = sub { $_[0]->_datetime_method( $meth, 'nanosecond' ) }; } } *_nanosecond = \&_format_nanosecs; *mon = \&month; *day_of_month = \&day; *mday = \&day; *min = \&minute; *sec = \&second; # Internal sub to call "DateTime" methods sub _datetime_method { my ( $self, $method ) = ( shift, shift ); my @fields = @_; # list of required fields my $date; for ( @fields ) { return undef unless ( $self->_has($_) ) } my %param; # if we don't need 'year', then we can safely set it to whatever. $param{year} = 1970 if ! @fields || $fields[0] ne 'year'; $param{locale} = $self->locale if $self->has_locale; $param{time_zone} = $self->time_zone if $self->has_time_zone; $param{$_} = $self->$_() for @fields; $date = DateTime->new( %param ); return $date->$method(); } # DATETIME-LIKE METHODS sub fractional_second { $_[0]->_datetime_method( 'fractional_second', 'second', 'nanosecond' ); } sub offset { $_[0]->_datetime_method( 'offset' ); } sub time_zone_short_name { $_[0]->_datetime_method( 'time_zone_short_name' ); } sub time_zone_long_name { $_[0]->_datetime_method( 'time_zone_long_name' ); } sub _from_datetime { my $class = shift; my $dt = shift; my %param; $param{$_} = $dt->$_() for @FIELDS_SORTED; return $class->new( %param ); } sub last_day_of_month { my $self = shift; my %param = @_; my $result = $self->_from_datetime( DateTime->last_day_of_month( @_ ) ); for ( @TIME_FIELDS ) { $result->set( $_, undef ) unless defined $param{$_}; } return $result; } sub from_epoch { return (shift)->_from_datetime( DateTime->from_epoch( @_ ) ); } sub now { return (shift)->_from_datetime( DateTime->now( @_ ) ); } sub from_object { return (shift)->_from_datetime( DateTime->from_object( @_ ) ); } sub from_day_of_year { my $self = shift; my %param = @_; my $result = $self->_from_datetime( DateTime->from_day_of_year( @_ ) ); for ( @TIME_FIELDS ) { $result->set( $_, undef ) unless defined $param{$_}; } return $result; } sub today { my $class = shift; my $now = DateTime->now( @_ ); my %param; my %fields = ( %FIELD_LENGTH ); delete $fields{$_} for ( qw/ hour minute second nanosecond / ); $param{$_} = $now->$_() for ( keys %fields ); return $class->new( %param ); } sub new { # parameter checking is done in "set" method. my $class = shift; my %param = @_; my $base = delete $param{base}; die "base must be a datetime" if defined $base && ! UNIVERSAL::can( $base, 'utc_rd_values' ); my $self = bless { has => \%param, }, $class; $self->set_base( $base ); $self->set( locale => $self->{has}{locale} ) if $self->{has}{locale}; $self->set_time_zone( $self->{has}{time_zone} ) if $self->{has}{time_zone}; return $self; } sub set_base { my $self = shift; $self->{base} = shift; if ( defined $self->{base} ) { my ($key, $value); while (($key, $value) = each %{$self->{has}} ) { next unless defined $value; if ( $key eq 'time_zone' ) { $self->{base}->set_time_zone( $value ); next; } $self->{base}->set( $key => $value ); } } } sub base { return undef unless defined $_[0]->{base}; $_[0]->{base}->clone; } sub has_base { return defined $_[0]->{base} ? 1 : 0; } sub set { my $self = shift; my %p = @_; while ( my ( $k, $v ) = each %p ) { if ( $k eq 'locale' ) { $self->_set_locale($v); next; } $self->{base}->set( $k => $v ) if $self->{base} && defined $v; $self->{has}{ $k } = $v; } } sub _get { $_[0]->{has}{$_[1]}; } sub _has { defined $_[0]->{has}{$_[1]} ? 1 : 0; } sub has { # returns true or false my $self = shift; foreach (@_) { return 0 unless $self->_has( $_ ) } return 1 } sub has_date { $_[0]->has_year && $_[0]->has_month && $_[0]->has_day } sub has_time { $_[0]->has_hour && $_[0]->has_minute && $_[0]->has_second } sub defined_fields { # no params, returns a list of fields my $self = shift; my @has = (); for ( @FIELDS_SORTED ) { push @has, $_ if $self->_has( $_ ); } return @has; } sub can_be_datetime { my $self = shift; return 0 if ! $self->has_year; my $can = 1; for ( qw( month day hour minute second nanosecond ) ) { return 0 if ! $can && $self->_has( $_ ); $can = 0 if $can && ! $self->_has( $_ ); } return 1; } #sub become_datetime { # my $self = shift; # return undef unless $self->has_year; # # warn "param = @{[ %{$self->{has}} ]} "; # # return DateTime->new( %{$self->{has}} ); # my @parm = map { ( $_, $self->$_() ) } $self->defined_fields; # # warn "param = @parm"; # return DateTime->new( @parm ); #} sub set_time_zone { die "set_time_zone() requires a time_zone value" unless $#_ == 1; my $time_zone = $_[1]; if ( defined $time_zone ) { $time_zone = DateTime::TimeZone->new( name => $time_zone ) unless ref $time_zone; $_[0]->{base}->set_time_zone( $time_zone ) if defined $_[0]->{base}; } $_[0]->{has}{time_zone} = $time_zone; } sub _set_locale { die "set_locale() requires a locale value" unless $#_ == 1; my $locale = $_[1]; if ( defined $locale ) { $locale = DateTime::Locale->load( $locale ) unless ref $locale; $_[0]->{base}->set( locale => $locale ) if defined $_[0]->{base}; } $_[0]->{has}{locale} = $locale; } sub clone { my $base; $base = $_[0]->{base}->clone if defined $_[0]->{base}; bless { has => { %{ $_[0]->{has} } }, base => $base, }, ref $_[0]; } sub is_finite { 1 } sub is_infinite { 0 } sub truncate { my $self = shift; my %p = validate( @_, { to => { regex => qr/^(?:year|month|day|hour|minute|second)$/ }, }, ); my @fields = @FIELDS; my $field; my $value; my $set = 0; while ( @fields ) { ( $field, $value ) = ( shift @fields, shift @fields ); $self->set( $field => $value ) if $set; $set = 1 if $p{to} eq $field; } return $self; } # Stringification methods sub ymd { my ( $self, $sep ) = ( @_, '-' ); return $self->_year . $sep. $self->_month . $sep . $self->_day; } *date = \&ymd; sub mdy { my ( $self, $sep ) = ( @_, '-' ); return $self->_month . $sep. $self->_day . $sep . $self->_year; } sub dmy { my ( $self, $sep ) = ( @_, '-' ); return $self->_day . $sep. $self->_month . $sep . $self->_year; } sub hms { my ( $self, $sep ) = ( @_, ':' ); return $self->_hour . $sep. $self->_minute . $sep . $self->_second; } # don't want to override CORE::time() *DateTime::Incomplete::time = \&hms; sub iso8601 { join 'T', $_[0]->ymd('-'), $_[0]->hms(':') } *datetime = \&iso8601; # "strftime" # Modified from DateTime::strftime %formats; many changes. my %formats = ( 'a' => sub { $_[0]->has_day ? $_[0]->day_abbr : $UNDEF_CHAR x 3 }, 'A' => sub { $_[0]->has_day ? $_[0]->day_name : $UNDEF_CHAR x 5 }, 'b' => sub { $_[0]->has_month ? $_[0]->month_abbr : $UNDEF_CHAR x 3 }, 'B' => sub { $_[0]->has_month ? $_[0]->month_name : $UNDEF_CHAR x 5 }, 'c' => sub { $_[0]->has_locale ? $_[0]->strftime( $_[0]->locale->default_datetime_format ) : $_[0]->datetime }, 'C' => sub { $_[0]->has_year ? int( $_[0]->year / 100 ) : $UNDEF_CHAR x 2}, 'd' => sub { $_[0]->_day }, 'D' => sub { $_[0]->strftime( '%m/%d/%y' ) }, 'e' => sub { $_[0]->has_month ? sprintf( '%2d', $_[0]->day_of_month ) : " $UNDEF_CHAR" }, 'F' => sub { $_[0]->ymd('-') }, 'g' => sub { substr( $_[0]->week_year, -2 ) }, 'G' => sub { $_[0]->week_year }, 'H' => sub { $_[0]->_hour }, 'I' => sub { $_[0]->has_hour ? sprintf( '%02d', $_[0]->hour_12 ) : $UNDEF_CHAR x 2 }, 'j' => sub { defined $_[0]->day_of_year ? $_[0]->day_of_year : $UNDEF_CHAR x 3 }, 'k' => sub { $_[0]->_hour }, 'l' => sub { $_[0]->has_hour ? sprintf( '%2d', $_[0]->hour_12 ) : " $UNDEF_CHAR" }, 'm' => sub { $_[0]->_month }, 'M' => sub { $_[0]->_minute }, 'n' => sub { "\n" }, # should this be OS-sensitive? 'N' => sub { (shift)->_format_nanosecs( @_ ) }, 'p' => sub { $_[0]->_format_am_pm }, 'P' => sub { lc $_[0]->_format_am_pm }, 'r' => sub { $_[0]->strftime( '%I:%M:%S %p' ) }, 'R' => sub { $_[0]->strftime( '%H:%M' ) }, 's' => sub { $_[0]->_format_epoch }, 'S' => sub { $_[0]->_second }, 't' => sub { "\t" }, 'T' => sub { $_[0]->strftime( '%H:%M:%S' ) }, 'u' => sub { $_[0]->day_of_week }, # algorithm from Date::Format::wkyr 'U' => sub { my $dow = $_[0]->day_of_week; return $UNDEF_CHAR x 2 unless defined $dow; $dow = 0 if $dow == 7; # convert to 0-6, Sun-Sat my $doy = $_[0]->day_of_year - 1; return int( ( $doy - $dow + 13 ) / 7 - 1 ) }, 'w' => sub { my $dow = $_[0]->day_of_week; return $UNDEF_CHAR unless defined $dow; return $dow % 7; }, 'W' => sub { my $dow = $_[0]->day_of_week; return $UNDEF_CHAR x 2 unless defined $dow; my $doy = $_[0]->day_of_year - 1; return int( ( $doy - $dow + 13 ) / 7 - 1 ) }, 'x' => sub { $_[0]->has_locale ? $_[0]->strftime( $_[0]->locale->default_date_format ) : $_[0]->date }, 'X' => sub { $_[0]->has_locale ? $_[0]->strftime( $_[0]->locale->default_time_format ) : $_[0]->time }, 'y' => sub { $_[0]->has_year ? sprintf( '%02d', substr( $_[0]->year, -2 ) ) : $UNDEF_CHAR x 2 }, 'Y' => sub { $_[0]->_year }, 'z' => sub { defined $_[0]->time_zone ? DateTime::TimeZone::offset_as_string( $_[0]->offset ) : $UNDEF_CHAR x 5 }, 'Z' => sub { defined $_[0]->time_zone ? $_[0]->time_zone_short_name : $UNDEF_CHAR x 5 }, '%' => sub { '%' }, ); $formats{h} = $formats{b}; sub _format_epoch { my $epoch; $epoch = $_[0]->epoch; return $UNDEF_CHAR x 6 unless defined $epoch; return $epoch; } sub _format_am_pm { defined $_[0]->locale ? $_[0]->locale->am_pm( $_[0] ) : $UNDEF_CHAR x 2 } sub _format_nanosecs { my $self = shift; my $precision = shift || 9; return $UNDEF_CHAR x $precision unless defined $self->nanosecond; # rd_nanosecs can have a fractional separator my ( $ret, $frac ) = split /[.,]/, $self->nanosecond; $ret = sprintf "09d" => $ret; # unless length( $ret ) == 9; $ret .= $frac if $frac; return substr( $ret, 0, $precision ); } sub strftime { my $self = shift; # make a copy or caller's scalars get munged my @formats = @_; my @r; foreach my $f (@formats) { $f =~ s/ %\{(\w+)\} / if ( $self->can($1) ) { my $tmp = $self->$1(); defined $tmp ? $tmp : ( exists $FIELD_LENGTH{$1} ? $UNDEF_CHAR x $FIELD_LENGTH{$1} : $UNDEF_CHAR x 2 ); } /sgex; # regex from Date::Format - thanks Graham! $f =~ s/ %([%a-zA-Z]) / $formats{$1} ? $formats{$1}->($self) : $1 /sgex; # %3N $f =~ s/ %(\d+)N / $formats{N}->($self, $1) /sgex; return $f unless wantarray; push @r, $f; } return @r; } # DATETIME::INCOMPLETE METHODS sub is_undef { for ( values %{$_[0]->{has}} ) { return 0 if defined $_; } return 1; } sub to_datetime { my $self = shift; my %param = @_; $param{base} = $self->{base} if defined $self->{base} && ! exists $param{base}; my $result; if ( defined $param{base} && UNIVERSAL::can( $param{base}, 'utc_rd_values' ) ) { $result = $param{base}->clone; } else { $result = DateTime->today; } my @params; for my $key ( @FIELDS_SORTED ) { my $value = $self->{has}{$key}; next unless defined $value; if ( $key eq 'time_zone' ) { $result->set_time_zone( $value ); next; } push @params, ( $key => $value ); } $result->set( @params ); return $result; } sub contains { my $self = shift; my $dt = shift; die "no datetime" unless defined $dt && UNIVERSAL::can( $dt, 'utc_rd_values' ); if ( $self->has_time_zone ) { $dt = $dt->clone; $dt->set_time_zone( $self->time_zone ); } my ($key, $value); while (($key, $value) = each %{$self->{has}} ) { next unless defined $value; if ( $key eq 'time_zone' || $key eq 'locale' ) { # time_zone and locale are ignored. next; } return 0 unless $dt->$key() == $value; } return 1; } # _fix_time_zone # internal method used by next, previous # sub _fix_time_zone { my ($self, $base, $code) = @_; $base = $self->{base} if defined $self->{base} && ! defined $base; die "no base datetime" unless defined $base && UNIVERSAL::can( $base, 'utc_rd_values' ); my $base_tz = $base->time_zone; my $result = $base->clone; $result->set_time_zone( $self->time_zone ) if $self->has_time_zone; $result = $code->($self, $result); return undef unless defined $result; $result->set_time_zone( $self->time_zone ) if $self->has_time_zone; $result->set_time_zone( $base_tz ); return $result; } sub next { # returns 'next or equal' my $self = shift; my $base = shift; return $self->_fix_time_zone( $base, sub { my ($self, $result) = @_; REDO: for (1..10) { # warn "next: self ".$self->datetime." base ".$result->datetime; my @fields = @FIELDS; my ( $field, $overflow, $bigger_field ); while ( @fields ) { ( $field, undef ) = ( shift @fields, shift @fields ); if ( defined $self->$field() ) { $overflow = ( $self->$field() < $result->$field() ); return undef if $overflow && $field eq $FIELDS[0]; if ( $self->$field() != $result->$field() ) { eval { $result->set( $field => $self->$field() ) }; if ( $@ ) { $result->set( @fields ); eval { $result->set( $field => $self->$field() ) }; if ( $@ ) { $overflow = 1; } } if ( $overflow ) { $result->add( $bigger_field . 's' => 1 ); next REDO; } else { $result->set( @fields ); } } } $bigger_field = $field; } return $result; } return undef; } ); } sub previous { # returns 'previous or equal' my $self = shift; my $base = shift; return $self->_fix_time_zone( $base, sub { my ($self, $result) = @_; # warn "# previous: self ".$self->datetime." base ".$result->datetime." ".$result->time_zone->name; my ( $field, $value, $overflow, $bigger_field ); REDO: for (1..10) { my @fields = @FIELDS; while ( @fields ) { ( $field, $value ) = ( shift @fields, shift @fields ); if ( defined $self->$field() ) { $overflow = ( $self->$field() > $result->$field() ); return undef if $overflow && $field eq $FIELDS[0]; if ( $self->$field() != $result->$field() ) { if ( $overflow ) { $result->set( $field => $value, @fields ); $result->subtract( nanoseconds => 1 ); next REDO; } my $diff = $result->$field() - $self->$field() ; $diff--; $result->subtract( $field . 's' => $diff ); $result->set( @fields ); $result->subtract( nanoseconds => 1 ); if ( $result->$field() != $self->$field() ) { $result->set( @fields ); $result->subtract( nanoseconds => 1 ); } } } $bigger_field = $field; } return $result; } return undef; } ); } sub closest { # returns 'closest datetime' my $self = shift; my $base = shift; $base = $self->{base} if defined $self->{base} && ! defined $base; die "no base datetime" unless defined $base && UNIVERSAL::can( $base, 'utc_rd_values' ); my $dt1 = $self->previous( $base ); my $dt2 = $self->next( $base ); return $dt1 unless defined $dt2; return $dt2 unless defined $dt1; my $delta = $base - $dt1; return $dt1 if ( $dt2 - $delta ) >= $base; return $dt2; } sub start { my $self = shift; return undef unless $self->has_year; my $dt = $self->to_datetime; $dt->subtract( years => 1 ); return $self->next( $dt ); } sub end { my $self = shift; return undef unless $self->has_year; my $dt = $self->to_datetime; $dt->add( years => 1 ); my $end = $self->previous( $dt ); $end->add( nanoseconds => 1 ) unless $self->has_nanosecond; return $end; } sub to_span { my $self = shift; my $start = $self->start; my $end = $self->end; return DateTime::Set->empty_set->complement->span if ! $start && ! $end; my @start; @start = ( 'start', $start ) if $start; my @end; if ( $end ) { if ( $self->has_nanosecond ) { @end = ( 'end', $end ); } else { @end = ( 'before', $end ); } } return DateTime::Span->from_datetimes( @start, @end ); } sub to_recurrence { my $self = shift; my %param; my $freq = ''; my $year; for ( qw( second minute hour day month year ) ) { my $by = $_ . 's'; # months, hours if ( exists $self->{has}{$_} && defined $self->{has}{$_} ) { if ( $_ eq 'year' ) { $year = $self->$_(); next; } $param{$by} = [ $self->$_() ]; next; } $freq = $_ unless $freq; # TODO: use a hash $param{$by} = [ 1 .. 12 ] if $_ eq 'month'; $param{$by} = [ 1 .. 31 ] if $_ eq 'day'; $param{$by} = [ 0 .. 23 ] if $_ eq 'hour'; $param{$by} = [ 0 .. 59 ] if $_ eq 'minute'; $param{$by} = [ 0 .. 59 ] if $_ eq 'second'; } if ( $freq eq '' ) { # it is a single date my $dt = DateTime->new( %{$self->{has}} ); return DateTime::Set->from_datetimes( dates => [ $dt ] ); } # for ( keys %param ) { print STDERR " param $_ = @{$param{$_}} \n"; } my $r = DateTime::Event::Recurrence->yearly( %param ); if ( defined $year ) { my $span = DateTime::Span->from_datetimes( start => DateTime->new( year => $year ), before => DateTime->new( year => $year + 1 ) ); $r = $r->intersection( $span ); } return $r; } sub to_spanset { my $self = shift; my @reset; for ( qw( second minute hour day month year ) ) { if ( $self->has( $_ ) ) { my %fields = @FIELDS; @reset = map { $_ => $fields{$_} } @reset; my $dti = $self->clone; $dti->set( @reset ) if @reset; return DateTime::SpanSet->from_set_and_duration ( set => $dti->to_recurrence, $_ . 's' => 1, ); } push @reset, $_; } return $self->to_span; } sub STORABLE_freeze { my ( $self, $cloning ) = @_; return if $cloning; my @data; for my $key ( @FIELDS_SORTED ) { next unless defined $self->{has}{$key}; if ( $key eq 'locale' ) { push @data, "locale:" . $self->{has}{locale}->id; } elsif ( $key eq 'time_zone' ) { push @data, "tz:" . $self->{has}{time_zone}->name; } else { push @data, "$key:" . $self->{has}{$key}; } } return join( '|', @data ), [$self->base]; } sub STORABLE_thaw { my ( $self, $cloning, $data, $base ) = @_; my %data = map { split /:/ } split /\|/, $data; my $locale = delete $data{locale}; my $tz = delete $data{tz}; $self->{has} = \%data; $self->set_time_zone( $tz ); $self->set( locale => $locale ); $self->{base} = $base->[0]; return $self; } 1; __END__ =head1 NAME DateTime::Incomplete - An incomplete datetime, like January 5 =head1 SYNOPSIS my $dti = DateTime::Incomplete->new( year => 2003 ); # 2003-xx-xx $dti->set( month => 12 ); # 2003-12-xx $dt = $dti->to_datetime( base => DateTime->now ); # 2003-12-19T16:54:33 =head1 DESCRIPTION DateTime::Incomplete is a class for representing partial dates and times. These are actually encountered relatively frequently. For example, a birthday is commonly given as a month and day, without a year. =head1 ERROR HANDLING Constructor and mutator methods (such as C and C) will die if there is an attempt to set the datetime to an invalid value. Invalid values are detected by setting the appropriate fields of a "base" datetime object. See the C method. Accessor methods (such as C) will return either a value or C, but will never die. =head1 THE "BASE" DATETIME A C object can have a "base" C object. This object is used as a default datetime in the C method, and it also used to validate inputs to the C method. The base object must use the year/month/day system. Most calendars use this system including Gregorian (C) and Julian. Note that this module has not been well tested with base objects from classes other than C class. By default, newly created C objects have no base. =head1 DATETIME-LIKE METHODS Most methods provided by this class are designed to emulate the behavior of C whenever possible. =over =item * new() Creates a new incomplete date: my $dti = DateTime::Incomplete->new( year => 2003 ); # 2003-xx-xx This class method accepts parameters for each date and time component: "year", "month", "day", "hour", "minute", "second", "nanosecond". Additionally, it accepts "time_zone", "locale", and "base" parameters. Any parameters not given default to C. Calling the C method without parameters creates a completely undefined datetime: my $dti = DateTime::Incomplete->new(); =item * from_day_of_year( ... ) This constructor takes the same arguments as can be given to the C method, except that it does not accept a "month" or "day" argument. Instead, it requires both "year" and "day_of_year". The day of year must be between 1 and 366, and 366 is only allowed for leap years. It creates a C object with all date fields defined, but with the time fields (hour, minute, etc.) set to undef. =item * from_object( object => $object, ... ) This class method can be used to construct a new C object from any object that implements the C method. All C modules must implement this method in order to provide cross-calendar compatibility. This method accepts a "locale" parameter. If the object passed to this method has a C method, that is used to set the time zone. Otherwise UTC is used. It creates a C object with all fields defined. =item * from_epoch( ... ) This class method can be used to construct a new C object from an epoch time instead of components. Just as with the C method, it accepts "time_zone" and "locale" parameters. If the epoch value is not an integer, the part after the decimal will be converted to nanoseconds. This is done in order to be compatible with C. It creates a C object with all fields defined. =item * now( ... ) This class method is equivalent to C<< DateTime->now >>. It creates a new C object with all fields defined. =item * today( ... ) This class method is equivalent to C, but it leaves hour, minute, second and nanosecond undefined. =item * clone Creates a new object with the same information as the object this method is called on. =back =head2 "Get" Methods =over 4 =item * year =item * month =item * day =item * hour =item * minute =item * second =item * nanosecond =item * time_zone =item * locale These methods returns the field value for the object, or C. These values can also be accessed using the same alias methods available in C, such as C, C, etc. =item * has_year =item * has_month =item * has_day =item * has_hour =item * has_minute =item * has_second =item * has_nanosecond =item * has_time_zone =item * has_locale =item * has_date =item * has_time Returns a boolean value indicating whether the corresponding component is defined. C tests for year, month, and day. C tests for hour, minute, and second. =item * has $has_date = $dti->has( 'year', 'month', 'day' ); Returns a boolean value indicating whether all fields in the argument list are defined. =item * defined_fields @fields = $dti->defined_fields; # list of field names Returns a list containing the names of the fields that are defined. The list order is: year, month, day, hour, minute, second, nanosecond, time_zone, locale. =item * datetime, ymd, date, hms, time, iso8601, mdy, dmy These are equivalent to DateTime stringification methods with the same name, except that the undefined fields are replaced by 'xx' or 'xxxx' as appropriate. =item * epoch =item * hires_epoch =item * is_dst =item * utc_rd_values =item * utc_rd_as_seconds my $epoch = $dti->epoch( base => $dt ); These methods are equivalent to the C methods with the same name. They all accept a "base" argument to use in order to calculate the method's return values. If no "base" argument is given, then C is used. =item * is_finite, is_infinite Incomplete dates are always "finite". =item * strftime( $format, ... ) This method implements functionality similar to the C method in C. However, if given multiple format strings, then it will return multiple scalars, one for each format string. See the "strftime Specifiers" section in the C documentation for a list of all possible format specifiers. Undefined fields are replaced by 'xx' or 'xxxx' as appropriate. The specification C<%s> (epoch) is calculated using C as the base date, unless the object has a base datetime set. =back =head3 Computed Values All other accessors, such as C, or C are computed from the base values for a datetime. When these methods are called, they return the requested information if there is enough data to compute them, otherwise they return C =head3 Unimplemented Methods The following C methods are not implemented in C, though some of them may be implemented in future versions: =over 4 =item * add_duration =item * add =item * subtract_duration =item * subtract =item * subtract_datetime =item * subtract_datetime_absolute =item * delta_md =item * delta_days =item * delta_ms =item * compare =item * compare_ignore_floating =item * DefaultLanguage =back =head2 "Set" Methods =over 4 =item * set Use this to set or undefine a datetime field: $dti->set( month => 12 ); $dti->set( day => 24 ); $dti->set( day => undef ); This method takes the same arguments as the C method in C, but it can accept C for any value. =item * set_time_zone This method accepts either a time zone object or a string that can be passed as the "name" parameter to C<< DateTime::TimeZone->new() >>. Unlike with C, if the new time zone's offset is different from the previous time zone, no local time adjustment is made. You can remove time zone information by calling this method with the value C. =item * truncate( to => ... ) This method allows you to reset some of the local time components in the object to their "zero" values. The "to" parameter is used to specify which values to truncate, and it may be one of "year", "month", "day", "hour", "minute", or "second". For example, if "month" is specified, then the local day becomes 1, and the hour, minute, and second all become 0. Note that the "to" parameter B. =back =head1 "DATETIME::INCOMPLETE" METHODS C objects also have a number of methods unique to this class. =over 4 =item * base Returns the base datetime value, or C if the object has none. =item * has_base Returns a boolean value indicating whether or not the object has a base datetime set. =item * is_undef Returns true if the datetime is completely undefined. =item * can_be_datetime Returns true if the datetime has enough information to be converted to a proper DateTime object. The year field must be valid, followed by a sequence of valid fields. Examples: Can be datetime: 2003-xx-xxTxx:xx:xx 2003-10-xxTxx:xx:xx 2003-10-13Txx:xx:xx Can not be datetime: 2003-10-13Txx:xx:30 xxxx-10-13Txx:xx:30 =cut #=item * become_datetime # #Returns a C object. # #Returns C if the year value is not set. # #This method may C if the parameters are not valid #in the call to Cnew>. =item * set_base Sets the base datetime object for the C object. The default value for "base" is C, which means no validation is made on input. =item * to_datetime This method takes an optional "base" parameter and returns a "complete" datetime. $dt = $dti->to_datetime( base => DateTime->now ); $dti->set_base( DateTime->now ); $dt = $dti->to_datetime; The resulting datetime can be either before of after the given base datetime. No adjustments are made, besides setting the missing fields. This method will use C if the object has no base datetime set and none is given as an argument. This method may die if it results in a datetime that doesn't actually exist, such as February 30, for example. The fields in the resulting datetime are set in this order: locale, time_zone, nanosecond, second, minute, hour, day, month, year. =item * to_recurrence This method generates the set of all possible datetimes that fit into an incomplete datetime definition. $dti = DateTime::Incomplete->new( month => 12, day => 24 ); $dtset1 = $dti->to_recurrence; # Christmas recurrence, with _seconds_ resolution $dti->truncate( to => 'day' ); $dtset2 = $dti->to_recurrence; # Christmas recurrence, with days resolution (hour/min/sec = 00:00:00) Those recurrences are C objects: $dt_next_xmas = $dti->to_recurrence->next( DateTime->today ); Incomplete dates that have the year defined will generate finite sets. This kind of set can take a lot of resources (RAM and CPU). The following incomplete datetime would generate the set of I in 2003: 2003-xx-xxTxx:xx:xx Recurrences are generated with up to 1 second resolution. The C value is ignored. =item * to_spanset This method generates the set of all possible spans that fit into an incomplete datetime definition. $dti = DateTime::Incomplete->new( month => 12, day => 24 ); $dtset1 = $dti->to_spanset; # Christmas recurrence, from xxxx-12-24T00:00:00 # to xxxx-12-25T00:00:00 =item * start =item * end =item * to_span These methods view an incomplete datetime as a "time span". For example, the incomplete datetime C<2003-xx-xxTxx:xx:xx> starts in C<2003-01-01T00:00:00> and ends in C<2004-01-01T00:00:00>. The C method returns a C object. An incomplete datetime without an year spans "forever". Start and end datetimes are C. =item * contains Returns a true value if the incomplete datetime range I a given datetime value. For example: 2003-xx-xx contains 2003-12-24 2003-xx-xx does not contain 1999-12-14 =item * previous / next / closest $dt2 = $dti->next( $dt ); The C returns the first complete date I to the given datetime. The C returns the first complete date I to the given datetime. The C returns the closest complete date (previous or next) to the given datetime. All of these methods return C if there is no matching complete datetime. If no datetime is given, these methods use the "base" datetime. Note: The definition of C and C is different from the methods of the same name in the C class. The datetimes are generated with 1 nanosecond precision. The last "time" value of a given day is 23:59:59.999999999 (for non leapsecond days). =back =head1 SUPPORT Support for this module is provided via the datetime@perl.org email list. See http://lists.perl.org/ for more details. =head1 AUTHORS Flavio S. Glock With Ben Bennett , Claus Farber , Dave Rolsky , Eugene Van Der Pijll , Rick Measham , and the DateTime team. =head1 COPYRIGHT Copyright (c) 2003 Flavio S. Glock. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. =head1 SEE ALSO datetime@perl.org mailing list http://datetime.perl.org/ =cut