DateTime-Event-Recurrence-0.19/0000755000175000017500000000000013057613173015613 5ustar fglockfglockDateTime-Event-Recurrence-0.19/CREDITS0000644000175000017500000000016013057610261016623 0ustar fglockfglockCREDITS list for Perl module DateTime::Event::Recurrence The credits are in lib/DateTime/Event/Recurrence.pm ! DateTime-Event-Recurrence-0.19/MANIFEST0000644000175000017500000000100513057610261016733 0ustar fglockfglockCREDITS Changes LICENSE MANIFEST This list of files MANIFEST.SKIP Makefile.PL README TODO lib/DateTime/Event/Recurrence.pm t/00load.t t/01sanity.t t/02next.t t/03offset.t t/04neg_offset.t t/05set.t t/06overflow.t t/07set-2.t t/08stress.t t/09yearly_weekly.t t/10weekly_more.t t/11mixed_offset.t t/12monthly_weekly.t t/13yearly_by_day.t t/22intersects.t META.yml Module meta-data (added by MakeMaker) META.json Module JSON meta-data (added by MakeMaker) DateTime-Event-Recurrence-0.19/MANIFEST.SKIP0000644000175000017500000000020413057610261017500 0ustar fglockfglock^blib/ ^Makefile$ ^Makefile\.[a-z]+$ ^pm_to_blib$ CVS/.* ,v$ ^tmp/ \.old$ \.bak$ ~$ ^# \.shar$ \.tar$ \.tgz$ \.tar\.gz$ \.zip$ _uu$ DateTime-Event-Recurrence-0.19/META.yml0000664000175000017500000000115613057613173017071 0ustar fglockfglock--- abstract: 'DateTime base recurrences' 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-Event-Recurrence no_index: directory: - t - inc requires: DateTime: '0.27' DateTime::Set: '0.3600' resources: repository: https://github.com/fglock/DateTime-Event-Recurrence.git version: '0.19' DateTime-Event-Recurrence-0.19/Changes0000644000175000017500000001147413057612546017120 0ustar fglockfglock0.19 2017-03-07 - Documentation: -- "week_start_day" parameter no longer marked "for internal use". -- Fix "week day" examples. Pointed out by Eric Jensen and Zefram in a thread started by Andrew Martin in datetime@perl.org -- Clarify that week_start_day defaults to "1mo", except for yearly recurrences that default to "mo". Patches by David Steinbrunner. -- Updated contact email. 0.18 2015-11-11 - added a test; depends on DateTime::Set 0.3600 0.17 2005-08-11 - added a test and fixed a bug where the parameter to next($dt) had a timezone. Reported by Simon Wistow. 0.16 2005-05-12 - fix 'BYWEEK' -> 'BYWEEKNO' - Depends on DateTime 0.27 because it uses local_rd_values(). This fixes a local/UTC problem reported by Dave Rolsky. - uses no DateTime.pm internals - removed (undocumented) arguments 'after' and 'start' 0.15_02 2005-01-27 - allows interleaved neg/positive values; allows repeated indexes. Supports weird argument lists such as [ -200, -10, -10, 200, 20 ]. Speed is slower by another 10%. 0.15_01 2005-01-26 - full overflow checking. The previous version only checked for some kinds of month overflows. The tests run slower by about 12%. - checks for invalid parameters, such as "monthly( months=>xx )" or "yearly( months=>xx, weeks=>xx )" - added a dispatch table for "offset" calculations - fixed and added tests for monthly( week => ...) - modified "sort positive values first". Patch by Yitzchak Scott-Thoennes. - refactored _setup_parameters() - Updated pod and tests. 0.15 2005-01-19 - array-ref parameter lists are not mutated. Patch by Daisuke Maki. - rewritten "sort positive values first" in _setup_parameters() 0.14 - requires DT::Set 0.17, because 0.16 had a bug that would break some tests. 0.13 2004-06-17 - a weekly recurrence with an interval behaves strangely, if the given dtstart is a sunday. Reported by Bridget Almas. Fix: _week() uses "week start day" in the calculation. 0.12 2004-05-26 - monthly recurrence at day 29 shows march-01. Reported by Bridget Almas. 0.11 2004-05-24 - using both 'interval' and 'start' parameters could cause the program to hang. Reported by Bridget Almas. 0.10 2004-03-17 0.0901 2004-03-09 - the recurrence functions accept infinite DateTimes, as required by DT::Set 0.1402 0.09 2003-10-10 - recurrences can be formatted using DateTime::Format::ICal->format_recurrence(). Some recurrences (ex: nanoseconds) are not supported by ICal format. - added nanosecond tests 0.08 2003-10-31 - bugfix: when "interval==1" it should be processed as if there was no interval. Found by Danny Rappleyea - document "start" parameter. - changed some operations in next/previous that were done twice. 0.07 2003-09-02 - tests pass under Perl 5.00503 0.06 - defines DateTime::Set::ICal class, in order to provide ICal strings to represent recurrences (set/get_ical) 0.05 2003-05-23 - memoizes durations; makes less calls to DT::Duration->new - 'weekly' can use 'week_start_day' 0.04 2003-05-14 - turn on warnings in tests and fix all warnings given. - require DateTime::Set 0.06 0.03 2003-05-12 - iterates using binary tree - parameter checking - fixed behaviour of negative numbers (rfc2445) 14h and -15min was: 13:45 = subtract 15 minutes now: 14:45 = last 15 minutes of hour - removed parameter 'year_type' - 'duration' argument is obsolete - added 'interval' parameter - moved local parameters to a hash - moved unit-specific subs to hash - added year_type => 'weekly' to yearly (internal) default is year_type => 'monthly'. 0.02 2003-04-27 - tests month-day overflow for positive day offsets, if 'month' argument is specified. Skips a datetime if it is invalid. - setup structure to allow other overflow tests. - returns empty set for 'impossible' recurrences. - many docs and code tweaks. by Dave Rolsky 0.01 2003-04-21 - CPAN upload - no longer inherits DateTime::Set 0.00_11 - added 'set' tests - docs correction. Dave Rolsky 0.00_10 - ISA DateTime::Set - removed as_set - moved all accessors to DateTime::Set - requires DT::Set 0.02 0.00_09 - new syntax $r = DT::E::R->monthly ( days => [ 4, 15, 18 ], hours => [ 10, 20 ] ); 0.00_08 - both previous and next work; all tests pass; more docs 0.00_07 - works with 2-D durations; looks up table in linear time (in worst case). That is, a 4x4 table gives 4^4 combinations but is looked up in 4*4 time. But it could be done in 4log4 time... 0.00_06 - works with multiple durations like $r = DT::E::R->monthly ( duration => \@durations ); - durations _must_ be pre-sorted. 0.00_05 - refactored constructor subs - added a very rough multiple-duration structure (doesn't work with mixed negative/positive durations) 0.00_03 - "duration" argument in constructors 0.00_02 - previous, closest, weekly DateTime-Event-Recurrence-0.19/META.json0000664000175000017500000000220713057613173017237 0ustar fglockfglock{ "abstract" : "DateTime base recurrences", "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-Event-Recurrence", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "DateTime" : "0.27", "DateTime::Set" : "0.3600" } } }, "release_status" : "stable", "resources" : { "repository" : { "type" : "git", "url" : "https://github.com/fglock/DateTime-Event-Recurrence.git", "web" : "https://github.com/fglock/DateTime-Event-Recurrence" } }, "version" : "0.19" } DateTime-Event-Recurrence-0.19/LICENSE0000644000175000017500000005010113057610261016610 0ustar fglockfglockTerms 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-Event-Recurrence-0.19/TODO0000644000175000017500000000123313057610261016275 0ustar fglockfglockTODO list for Perl module DateTime::Event::Recurrence "ICAL FORMAT" * tests with ICal format, using DateTime::Format::ICal->format_recurrence(): wkst interval start date monthly, week + day (is it day-of-week or day-of-month?) * it should not generate an ICal string if it finds an invalid WKST or # DONE if it specify nanoseconds or if there is a "start" value * move class DateTime::Set::ICal to a separate file OTHER * add tests for error-messages * move calculations to a DateTime::Util::* module * add more tests with 'interval' > 1 * add more 'previous' tests * find out how it behaves with mixed timezones and DST changes DateTime-Event-Recurrence-0.19/t/0000755000175000017500000000000013057613173016056 5ustar fglockfglockDateTime-Event-Recurrence-0.19/t/04neg_offset.t0000644000175000017500000000465112620326751020532 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 16; use DateTime; use DateTime::Event::Recurrence; # MONTHLY { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); # last day of month my $monthly = monthly DateTime::Event::Recurrence ( days => -1 ); my $dt; $dt = $monthly->next( $dt1 ); is ( $dt->datetime, '2003-04-30T00:00:00', 'next' ); $dt = $monthly->next( $dt ); is ( $dt->datetime, '2003-05-31T00:00:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $monthly->previous( $dt1 ); is ( $dt->datetime, '2003-03-31T00:00:00', 'previous' ); $dt = $monthly->previous( $dt ); is ( $dt->datetime, '2003-02-28T00:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $monthly->closest( $dt1 ); is ( $dt->datetime, '2003-04-30T00:00:00', 'closest' ); $dt = $dt->subtract( days => 20 ); # 2003-04-10T00:00:00 $dt = $monthly->closest( $dt ); is ( $dt->datetime, '2003-03-31T00:00:00', 'closest' ); } # WEEKLY { # mon tue wed thu fri sat sun # 14 15 16 17 18 19 20 # 21 22 23 24 25 26 27 # 28 29 30 # +0 +1 +2 -3 -2 -1 my $dt1 = new DateTime( year => 2003, month => 4, day => 18, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $weekly = weekly DateTime::Event::Recurrence( days => -2 ); # Sat my $dt; $dt = $weekly->next( $dt1 ); is ( $dt->datetime, '2003-04-19T00:00:00', 'next' ); $dt = $weekly->next( $dt ); is ( $dt->datetime, '2003-04-26T00:00:00', 'next' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->previous( $dt1 ); is ( $dt->datetime, '2003-04-12T00:00:00', 'previous' ); $dt = $weekly->previous( $dt ); is ( $dt->datetime, '2003-04-05T00:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->closest( $dt1 ); is ( $dt->datetime, '2003-04-19T00:00:00', 'closest' ); $dt = $dt->subtract( days => 5 ); # 2003-04-14T00:00:00 $dt = $weekly->closest( $dt ); is ( $dt->datetime, '2003-04-12T00:00:00', 'closest' ); } DateTime-Event-Recurrence-0.19/t/08stress.t0000644000175000017500000000651012620326751017736 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 14; use DateTime; use DateTime::SpanSet; use DateTime::Event::Recurrence; sub str { ref($_[0]) ? $_[0]->datetime : $_[0] } sub span_str { str($_[0]->min) . '..' . str($_[0]->max) } { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( nanoseconds => [ 500000, 700000 ], ); my $dt; $dt = $r1->next( $dt1 ); is ( $dt->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2004-01-01T00:00:00.000500000', 'next nanosecond' ); $dt = $r1->next( $dt ); is ( $dt->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2004-01-01T00:00:00.000700000', 'next nanosecond' ); $dt = $r1->next( $dt ); is ( $dt->strftime( "%Y-%m-%dT%H:%M:%S.%N" ), '2005-01-01T00:00:00.000500000', 'next nanosecond' ); } { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 1 .. 12 ], days => [ 1 .. 31 ], hours => [ 0 .. 23 ], minutes => [ 0 .. 59 ], seconds => [ 0 .. 59 ], ); my $r2 = daily DateTime::Event::Recurrence ( hours => [ 0, 2, 4, 8, 10, 12, 14, 16, 18, 20, 22 ], minutes => [ 0, 15, 30, 45 ] ); my $dt; $dt = $r1->next( $dt1 ); is ( $dt->datetime, '2003-04-28T12:10:46', 'next' ); $dt = $r1->next( $dt ); is ( $dt->datetime, '2003-04-28T12:10:47', 'next' ); $dt = $r2->next( $dt1 ); is ( $dt->datetime, '2003-04-28T12:15:00', 'next' ); $dt = $r2->next( $dt ); is ( $dt->datetime, '2003-04-28T12:30:00', 'next' ); my $r = $r1->intersection( $r2 ); $dt = $r->next( $dt1 ); is ( $dt->datetime, '2003-04-28T12:15:00', 'next intersection' ); $dt = $r->next( $dt ); is ( $dt->datetime, '2003-04-28T12:30:00', 'next intersection' ); $dt = $r->next( $dt ); is ( $dt->datetime, '2003-04-28T12:45:00', 'next intersection' ); $dt = $r->previous( $dt1 ); is ( str($dt), '2003-04-28T12:00:00', 'previous intersection' ); if ( $dt ) { $dt = $r->previous( $dt ); is ( str($dt), '2003-04-28T10:45:00', 'previous intersection' ); $dt = $r->previous( $dt ); is ( str($dt), '2003-04-28T10:30:00', 'previous intersection' ); } } { # NO-INTERSECTION my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 1 .. 12 ], days => [ 1 .. 31 ], hours => [ 14 ], minutes => [ 15 ] ); my $r2 = daily DateTime::Event::Recurrence ( hours => [ 11, 15 ], minutes => [ 15 ] ); my $dt; my $r = $r1->intersection( $r2 ); $dt = $r->next( $dt1 ); is ( $dt, undef, 'next no-intersection' ); } # TODO - make a test that has an intersection, but that is hard to find. DateTime-Event-Recurrence-0.19/t/05set.t0000644000175000017500000000507512620326751017210 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 9; use DateTime; use DateTime::Event::Recurrence; { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily_full = daily DateTime::Event::Recurrence ( hours => [ 10, 14, -1 ], # 10,14,23 minutes => [ 30, -15, 15 ] ); # 15,30,45 my $dt; # UNION my $dt_more = new DateTime( year => 2003, month => 4, day => 28, hour => 14, minute => 0, second => 0, time_zone => 'UTC' ); my $daily_join = $daily_full->union( $dt_more ); $dt = $daily_join->next( $dt1 ); #-- this datetime was added... is ( $dt->datetime, '2003-04-28T14:00:00', 'next union' ); $dt = $daily_join->next( $dt ); #-- is ( $dt->datetime, '2003-04-28T14:15:00', 'next union' ); $dt = $daily_join->next( $dt ); is ( $dt->datetime, '2003-04-28T14:30:00', 'next union' ); $dt = $daily_join->next( $dt ); is ( $dt->datetime, '2003-04-28T14:45:00', 'next union' ); # INTERSECTION my $dt_only = new DateTime( year => 2003, month => 4, day => 28, hour => 14, minute => 15, second => 0, time_zone => 'UTC' ); my $daily_selected = $daily_full->intersection( $dt_only ); #-- this datetime was not selected... # $dt = $daily_selected->next( $dt1 ); # is ( $dt->datetime, '2003-04-28T13:45:00', 'next intersection' ); #-- $dt = $daily_selected->next( $dt1 ); is ( $dt->datetime, '2003-04-28T14:15:00', 'next intersection' ); #-- no more datetimes $dt = $daily_selected->next( $dt ); is ( $dt, undef, 'no next intersection' ); # COMPLEMENT my $dt_out = new DateTime( year => 2003, month => 4, day => 28, hour => 14, minute => 15, second => 0, time_zone => 'UTC' ); my $daily_except = $daily_full->complement( $dt_out ); $dt = $daily_except->next( $dt1 ); is ( $dt->datetime, '2003-04-28T14:30:00', 'next complement' ); $dt = $daily_except->next( $dt ); #-- this datetime was removed... # is ( $dt->datetime, '2003-04-28T14:15:00', 'next complement' ); # $dt = $daily_except->next( $dt ); #-- is ( $dt->datetime, '2003-04-28T14:45:00', 'next complement' ); $dt = $daily_except->next( $dt ); is ( $dt->datetime, '2003-04-28T23:15:00', 'next complement' ); } DateTime-Event-Recurrence-0.19/t/00load.t0000644000175000017500000000014112620326751017314 0ustar fglockfglock#!/usr/bin/perl -w use Test::More; plan tests => 1; use_ok( 'DateTime::Event::Recurrence' ); DateTime-Event-Recurrence-0.19/t/09yearly_weekly.t0000644000175000017500000000556212620326751021307 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 6; use DateTime; use DateTime::Event::Recurrence; { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $dt2 = new DateTime( year => 2006, month => 5, day => 01, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $yearly = yearly DateTime::Event::Recurrence( weeks => 1 ); # year_type => 'weekly' ); my @dt = $yearly->as_list( start => $dt1, end => $dt2 ); my $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-29T00:00:00 2005-01-03T00:00:00 2006-01-02T00:00:00', "yearly-weekly" ); $yearly = yearly DateTime::Event::Recurrence( # year_type => 'weekly', weeks => [ 2 ] ); @dt = $yearly->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2004-01-05T00:00:00 2005-01-10T00:00:00 2006-01-09T00:00:00', "yearly-weekly week 2" ); $yearly = yearly DateTime::Event::Recurrence( weeks => -1 ); @dt = $yearly->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-22T00:00:00 2004-12-27T00:00:00 2005-12-26T00:00:00', "yearly-weekly weeks -1" ); $yearly = yearly DateTime::Event::Recurrence( # year_type => 'weekly', weeks => [ -1 ] ); @dt = $yearly->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-22T00:00:00 2004-12-27T00:00:00 2005-12-26T00:00:00', "yearly-weekly week -1" ); $yearly = yearly DateTime::Event::Recurrence( # year_type => 'weekly', weeks => [ -1, 2 ] ); @dt = $yearly->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-22T00:00:00 2004-01-05T00:00:00 '. '2004-12-27T00:00:00 2005-01-10T00:00:00 '. '2005-12-26T00:00:00 2006-01-09T00:00:00', "yearly-weekly week -1, 2" ); # YEARLY TYPE AUTO-DETECTION $yearly = yearly DateTime::Event::Recurrence( # year_type => 'weekly', weeks => [ -1, 2 ] ); @dt = $yearly->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-22T00:00:00 2004-01-05T00:00:00 '. '2004-12-27T00:00:00 2005-01-10T00:00:00 '. '2005-12-26T00:00:00 2006-01-09T00:00:00', "yearly-weekly week -1, 2" ); } DateTime-Event-Recurrence-0.19/t/01sanity.t0000644000175000017500000000335412620326751017716 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 4; use DateTime; use DateTime::Event::Recurrence; my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $dt2 = new DateTime( year => 2003, month => 5, day => 01, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); { # DAILY my $daily = daily DateTime::Event::Recurrence; my @dt = $daily->as_list( start => $dt1, end => $dt2 ); is( $daily->next( DateTime->new( year => 2005 ) )->time_zone_long_name, 'floating', 'the set is created with floating time zone' ); my $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-29T00:00:00 2003-04-30T00:00:00 2003-05-01T00:00:00', "daily" ); } { # WEEKLY my $start = $dt1->clone->subtract( days => 15 ); my $weekly = weekly DateTime::Event::Recurrence; my @dt = $weekly->as_list( start => $start, end => $dt2 ); my $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-14T00:00:00 2003-04-21T00:00:00 2003-04-28T00:00:00', "weekly" ); } { # Test if there are any side-effects on parameters my $start = $dt1->clone->subtract( days => 15 ); my $day = [ 1 ]; my $weekly = weekly DateTime::Event::Recurrence( days => $day ); my @dt = $weekly->as_list( start => $start, end => $dt2 ); my $r = join(' ', map { $_->datetime } @dt); is( "@$day", "1", "it has no side-effects on parameters" ); } DateTime-Event-Recurrence-0.19/t/13yearly_by_day.t0000644000175000017500000000156012620326751021243 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 1; use DateTime; use DateTime::Event::Recurrence; { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $dt2 = new DateTime( year => 2006, month => 5, day => 01, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $yearly = yearly DateTime::Event::Recurrence( days => 40 ); my @dt = $yearly->as_list( start => $dt1, end => $dt2 ); my $r = join(' ', map { $_->datetime } @dt); is( $r, '2004-02-09T00:00:00 2005-02-09T00:00:00 2006-02-09T00:00:00', "yearly-by-day" ); } DateTime-Event-Recurrence-0.19/t/12monthly_weekly.t0000644000175000017500000000244512620326751021463 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 2; use DateTime; use DateTime::Event::Recurrence; my $dt1 = new DateTime( year => 1997, month => 9, day => 1, time_zone => 'UTC' ); my $dt2 = new DateTime( year => 1998, month => 6, day => 1, time_zone => 'UTC' ); { my $monthly = monthly DateTime::Event::Recurrence( week_start_day => '1fr', weeks => 1, hours => 9 ); my @dt = $monthly->as_list( start => $dt1, end => $dt2 ); my $r = join(',', map { $_->datetime } @dt); is( $r, '1997-09-05T09:00:00,1997-10-03T09:00:00,1997-11-07T09:00:00,'. '1997-12-05T09:00:00,1998-01-02T09:00:00,1998-02-06T09:00:00,'. '1998-03-06T09:00:00,1998-04-03T09:00:00,1998-05-01T09:00:00', "monthly-weekly" ); } { my $monthly = monthly DateTime::Event::Recurrence( week_start_day => 'fr', weeks => 1, hours => 9 ); my @dt = $monthly->as_list( start => $dt1, end => $dt2 ); my $r = join(',', map { $_->datetime } @dt); is( $r, '1997-10-03T09:00:00,1997-10-31T09:00:00,'. '1997-11-28T09:00:00,1998-01-02T09:00:00,'. '1998-01-30T09:00:00,1998-02-27T09:00:00,'. '1998-04-03T09:00:00,1998-05-01T09:00:00,1998-05-29T09:00:00', "monthly-weekly" ); } DateTime-Event-Recurrence-0.19/t/03offset.t0000644000175000017500000002234112620326751017674 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 61; use DateTime; use DateTime::Event::Recurrence; # DAILY { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence ( hours => 10 ); my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-29T10:00:00', 'next daily' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-30T10:00:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2003-04-28T10:00:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-27T10:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); is ( $dt->datetime, '2003-04-28T10:00:00', 'closest' ); $dt = $dt->subtract( hours => 20 ); # 2003-04-28T14:00:00 $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-04-27T10:00:00', 'closest' ); } # WEEKLY { # mon tue wed thu fri sat sun # 14 15 16 17 18 19 20 # 21 22 23 24 25 26 27 # 28 29 30 # +0 +1 +2 my $dt1 = new DateTime( year => 2003, month => 4, day => 18, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $weekly = weekly DateTime::Event::Recurrence( days => 3 ); # Wed my $dt; $dt = $weekly->next( $dt1 ); is ( $dt->datetime, '2003-04-23T00:00:00', 'next weekly' ); $dt = $weekly->next( $dt ); is ( $dt->datetime, '2003-04-30T00:00:00', 'next' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->previous( $dt1 ); is ( $dt->datetime, '2003-04-16T00:00:00', 'previous' ); $dt = $weekly->previous( $dt ); is ( $dt->datetime, '2003-04-09T00:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->closest( $dt1 ); is ( $dt->datetime, '2003-04-16T00:00:00', 'closest' ); $dt = $dt->add( days => 5 ); # 2003-04-21T00:00:00 $dt = $weekly->closest( $dt ); is ( $dt->datetime, '2003-04-23T00:00:00', 'closest' ); } # WEEKLY with "duration" { my $dt1 = new DateTime( year => 2003, month => 4, day => 18, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $weekly = weekly DateTime::Event::Recurrence( days => 3 ); # duration => new DateTime::Duration( days => 2 ) ); # Wed my $dt; $dt = $weekly->next( $dt1 ); is ( $dt->datetime, '2003-04-23T00:00:00', 'next syntax' ); } # -- test 18 # DAILY, many occurrences { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence ( hours => [ -1, 10, 14 ] ); # duration => [ [ # new DateTime::Duration( hours => -1 ), # new DateTime::Duration( hours => 10 ), # new DateTime::Duration( hours => 14 ), # ] ] ); my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-28T14:00:00', 'next daily many' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T23:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-29T10:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-29T14:00:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2003-04-28T10:00:00', 'previous ' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-27T23:00:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-27T14:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); is ( $dt->datetime, '2003-04-28T14:00:00', 'closest' ); $dt = $dt->subtract( hours => 3 ); # 2003-04-28T11:00:00 $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-04-28T10:00:00', 'closest' ); } # DAILY, many many occurrences { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence ( hours => [ -1, 10, 14 ] , minutes => [ -15, 15, 30 ] ); # duration => [ [ # new DateTime::Duration( hours => -1 ), # 23h # new DateTime::Duration( hours => 10 ), # new DateTime::Duration( hours => 14 ), ], # [ # new DateTime::Duration( minutes => -15 ), # 45min # new DateTime::Duration( minutes => 15 ), # new DateTime::Duration( minutes => 30 ), # ], # ] ); # 10:15 10:30 10:45 # 14:15 14:30 14:45 # 23:15 23:30 23:45 my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-28T14:15:00', 'next daily many many' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T14:30:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T14:45:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T23:15:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2003-04-28T10:45:00', 'previous '.$dt->datetime ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-28T10:30:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-28T10:15:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); # 12:10 is ( $dt->datetime, '2003-04-28T10:45:00', 'closest' ); $dt = $dt->subtract( hours => 3 ); # 09:10:00 $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-04-28T10:15:00', 'closest' ); } # DAILY, many many occurrences + syntax sugar { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence ( hours => [ 10, 14, -1 ], minutes => [ 30, -15, 15 ] ); my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-28T14:15:00', 'next daily many many syntax' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T14:30:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T14:45:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-28T23:15:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2003-04-28T10:45:00', 'previous '.$dt->datetime ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-28T10:30:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-28T10:15:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); is ( $dt->datetime, '2003-04-28T10:45:00', 'closest' ); $dt = $dt->subtract( hours => 3 ); # 2003-04-28T09:10:00 $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-04-28T10:15:00', 'closest' ); } # YEARLY, many occurrences + syntax sugar { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = yearly DateTime::Event::Recurrence ( months => [ 9, 11 ], days => [ 15 ], hours => [ 14 ] ); my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-09-15T14:00:00', 'next yearly many syntax' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-11-15T14:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2004-09-15T14:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2004-11-15T14:00:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2002-11-15T14:00:00', 'previous '.$dt->datetime ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2002-09-15T14:00:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2001-11-15T14:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); is ( $dt->datetime, '2003-09-15T14:00:00', 'closest' ); $dt = $dt->add( months => 3 ); $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-11-15T14:00:00', 'closest' ); } DateTime-Event-Recurrence-0.19/t/02next.t0000644000175000017500000000427512620326751017371 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 16; use DateTime; use DateTime::Event::Recurrence; # DAILY { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence; my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-29T00:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-30T00:00:00', 'next' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->previous( $dt1 ); is ( $dt->datetime, '2003-04-28T00:00:00', 'previous' ); $dt = $daily->previous( $dt ); is ( $dt->datetime, '2003-04-27T00:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-28T12:10:45', 'immutable' ); $dt = $daily->closest( $dt1 ); is ( $dt->datetime, '2003-04-29T00:00:00', 'closest' ); $dt = $dt->subtract( hours => 14 ); # 2003-04-28T10:00:00 $dt = $daily->closest( $dt ); is ( $dt->datetime, '2003-04-28T00:00:00', 'closest' ); } # WEEKLY { my $dt1 = new DateTime( year => 2003, month => 4, day => 18, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $weekly = weekly DateTime::Event::Recurrence; my $dt; $dt = $weekly->next( $dt1 ); is ( $dt->datetime, '2003-04-21T00:00:00', 'next' ); $dt = $weekly->next( $dt ); is ( $dt->datetime, '2003-04-28T00:00:00', 'next' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->previous( $dt1 ); is ( $dt->datetime, '2003-04-14T00:00:00', 'previous' ); $dt = $weekly->previous( $dt ); is ( $dt->datetime, '2003-04-07T00:00:00', 'previous' ); is ( $dt1->datetime, '2003-04-18T12:10:45', 'immutable' ); $dt = $weekly->closest( $dt1 ); is ( $dt->datetime, '2003-04-21T00:00:00', 'closest' ); $dt = $dt->subtract( days => 5 ); # 2003-04-17T00:00:00 $dt = $weekly->closest( $dt ); is ( $dt->datetime, '2003-04-14T00:00:00', 'closest' ); } DateTime-Event-Recurrence-0.19/t/11mixed_offset.t0000644000175000017500000000166412620326751021066 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 5; use DateTime; use DateTime::Event::Recurrence; { # intermixed neg/pos args my $dt1 = new DateTime( year => 2003, month => 4, day => 30, hour => 1, minute => 2, second => 3, nanosecond => 123456, time_zone => 'UTC' ); my $daily = daily DateTime::Event::Recurrence ( hours => [ 10, 10, 20, -10, -10, -20 ] ); my $dt; $dt = $daily->next( $dt1 ); is ( $dt->datetime, '2003-04-30T04:00:00', 'next daily' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-30T10:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-30T14:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-04-30T20:00:00', 'next' ); $dt = $daily->next( $dt ); is ( $dt->datetime, '2003-05-01T04:00:00', 'next' ); } DateTime-Event-Recurrence-0.19/t/22intersects.t0000644000175000017500000000105112620577610020567 0ustar fglockfglockuse DateTime::Event::Recurrence; use Test::More; use strict; use warnings; plan tests => 3; my $hourly = DateTime::Event::Recurrence->hourly; my $next_day = DateTime::Span->from_datetimes( start => DateTime->now, end => DateTime->now->add( days => 1 ) ); my $future = DateTime::Span->from_datetimes( start => DateTime->now ); ok( $next_day->intersects($future), "next day intersects future" ); ok( $hourly->intersects($next_day), "hourly event intersects next day" ); ok( $hourly->intersects($future), "hourly event intersects future" ); DateTime-Event-Recurrence-0.19/t/07set-2.t0000644000175000017500000000726112620326751017350 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 9; use DateTime; use DateTime::SpanSet; use DateTime::Event::Recurrence; sub str { ref($_[0]) ? $_[0]->datetime : $_[0] } sub span_str { str($_[0]->min) . '..' . str($_[0]->max) } { # INTERSECTION my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 10, 14 ], days => [ 15 ], hours => [ 14 ], minutes => [ 15 ] ); my $r2 = daily DateTime::Event::Recurrence ( hours => [ 10, 14 ], minutes => [ 15 ] ); my $dt; my $r = $r1->intersection( $r2 ); $dt = $r->next( $dt1 ); is ( $dt->datetime, '2003-10-15T14:15:00', 'next intersection' ); $dt = $r->next( $dt ); is ( $dt->datetime, '2004-10-15T14:15:00', 'next intersection' ); $dt = $r->next( $dt ); is ( $dt->datetime, '2005-10-15T14:15:00', 'next intersection' ); } { # NO-INTERSECTION my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 10, 14 ], days => [ 15 ], hours => [ 14 ], minutes => [ 15 ] ); my $r2 = daily DateTime::Event::Recurrence ( hours => [ 11, 15 ], minutes => [ 15 ] ); my $dt; my $r = $r1->intersection( $r2 ); $dt = $r->next( $dt1 ); is ( $dt, undef, 'next no-intersection' ); } { # BUILD SPAN-SET my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 9, 11 ], days => [ 15 ], hours => [ 14 ] ); my $r = DateTime::SpanSet->from_set_and_duration( set => $r1, hours => 1, ); my $span; my $s; # test Set my $iterator = $r1->intersection( DateTime::Span->new( after => $dt1 ) ) ->iterator; $span = $iterator->next; $s = str( $span ); is ( $s, '2003-09-15T14:00:00', 'next set' ); $span = $iterator->next; $s = str( $span ); is ( $s, '2003-11-15T14:00:00', 'next set' ); # test SpanSet $iterator = $r->intersection( DateTime::Span->new( after => $dt1 ) ) ->iterator; $span = $iterator->next; $s = span_str( $span ); is ( $s, '2003-09-15T14:00:00..2003-09-15T15:00:00', 'next span-set' ); $span = $iterator->next; $s = span_str( $span ); is ( $s, '2003-11-15T14:00:00..2003-11-15T15:00:00', 'next span-set' ); } { # INTERSECTION TO SPAN-SET my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $r1 = yearly DateTime::Event::Recurrence ( months => [ 10, 14 ], days => [ 15 ], hours => [ 14 ] ); my $rs1 = DateTime::SpanSet->from_set_and_duration( set => $r1, hours => 1, ); my $r2 = daily DateTime::Event::Recurrence ( minutes => [ 15 ] ); my $dt; my $r = $r2->intersection( $rs1 ); $dt = $r->next( $dt1 ); is ( $dt, undef, 'next intersection to span-set' ); } DateTime-Event-Recurrence-0.19/t/06overflow.t0000644000175000017500000001566212620326751020264 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 35; use DateTime; use DateTime::Event::Recurrence; { # multiple overflows my $dt1 = new DateTime( year => 2004, month => 3, day => 3, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $yearly = yearly DateTime::Event::Recurrence ( months => [ 2, 12 ], days => [ 1 .. 31 ], hours => 12, minutes => 10, seconds => 45, ); my $dt; $dt = $yearly->next( $dt1 ); is ( $dt->datetime, '2004-12-01T12:10:45', 'next - multiple overflows' ); $dt = $yearly->previous( $dt1 ); is ( $dt->datetime, '2004-02-29T12:10:45', 'previous - multiple overflows' ); } { # multiple overflows - negative indexes my $dt1 = new DateTime( year => 2004, month => 3, day => 3, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $yearly = yearly DateTime::Event::Recurrence ( months => [ 2, 12 ], days => [ -31 .. -1 ], hours => 12, minutes => 10, seconds => 45, ); my $dt; $dt = $yearly->next( $dt1 ); is ( $dt->datetime, '2004-12-01T12:10:45', 'next - multiple overflows - negative' ); $dt = $yearly->previous( $dt1 ); is ( $dt->datetime, '2004-02-29T12:10:45', 'previous - multiple overflows - negative' ); } { # two options, two levels my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = monthly DateTime::Event::Recurrence ( days => [ 31, 15 ], minutes => [ 20, 30 ] ); my $dt; $dt = $month->next( $dt1 ); is ( $dt->datetime, '2003-05-15T00:20:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-05-15T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-05-31T00:20:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-05-31T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-06-15T00:20:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-06-15T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-07-15T00:20:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-07-15T00:30:00', 'next' ); # TODO: { # local $TODO = "binary search breaks overflow checks"; # PREVIOUS $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-07-15T00:20:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-06-15T00:30:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-06-15T00:20:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-05-31T00:30:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-05-31T00:20:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-05-15T00:30:00', 'previous' ); # } } { # two options my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = monthly DateTime::Event::Recurrence ( days => [ 31, 15 ], minutes => [ 30 ] ); my $dt; $dt = $month->next( $dt1 ); is ( $dt->datetime, '2003-05-15T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-05-31T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-06-15T00:30:00', 'next' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-07-15T00:30:00', 'next' ); # TODO: { # local $TODO = "binary search breaks overflow checks"; # PREVIOUS $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-06-15T00:30:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-05-31T00:30:00', 'previous' ); $dt = $month->previous( $dt ); is ( $dt->datetime, '2003-05-15T00:30:00', 'previous' ); # } } { # only one option my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = monthly DateTime::Event::Recurrence ( days => [ 31 ], minutes => [ 30 ] ); my $dt; $dt = $month->next( $dt1 ); is ( $dt->datetime, '2003-05-31T00:30:00', 'next - only one option' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-07-31T00:30:00', 'next - only one option' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-08-31T00:30:00', 'next - only one option' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-10-31T00:30:00', 'next - only one option' ); } { # invalid value my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = monthly DateTime::Event::Recurrence ( days => [ 32 ], minutes => [ 30 ] ); my $dt; $dt = $month->next( $dt1 ); is ( $dt, undef, 'next - with an invalid value' ); } { # detects an invalid argument my $month; eval { $month = monthly DateTime::Event::Recurrence ( months => [ 2 ], ); }; is ( $month, undef, 'detects an invalid argument' ); } { # february-30 my $dt1 = new DateTime( year => 2003, month => 1, day => 30, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = yearly DateTime::Event::Recurrence ( months => 2, days => 30 ); my $dt; $dt = $month->next( $dt1 ); is ( $dt, undef, 'next - feb-30' ); } { # february-29 my $dt1 = new DateTime( year => 2003, month => 1, day => 20, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $month = monthly DateTime::Event::Recurrence ( days => [ 29 ], ); my $dt; $dt = $month->next( $dt1 ); is ( $dt->datetime, '2003-01-29T00:00:00', 'next - feb-29' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-03-29T00:00:00', 'next - feb-29' ); $dt = $month->next( $dt ); is ( $dt->datetime, '2003-04-29T00:00:00', 'next - feb-29' ); } DateTime-Event-Recurrence-0.19/t/10weekly_more.t0000644000175000017500000001267112620326751020733 0ustar fglockfglock#!/usr/bin/perl -w use strict; use Test::More tests => 16; use DateTime; use DateTime::Event::Recurrence; my $dt1; my $dt2; sub calc { my @dt = $_[0]->as_list( start => $dt1, end => $dt2 ); my $r = join(' ', map { $_->datetime } @dt); return $r; } $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); $dt2 = new DateTime( year => 2006, month => 5, day => 01, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => 'mo' ); is( calc( $yearly ), '2003-12-29T00:00:00 2005-01-03T00:00:00 2006-01-02T00:00:00', "yearly-weekly mo" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => 'su' ); is( calc( $yearly ), '2004-01-04T00:00:00 2005-01-02T00:00:00 2006-01-01T00:00:00', "yearly-weekly su" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => 'tu' ); is( calc( $yearly ), '2003-12-30T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly tu" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, days => 'tu', week_start_day => 'tu' ); is( calc( $yearly ), '2003-12-30T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly tu - named week-day" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, days => 2, week_start_day => 'tu' ); is( calc( $yearly ), '2003-12-30T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly tu - numbered week-day" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1mo' ); is( calc( $yearly ), '2004-01-05T00:00:00 2005-01-03T00:00:00 2006-01-02T00:00:00', "yearly-weekly 1mo" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1su' ); is( calc( $yearly ), '2004-01-04T00:00:00 2005-01-02T00:00:00 2006-01-01T00:00:00', "yearly-weekly 1su" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1tu' ); is( calc( $yearly ), '2004-01-06T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly 1tu" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, days => 'tu', week_start_day => '1tu' ); is( calc( $yearly ), '2004-01-06T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly 1tu - named week-day" ); $yearly = yearly DateTime::Event::Recurrence( weeks => 1, days => 2, week_start_day => '1tu' ); is( calc( $yearly ), '2004-01-06T00:00:00 2005-01-04T00:00:00 2006-01-03T00:00:00', "yearly-weekly 1tu - numbered week-day" ); # MONTHLY $dt2 = new DateTime( year => 2004, month => 2, day => 01, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $monthly = monthly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1mo' ); is( calc( $monthly ), '2003-05-05T00:00:00 2003-06-02T00:00:00 2003-07-07T00:00:00 2003-08-04T00:00:00 2003-09-01T00:00:00 2003-10-06T00:00:00 2003-11-03T00:00:00 2003-12-01T00:00:00 2004-01-05T00:00:00', "monthly-weekly 1mo" ); $monthly = monthly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1su' ); is( calc( $monthly ), '2003-05-04T00:00:00 2003-06-01T00:00:00 2003-07-06T00:00:00 2003-08-03T00:00:00 2003-09-07T00:00:00 2003-10-05T00:00:00 2003-11-02T00:00:00 2003-12-07T00:00:00 2004-01-04T00:00:00 2004-02-01T00:00:00', "monthly-weekly 1su" ); $monthly = monthly DateTime::Event::Recurrence( weeks => 1, week_start_day => '1tu' ); is( calc( $monthly ), '2003-05-06T00:00:00 2003-06-03T00:00:00 2003-07-01T00:00:00 2003-08-05T00:00:00 2003-09-02T00:00:00 2003-10-07T00:00:00 2003-11-04T00:00:00 2003-12-02T00:00:00 2004-01-06T00:00:00', "monthly-weekly 1tu" ); # WEEKLY $dt2 = new DateTime( year => 2003, month => 6, day => 10, hour => 12, minute => 10, second => 45, nanosecond => 123456, time_zone => 'UTC' ); my $weekly = weekly DateTime::Event::Recurrence( week_start_day => '1su' ); is( calc( $weekly ), '2003-05-04T00:00:00 2003-05-11T00:00:00 2003-05-18T00:00:00 2003-05-25T00:00:00 2003-06-01T00:00:00 2003-06-08T00:00:00', "weekly 1su" ); $weekly = weekly DateTime::Event::Recurrence( days => 7, week_start_day => '1su' ); is( calc( $weekly ), '2003-05-04T00:00:00 2003-05-11T00:00:00 2003-05-18T00:00:00 2003-05-25T00:00:00 2003-06-01T00:00:00 2003-06-08T00:00:00', "weekly 1su - numbered week-day" ); $weekly = weekly DateTime::Event::Recurrence( days => 'su', week_start_day => '1su' ); is( calc( $weekly ), '2003-05-04T00:00:00 2003-05-11T00:00:00 2003-05-18T00:00:00 2003-05-25T00:00:00 2003-06-01T00:00:00 2003-06-08T00:00:00', "weekly 1su - named week-day" ); DateTime-Event-Recurrence-0.19/lib/0000755000175000017500000000000013057613173016361 5ustar fglockfglockDateTime-Event-Recurrence-0.19/lib/DateTime/0000755000175000017500000000000013057613173020055 5ustar fglockfglockDateTime-Event-Recurrence-0.19/lib/DateTime/Event/0000755000175000017500000000000013057613173021136 5ustar fglockfglockDateTime-Event-Recurrence-0.19/lib/DateTime/Event/Recurrence.pm0000644000175000017500000010314213057612227023571 0ustar fglockfglockuse strict; package DateTime::Set::ICal; use vars qw(@ISA); # use Carp; # a "dt::set" with a symbolic string representation @ISA = qw( DateTime::Set ); sub set_ical { # include list, exclude list my $self = shift; # carp "set_ical $_[0] => @{$_[1]}" if @_; $self->{as_ical} = [ @_ ]; $self; } sub get_ical { my $self = shift; return unless $self->{as_ical}; return @{ $self->{as_ical} }; } sub clone { my $self = shift; my $new = $self->SUPER::clone( @_ ); $new->set_ical( $self->get_ical ); $new; } sub union { my $self = shift; my $new = $self->SUPER::union( @_ ); # RFC2445 - op1, op2 must have no 'exclude' my (%op1, %op2); %op1 = ( $self->get_ical ) if ( UNIVERSAL::can( $self, 'get_ical' ) ); %op2 = ( $_[0]->get_ical ) if ( UNIVERSAL::can( $_[0], 'get_ical' ) ); return $new if ( ( exists $op1{exclude} ) || ( exists $op2{exclude} ) ); bless $new, 'DateTime::Set::ICal'; # warn " -- 1 isa @{[%op1]} -- 2 isa @{[%op2]} -- "; my @ical; @ical = exists $op1{include} ? @{$op1{include}} : $self; # push @ical, @{$op2{include}}, @_; if ( exists $op2{include} ) { push @ical, @{$op2{include}}; } else { push @ical, @_; # whatever... } # warn "union: @ical"; $new->set_ical( include => [ @ical ] ); $new; } sub complement { my $self = shift; my $new = $self->SUPER::complement( @_ ); return $new unless @_; # RFC2445 - op2 must have no 'exclude' my (%op1, %op2); %op1 = ( $self->get_ical ) if ( UNIVERSAL::can( $self, 'get_ical' ) ); %op2 = ( $_[0]->get_ical ) if ( UNIVERSAL::can( $_[0], 'get_ical' ) ); return $new if ( exists $op2{exclude} ); bless $new, 'DateTime::Set::ICal'; # warn " -- 1 isa @{[%op1]} -- 2 isa @{[%op2]} -- "; my ( @include, @exclude ); @include = exists $op1{include} ? @{$op1{include}} : $self; @exclude = exists $op1{exclude} ? @{$op1{exclude}} : (); if ( exists $op2{include} ) { push @exclude, @{$op2{include}}; } else { push @exclude, @_; # whatever... } # warn "complement: include @include exclude @exclude"; $new->set_ical( include => [ @include ], exclude => [ @exclude ] ); $new; } package DateTime::Event::Recurrence; use strict; use DateTime; use DateTime::Set; use DateTime::Span; use Params::Validate qw(:all); use vars qw( $VERSION ); $VERSION = '0.19'; use constant INFINITY => 100 ** 100 ** 100 ; use constant NEG_INFINITY => -1 * (100 ** 100 ** 100); # -------- BASE OPERATIONS use vars qw( %as_number %truncate %next_unit %previous_unit %truncate_interval %next_unit_interval %previous_unit_interval %weekdays %weekdays_1 %weekdays_any %memoized_duration %ical_name %ical_days %limits @units ); BEGIN { %weekdays = qw( mo 1 tu 2 we 3 th 4 fr 5 sa 6 su 7 ); %weekdays_1 = qw( 1mo 1 1tu 2 1we 3 1th 4 1fr 5 1sa 6 1su 7 ); %weekdays_any = ( %weekdays, %weekdays_1 ); %ical_name = qw( months BYMONTH weeks BYWEEKNO days BYMONTHDAY hours BYHOUR minutes BYMINUTE seconds BYSECOND ); %ical_days = qw( 1 MO 2 TU 3 WE 4 TH 5 FR 6 SA 7 SU -7 MO -6 TU -5 WE -4 TH -3 FR -2 SA -1 SU ); @units = qw( years months weeks days hours minutes seconds nanoseconds ); %limits = qw( nanoseconds 1000000000 seconds 61 minutes 60 hours 24 months 12 weeks 53 days 366 ); } # BEGIN # memoization reduces 'duration' creation from >10000 to about 30 per run, # in DT::E::ICal sub _add { # datetime, unit, value my $dur = \$memoized_duration{$_[1]}{$_[2]}; $$dur = new DateTime::Duration( $_[1] => $_[2] ) unless defined $$dur; $_[0]->add_duration( $$dur ); } # TODO: %as_number should use the "subtract" routines from DateTime %as_number = ( years => sub { $_[0]->year }, months => sub { 12 * $_[0]->year + $_[0]->month - 1 }, days => sub { ( $_[0]->local_rd_values() )[0] }, weeks => sub { # $_[1] is the "week start day", such as "1mo" use integer; return ( $as_number{days}->( $_[0] ) - $weekdays_any{ $_[1] } ) / 7; }, hours => sub { $as_number{days}->($_[0]) * 24 + $_[0]->hour }, minutes => sub { $as_number{hours}->($_[0]) * 60 + $_[0]->minute }, seconds => sub { $_[0]->local_rd_as_seconds }, years_weekly => sub { # get the internal year number, in 'week' mode # $_[1] is the "week start day", such as "1mo" my $base = $_[0]->clone; $base = $truncate{years_weekly}->( $base, $_[1] ) if $base->month > 11 || $base->month < 2; _add( $base, weeks => 1 ); return $as_number{years}->( $base ); }, months_weekly => sub { # get the internal month number, in 'week' mode # $_[1] is the "week start day", such as "1mo" my $base = $_[0]->clone; $base = $truncate{months_weekly}->( $base, $_[1] ) if $base->day > 20 || $base->day < 7; _add( $base, weeks => 1 ); return $as_number{months}->( $base ); }, ); %truncate = ( # @_ = ( $datetime, $week_start_day ) ( map { my $name = $_; $name =~ s/s$//; $_ => sub { my $tmp = $_[0]->clone; $tmp->truncate( to => $name ) } } qw( years months days hours minutes seconds ) ), weeks => sub { my $base = $_[0]->clone->truncate( to => 'day' ); _add( $base, days => - $_[0]->day_of_week + $weekdays_any{ $_[1] } ); while(1) { return $base if $base <= $_[0]; _add( $base, weeks => -1 ); } }, months_weekly => sub { my $tmp; my $base = $_[0]->clone; _add( $base, days => 7 ); $base->truncate( to => 'month' ); my $val; my $diff; while(1) { $tmp = $base->clone; $val = $weekdays_1{ $_[1] }; if ( $val ) { $diff = $val - $base->day_of_week; $diff += 7 if $diff < 0; } else { $diff = ( $weekdays{ $_[1] } - $base->day_of_week ) % 7; $diff -= 7 if $diff > 3; } _add( $tmp, days => $diff ); return $tmp if $tmp <= $_[0]; _add( $base, months => -1 ); } }, years_weekly => sub { my $tmp; my $base = $_[0]->clone; _add( $base, months => 1 ); $base->truncate( to => 'year' ); my $val; my $diff; # warn "wsd $_[1]\n"; while(1) { $tmp = $base->clone; $val = $weekdays_1{ $_[1] }; if ( $val ) { $diff = $val - $base->day_of_week; $diff += 7 if $diff < 0; } else { $diff = ( $weekdays{ $_[1] } - $base->day_of_week ) % 7; $diff -= 7 if $diff > 3; } _add( $tmp, days => $diff ); return $tmp if $tmp <= $_[0]; _add( $base, years => -1 ); } }, ); %next_unit = ( # @_ = ( $datetime, $week_start_day ) ( map { my $names = $_; $_ => sub { _add( $_[0], $names => 1 ) } } qw( years months weeks days hours minutes seconds ) ), months_weekly => sub { my $base = $_[0]->clone; my $return; while(1) { _add( $base, days => 21 ); $return = $truncate{months_weekly}->( $base, $_[1] ); return $_[0] = $return if $return > $_[0]; } }, years_weekly => sub { my $base = $_[0]->clone; my $return; while(1) { _add( $base, months => 11 ); $return = $truncate{years_weekly}->( $base, $_[1] ); return $_[0] = $return if $return > $_[0]; } }, ); %previous_unit = ( # @_ = ( $datetime, $week_start_day ) months_weekly => sub { my $base = $_[0]->clone; my $return; while(1) { $return = $truncate{months_weekly}->( $base, $_[1] ); return $_[0] = $return if $return < $_[0]; _add( $base, days => -21 ); } }, years_weekly => sub { my $base = $_[0]->clone; my $return; while(1) { $return = $truncate{years_weekly}->( $base, $_[1] ); return $_[0] = $return if $return < $_[0]; _add( $base, months => -11 ); } }, ); # -------- "INTERVAL" OPERATIONS %truncate_interval = ( # @_ = ( $datetime, $args ) ( map { my $names = $_; my $name = $_; $name =~ s/s$//; $_ => sub { my $tmp = $_[0]->clone; $tmp->truncate( to => $name ); _add( $tmp, $names => $_[1]{offset} - ( $as_number{$names}->($_[0]) % $_[1]{interval} ) ); } } qw( years months days hours minutes seconds ) ), weeks => sub { my $tmp = $truncate{weeks}->( $_[0], $_[1]{week_start_day} ); while ( $_[1]{offset} != ( $as_number{weeks}->( $tmp, $_[1]{week_start_day} ) % $_[1]{interval} ) ) { _add( $tmp, weeks => -1 ); } return $tmp; }, months_weekly => sub { my $tmp = $truncate{months_weekly}->( $_[0], $_[1]{week_start_day} ); while ( $_[1]{offset} != ( $as_number{months_weekly}->( $tmp, $_[1]{week_start_day} ) % $_[1]{interval} ) ) { $previous_unit{months_weekly}->( $tmp, $_[1]{week_start_day} ); } return $tmp; }, years_weekly => sub { my $tmp = $truncate{years_weekly}->( $_[0], $_[1]{week_start_day} ); while ( $_[1]{offset} != ( $as_number{years_weekly}->( $tmp, $_[1]{week_start_day} ) % $_[1]{interval} ) ) { $previous_unit{years_weekly}->( $tmp, $_[1]{week_start_day} ); } return $tmp; }, ); %next_unit_interval = ( ( map { my $names = $_; $_ => sub { _add( $_[0], $names => $_[1]{interval} ) } } qw( years months weeks days hours minutes seconds ) ), months_weekly => sub { for ( 1 .. $_[1]{interval} ) { $next_unit{months_weekly}->( $_[0], $_[1]{week_start_day} ); } }, years_weekly => sub { for ( 1 .. $_[1]{interval} ) { $next_unit{years_weekly}->( $_[0], $_[1]{week_start_day} ); } }, ); %previous_unit_interval = ( ( map { my $names = $_; $_ => sub { _add( $_[0], $names => - $_[1]{interval} ) } } qw( years months weeks days hours minutes seconds ) ), months_weekly => sub { for ( 1 .. $_[1]{interval} ) { $previous_unit{months_weekly}->( $_[0], $_[1]{week_start_day} ); } }, years_weekly => sub { for ( 1 .. $_[1]{interval} ) { $previous_unit{years_weekly}->( $_[0], $_[1]{week_start_day} ); } }, ); # -------- CONSTRUCTORS BEGIN { # setup all constructors: daily, ... for ( @units[ 0 .. $#units-1 ] ) { my $name = $_; my $namely = $_; $namely =~ s/ys$/ily/; $namely =~ s/s$/ly/; no strict 'refs'; *{__PACKAGE__ . "::$namely"} = sub { use strict 'refs'; my $class = shift; return _create_recurrence( base => $name, @_ ); }; } } # BEGIN sub _create_recurrence { my %args = @_; # print "ARGS: "; # for(@_){ print (( ref($_) eq "ARRAY" ) ? "[ @$_ ] " : "$_ ") } # print " \n"; # --- FREQUENCY my $base = delete $args{base}; my $namely = $base; $namely =~ s/ys$/ily/; $namely =~ s/s$/ly/; my $ical_string = uc( "RRULE:FREQ=$namely" ); my $base_unit = $base; $base_unit = 'years_weekly' if $base_unit eq 'years' && exists $args{weeks} ; $base_unit = 'months_weekly' if $base_unit eq 'months' && exists $args{weeks} ; # --- WEEK-START-DAY my $week_start_day = delete $args{week_start_day}; $ical_string .= ";WKST=". uc($week_start_day) if $week_start_day; $week_start_day = ( $base eq 'years' ) ? 'mo' : '1mo' unless defined $week_start_day; die "$base: invalid week start day ($week_start_day)" unless $weekdays_any{ $week_start_day }; # --- INTERVAL, START, and OFFSET my $interval = delete $args{interval} || 1; die "invalid 'interval' specification ($interval)" if $interval < 1; $ical_string .= ";INTERVAL=$interval" if $interval > 1; my $start = delete $args{start}; undef $start if defined $start && $start->is_infinite; my $offset = 0; $offset = $as_number{$base_unit}->( $start, $week_start_day ) % $interval if $start && $interval > 1; # --- DURATION LIST # check for invalid "units" arguments, such as "daily( years=> )" my @valid_units; for ( 0 .. $#units ) { if ( $base eq $units[$_] ) { @valid_units = @units[ $_+1 .. $#units ]; last; } } die "can't have both 'months' and 'weeks' arguments" if exists $args{weeks} && exists $args{months}; my $level = 1; my @duration = ( [] ); my @level_unit = ( $base_unit ); for my $unit ( @valid_units ) { next unless exists $args{$unit}; if ( ref( $args{$unit} ) eq 'ARRAY' ) { $args{$unit} = [ @{ $args{$unit} } ] } else { $args{$unit} = [ $args{$unit} ] } # TODO: sort _after_ normalization if ( $unit eq 'days' ) { # map rfc2445 weekdays to numbers @{$args{$unit}} = map { $_ =~ /[a-z]/ ? $weekdays{$_} : $_ } @{$args{$unit}}; } # sort positive values first @{$args{$unit}} = sort { ( $a < 0 ) <=> ( $b < 0 ) || $a <=> $b } @{$args{$unit}}; # make the "ical" string if ( $unit eq 'nanoseconds' ) { # there are no nanoseconds in ICal } elsif ( $base eq 'weeks' && $unit eq 'days' ) { # weekdays have names $ical_string .= uc( ';' . 'BYDAY' . '=' . join(",", map { exists( $ical_days{$_} ) ? $ical_days{$_} : $_ } @{$args{$unit}} ) ) } else { $ical_string .= uc( ';' . $ical_name{$unit} . '=' . join(",", @{$args{$unit}} ) ) } if ( $unit eq 'months' || $unit eq 'weeks' || $unit eq 'days' ) { # these units start in '1' for ( @{$args{$unit}} ) { die $unit . ' cannot be zero' unless $_; $_-- if $_ > 0; } } @{$args{$unit}} = grep { $_ < $limits{ $unit } && $_ >= - $limits{ $unit } } @{$args{$unit}}; if ( $unit eq 'days' && ( $base_unit eq 'months' || $level_unit[-1] eq 'months' ) ) { # month day @{$args{$unit}} = grep { $_ < 31 && $_ >= -31 } @{$args{$unit}}; } if ( $unit eq 'days' && ( $base_unit eq 'weeks' || $level_unit[-1] eq 'weeks' ) ) { # week day @{$args{$unit}} = grep { $_ < 7 && $_ >= -7 } @{$args{$unit}}; for ( @{$args{$unit}} ) { $_ = $_ - $weekdays_any{ $week_start_day } + 1; $_ += 7 while $_ < 0; } @{$args{$unit}} = sort @{$args{$unit}}; } return DateTime::Set::ICal->empty_set unless @{$args{$unit}}; # there are no args left push @duration, $args{$unit}; push @level_unit, $unit; delete $args{$unit}; $level++; } # TODO: use $span for selecting elements (using intersection) # note - this may change the documented behaviour - check the pod first # $span = delete $args{span}; # $span = DateTime::Span->new( %args ) if %args; die "invalid argument '@{[ keys %args ]}'" if keys %args; # --- SPLIT NEGATIVE/POSITIVE DURATIONS my @args; push @args, \@duration; for ( my $i = 0; $i < @args; $i++ ) { my $dur1 = $args[$i]; for ( 1 .. $#{$dur1} ) { my @negatives = grep { $_ < 0 } @{$dur1->[$_]}; my @positives = grep { $_ >= 0 } @{$dur1->[$_]}; if ( @positives && @negatives ) { # split # TODO: check if it really needs splitting my $dur2 = [ @{$args[$i]} ]; $dur2->[$_] = \@negatives; $dur1->[$_] = \@positives; push @args, $dur2; } } } # --- CREATE THE SET my $set; for ( @args ) { my @duration = @$_; my $total_durations = 1; my @total_level; for ( my $i = $#duration; $i > 0; $i-- ) { if ( $i == $#duration ) { $total_level[$i] = 1; } else { $total_level[$i] = $total_level[$i + 1] * ( 1 + $#{ $duration[$i + 1] } ); } $total_durations *= 1 + $#{ $duration[$i] }; } my $args = { truncate_interval => $truncate_interval{ $base_unit }, previous_unit_interval => $previous_unit_interval{ $base_unit }, next_unit_interval => $next_unit_interval{ $base_unit }, duration => \@duration, total_durations => $total_durations, level_unit => \@level_unit, total_level => \@total_level, interval => $interval, offset => $offset, week_start_day => $week_start_day, }; my $tmp = DateTime::Set::ICal->from_recurrence( next => sub { _get_next( $_[0], $args ); }, previous => sub { _get_previous( $_[0], $args ); }, ); $set = defined $set ? $set->union( $tmp ) : $tmp; } $set->set_ical( include => [ $ical_string ] ); # warn "Creating set: ". $ical_string ." \n"; return $set; } # _create_recurrence sub _get_occurrence_by_index { my ( $base, $occurrence, $args ) = @_; # TODO: memoize "occurrences" within an "INTERVAL" ??? RETRY_OVERFLOW: for ( 0 .. 5 ) { return undef if $occurrence < 0; my $next = $base->clone; my $previous = $base; my @values = ( -1 ); for my $j ( 1 .. $#{$args->{duration}} ) { # decode the occurrence-number into a parameter-index my $i = int( $occurrence / $args->{total_level}[$j] ); $occurrence -= $i * $args->{total_level}[$j]; push @values, $i; if ( $args->{duration}[$j][$i] < 0 ) { # warn "negative unit\n"; $next_unit{ $args->{level_unit}[$j - 1] }->( $next, $args->{week_start_day} ); } _add( $next, $args->{level_unit}[$j], $args->{duration}[$j][$i] ); # overflow check if ( $as_number{ $args->{level_unit}[$j - 1] }->( $next, $args->{week_start_day} ) != $as_number{ $args->{level_unit}[$j - 1] }->( $previous, $args->{week_start_day} ) ) { # calculate the "previous" occurrence-number $occurrence = -1; for ( 1 .. $j ) { $occurrence += $values[$_] * $args->{total_level}[$_]; } next RETRY_OVERFLOW; } $previous = $next->clone; } return $next; } return undef; } sub _get_previous { my ( $self, $args ) = @_; return $self if $self->is_infinite; $self->set_time_zone( 'floating' ); my $base = $args->{truncate_interval}->( $self, $args ); my ( $next, $i, $start, $end ); my $init = 0; my $retry = 30; INTERVAL: while(1) { $args->{previous_unit_interval}->( $base, $args ) if $init; $init = 1; # binary search $start = 0; $end = $args->{total_durations} - 1; while ( $retry-- ) { if ( $end - $start < 3 ) { for ( $i = $end; $i >= $start; $i-- ) { $next = _get_occurrence_by_index ( $base, $i, $args ); next INTERVAL unless defined $next; return $next if $next < $self; } next INTERVAL; } $i = int( $start + ( $end - $start ) / 2 ); $next = _get_occurrence_by_index ( $base, $i, $args ); next INTERVAL unless defined $next; if ( $next < $self ) { $start = $i; } else { $end = $i - 1; } } return undef; } } sub _get_next { my ( $self, $args ) = @_; return $self if $self->is_infinite; $self->set_time_zone( 'floating' ); my $base = $args->{truncate_interval}->( $self, $args ); my ( $next, $i, $start, $end ); my $init = 0; my $retry = 30; INTERVAL: while(1) { $args->{next_unit_interval}->( $base, $args ) if $init; $init = 1; # binary search $start = 0; $end = $args->{total_durations} - 1; while ( $retry-- ) { if ( $end - $start < 3 ) { for $i ( $start .. $end ) { $next = _get_occurrence_by_index ( $base, $i, $args ); next INTERVAL unless defined $next; return $next if $next > $self; } next INTERVAL; } $i = int( $start + ( $end - $start ) / 2 ); $next = _get_occurrence_by_index ( $base, $i, $args ); next INTERVAL unless defined $next; if ( $next > $self ) { $end = $i; } else { $start = $i + 1; } } return undef; } } 1; __END__ =head1 NAME DateTime::Event::Recurrence - DateTime::Set extension for create basic recurrence sets =head1 SYNOPSIS use DateTime; use DateTime::Event::Recurrence; my $dt = DateTime->new( year => 2000, month => 6, day => 20, ); my $daily_set = DateTime::Event::Recurrence->daily; my $dt_next = $daily_set->next( $dt ); my $dt_previous = $daily_set->previous( $dt ); my $bool = $daily_set->contains( $dt ); my @days = $daily_set->as_list( start => $dt1, end => $dt2 ); my $iter = $daily_set->iterator; while ( my $dt = $iter->next ) { print ' ', $dt->datetime; } =head1 DESCRIPTION This module provides convenience methods that let you easily create C objects for various recurrences, such as "once a month" or "every day". You can also create more complicated recurrences, such as "every Monday, Wednesday and Thursday at 10:00 AM and 2:00 PM". =head1 USAGE =over 4 =item * yearly monthly weekly daily hourly minutely secondly These methods all return a new C object representing the given recurrence. my $daily_set = DateTime::Event::Recurrence->daily; If no parameters are given, then the set members each occur at the I of the specified recurrence. For example, by default, the C method returns a set containing the first day of each month. Without parameters, the C method returns a set containing I. However, you can pass in parameters to alter where these datetimes fall. The parameters are the same as those given to the C constructor for specifying the length of a duration. For example, to create a set representing a daily recurrence at 10:30 each day, we write this: my $daily_at_10_30_set = DateTime::Event::Recurrence->daily( hours => 10, minutes => 30 ); To represent every I (second day of the week): my $weekly_on_tuesday_set = DateTime::Event::Recurrence->weekly( days => 2 ); A negative duration counts backwards from the end of the period. This is done in the same manner as is specified in RFC 2445 (iCal). Negative durations are useful for creating recurrences such as the I: my $last_day_of_month_set = DateTime::Event::Recurrence->monthly( days => -1 ); You can also provide multiple sets of duration arguments, such as this: my $set = DateTime::Event::Recurrence->daily ( hours => [ 10, 14, -1 ], minutes => [ 15, 30, -15 ], ); This specifies a recurrence occurring every day at these 9 different times: 10:15, 10:30, 10:45, # +10h ( +15min / +30min / last 15min (-15) ) 14:15, 14:30, 14:45, # +14h ( +15min / +30min / last 15min (-15) ) 23:15, 23:30, 23:45, # last 1h (-1) ( +15min / +30min / last 15min (-15) ) To create a set of recurrences occurring every thirty seconds, we could do this: my $every_30_seconds_set = DateTime::Event::Recurrence->minutely( seconds => [ 0, 30 ] ); The following is also valid. See the section on the "interval" parameter: my $every_30_seconds_set = DateTime::Event::Recurrence->secondly( interval => 30 ); =back =head2 Invalid DateTimes Invalid values are skipped at run time. For example, when days are added to a month, the result is checked for a nonexisting day (such as 31 or 30), and the invalid datetimes are skipped. Another example of this would be creating a set via the C method and specifying C<< hours => 25 >>. =head2 The "days" Parameter The "days" parameter can be combined with yearly, monthly, and weekly recurrences, resulting in six possible meanings: # tuesday of every week my $set = DateTime::Event::Recurrence->weekly( days => 2 ); # 10th day of every month my $set = DateTime::Event::Recurrence->monthly( days => 10 ); # second full week of every month, on tuesday my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days => 2 ); # 10th day of every year my $set = DateTime::Event::Recurrence->yearly( days => 10 ); # 10th day of every december my $set = DateTime::Event::Recurrence->yearly( months => 12, days => 10 ); # second week of every year, on tuesday my $set = DateTime::Event::Recurrence->yearly( weeks => 2, days => 2 ); Week days can also be called by name, as is specified in RFC 2445 (iCal): my $weekly_on_tuesday_set = DateTime::Event::Recurrence->weekly( days => 'tu' ); The "days" parameter defaults to "the first day". See also the section on the "week_start_day" parameter. # second full week of every month, on monday my $set = DateTime::Event::Recurrence->monthly( weeks => 2 ); # second tuesday of every month my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days => "tu", week_start_day => "1tu" ); =head2 The "interval" and "start" Parameters The "interval" parameter represents how often the recurrence rule repeats. The optional "start" parameter specifies where to start counting: my $dt_start = DateTime->new( year => 2003, month => 6, day => 15 ); my $set = DateTime::Event::Recurrence->daily ( interval => 11, hours => 10, minutes => 30, start => $dt_start, ); This specifies a recurrence that happens at 10:30 on the day specified by C<< start => $dt >>, and then every 11 days I C<$dt>. So we get a set like this: ... 2003-06-04T10:30:00, 2003-06-15T10:30:00, 2003-06-26T10:30:00, ... In this case, the method is used to specify the unit, so C means that our unit is a day, and C<< interval => 11 >> specifies the quantity of our unit. The "start" parameter should have no time zone. =head2 The "week_start_day" Parameter The C represents how the 'first week' of a period is calculated: "mo", "tu", "we", "th", "fr", "sa", "su" - The first week is one that starts on this week-day, and has I in this period. Works for C and C recurrences. "1mo", "1tu", "1we", "1th", "1fr", "1sa", "1su" - The first week is one that starts on this week-day, and has I in this period. This works for C, C and C recurrences. The C defaults to "1mo", except in yearly (C) recurrences which default to "mo". =head2 Time Zones Recurrences are created in the 'floating' time zone, as specified in the C module. If you want to specify a time zone for a recurrence, you can do this by calling C on the returned set: my $daily = DateTime::Event::Recurrence->daily; $daily->set_time_zone( 'Europe/Berlin' ); You can also pass a C object with a time zone to the set's C and C methods: my $dt = DateTime->today( time_zone => 'Europe/Berlin' ); my $next = $daily->next($dt); A recurrence can be affected DST changes, so it would be possible to specify a recurrence that creates nonexistent datetimes. Because C throws an exception if asked to create a non-existent datetime, please be careful when setting a time zone for your recurrence. It might be preferable to always use "UTC" for your sets, and then convert the returned object to the desired time zone. =head2 Leap Seconds There are no leap seconds, because the recurrences are created in the 'floating' time zone. The value C<60> for seconds (the leap second) is ignored. If you I want the leap second, then specify the second as C<-1>. =head1 AUTHOR Flavio Soibelmann Glock fglock@gmail.com =head1 CREDITS The API was developed with help from the people in the datetime@perl.org list. Special thanks to Dave Rolsky, Ron Hill and Matt Sisk for being around with ideas. If you can understand what this module does by reading the docs, you should thank Dave Rolsky. If you can't understand it, yell at him. He also helped removing weird idioms from the code. Jerrad Pierce came with the idea to move "interval" from DateTime::Event::ICal to here. =head1 COPYRIGHT Copyright (c) 2003 Flavio Soibelmann 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 DateTime Web page at http://datetime.perl.org/ DateTime - date and time :) DateTime::Set - for recurrence-set accessors docs. You can use DateTime::Set to specify recurrences using callback subroutines. DateTime::Event::ICal - if you need more complex recurrences. DateTime::SpanSet - sets of intervals, including recurring sets of intervals. =cut DateTime-Event-Recurrence-0.19/README0000644000175000017500000000033413057610261016466 0ustar fglockfglockOVERVIEW This module aims to support basic recurrences, such as 'daily'. INSTALLATION To install this module type the following in the distribution directory: perl Makefile.PL make make test make install DateTime-Event-Recurrence-0.19/Makefile.PL0000644000175000017500000000210013057610261017551 0ustar fglockfglockuse strict; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'DateTime::Event::Recurrence', VERSION_FROM => 'lib/DateTime/Event/Recurrence.pm', AUTHOR => 'Flavio S. Glock ', ABSTRACT => 'DateTime base recurrences', PREREQ_PM => { 'DateTime' => 0.27, # local_rd_values 'DateTime::Set' => '0.3600', }, META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'https://github.com/fglock/DateTime-Event-Recurrence.git', web => 'https://github.com/fglock/DateTime-Event-Recurrence', }, }, }, );