DateTime-Event-ICal-0.11/000755 000765 000024 00000000000 12046257351 015431 5ustar00fglockstaff000000 000000 DateTime-Event-ICal-0.11/Changes000644 000765 000024 00000002551 12046257034 016725 0ustar00fglockstaff000000 000000 Changes for DateTime-Event-ICal 0.11 2012-11-06 - performance patch, provided by Dario Hamidi 0.10 2009-11-17 - fixed recurrence stringification by DateTime::Format::ICal Reported by Nick Spacek 0.09 2005-09-30 - fixed a warning in BYSETPOS Reported by Mark D. Anderson 0.08 2004-05-24 - requires DateTime::Event::Recurrence 0.11. There was a bug there, that could cause this module to hang. Reported by Bridget Almas 0.07 2004-03-17 0.0601 2004-03-09 - the recurrence functions accept infinite DateTimes, as required by DT::Set 0.1402 0.06 2003-09-04 - recurrence stringification does not depend on hash 'order' 0.05 2003-09-02 - rfc2445.t is compatible with Perl 5.00503 0.04 2003-08-25 - fixed byday + interval - tests are 25% faster due to more efficient monthly-byday algorithm. - bugfix for 'yearly-byday'. Bug reported by John Bishop. - more tests for 'yearly-byday' - rfc2445 test uses a proper 'print' subroutine 0.03 2003-07-03 - change hints for DT::Format::ICal format_recurrence 0.02 2003-07-02 - provides hints for DT::Format::ICal format_recurrence 0.01 2003-05-23 - tests all expressions mentioned in RFC2445 - bysetpos is 2x faster - fixed the order of operations: bysetpos x span 0.00_02 2003-05-12 - bysetpos - count - by(units) 0.00_01 - base implementation: until, interval, dtstart, dtend, until DateTime-Event-ICal-0.11/lib/000755 000765 000024 00000000000 12046257351 016177 5ustar00fglockstaff000000 000000 DateTime-Event-ICal-0.11/LICENSE000644 000765 000024 00000050101 11545402422 016425 0ustar00fglockstaff000000 000000 Terms of Perl itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --------------------------------------------------------------------------- The General Public License (GPL) Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 675 Mass Ave, Cambridge, MA 02139, USA. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS --------------------------------------------------------------------------- The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End DateTime-Event-ICal-0.11/Makefile.PL000644 000765 000024 00000000756 11545402422 017405 0ustar00fglockstaff000000 000000 use strict; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'DateTime::Event::ICal', VERSION_FROM => 'lib/DateTime/Event/ICal.pm', AUTHOR => 'Flavio S. Glock ', ABSTRACT => 'DateTime rfc2445 recurrences', PREREQ_PM => { 'DateTime' => 0, 'DateTime::Event::Recurrence' => 0.11, }, ); DateTime-Event-ICal-0.11/MANIFEST000644 000765 000024 00000000410 11545402422 016547 0ustar00fglockstaff000000 000000 Changes LICENSE MANIFEST This list of files MANIFEST.SKIP Makefile.PL README TODO lib/DateTime/Event/ICal.pm t/00load.t t/01sanity.t t/02interval.t t/03by.t t/04rfc2445.t t/05byday.t META.yml Module meta-data (added by MakeMaker) DateTime-Event-ICal-0.11/MANIFEST.SKIP000644 000765 000024 00000000213 11545402422 017315 0ustar00fglockstaff000000 000000 ^blib/ ^Makefile$ ^Makefile\.[a-z]+$ ^pm_to_blib$ CVS/.* ,v$ ^tmp/ \.old$ \.bak$ ~$ ^# \.shar$ \.tar$ \.tgz$ \.tar\.gz$ \.zip$ _uu$ \.out DateTime-Event-ICal-0.11/META.yml000644 000765 000024 00000001134 12046257351 016701 0ustar00fglockstaff000000 000000 --- #YAML:1.0 name: DateTime-Event-ICal version: 0.11 abstract: DateTime rfc2445 recurrences author: - Flavio S. Glock license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: DateTime: 0 DateTime::Event::Recurrence: 0.11 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 DateTime-Event-ICal-0.11/README000644 000765 000024 00000000364 11545402422 016306 0ustar00fglockstaff000000 000000 OVERVIEW This module aims to support rfc2445 style recurrences, such as 'last friday of march'. INSTALLATION To install this module type the following in the distribution directory: perl Makefile.PL make make test make install DateTime-Event-ICal-0.11/t/000755 000765 000024 00000000000 12046257351 015674 5ustar00fglockstaff000000 000000 DateTime-Event-ICal-0.11/TODO000644 000765 000024 00000002337 11545402422 016120 0ustar00fglockstaff000000 000000 TODO list for Perl module DateTime-Event-ICal * include this in docs: http://www.w3.org/2001/sw/Europe/200210/calendar/vocab_usecases.html http://www.imc.org/ietf-calendar/mail-archive/msg00623.html * optimize yealy/monthly + interval + byday - uses intersection with "all days" * "byday -2 friday" - test overflow - need some 'interval' and 'dtstart' tests * the implementation of 'select' in Set::Infinite is incomplete and doesn't have the 'last' attribute. -- should be implemented! Note: this is not a problem because it is only used in 'count', which generates finite sets. * finish importing Date::Set RFC2445 recurrence tests * bysetpos - use some kind of memoization * byweekno - test with 'daily' * no tests were made defining recurrences without dtstart. * the effect of 'count' on a recurrence without dtstart is not defined. the effect of count == 0 is not defined. * no tests were made using datetimes with timezones. * mixing positive and negative arguments in the same list might give wrong results is the numbers are big enough to cause the datetimes to interleave. - split in two recurrences and join with 'union' * some arguments are not checked for overflow, such as byyearday. DateTime-Event-ICal-0.11/t/00load.t000644 000765 000024 00000000127 11545402422 017132 0ustar00fglockstaff000000 000000 #!/bin/perl -w use Test::More; plan tests => 1; use_ok( 'DateTime::Event::ICal' ); DateTime-Event-ICal-0.11/t/01sanity.t000644 000765 000024 00000005410 11545402422 017523 0ustar00fglockstaff000000 000000 #!/bin/perl -w use strict; use Test::More tests => 6; use DateTime; use DateTime::Event::ICal; { 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' ); my ( $set, @dt, $r ); # DAILY $set = DateTime::Event::ICal->recur( freq => 'daily' ); @dt = $set->as_list( start => $dt1, end => $dt2 ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-29T00:00:00 2003-04-30T00:00:00 2003-05-01T00:00:00', "daily without args" ); # SECONDLY $set = DateTime::Event::ICal->recur( freq => 'secondly' ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( seconds => 2 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-28T12:10:46 2003-04-28T12:10:47', "secondly" ); # MINUTELY $set = DateTime::Event::ICal->recur( freq => 'minutely', dtstart => $dt1 ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( minutes => 2 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-28T12:11:45 2003-04-28T12:12:45', "minutely and dtstart" ); # HOURLY $set = DateTime::Event::ICal->recur( freq => 'hourly', dtstart => $dt1, bysecond => [ 1, 3 ] ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( hours => 2 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-28T13:10:01 2003-04-28T13:10:03 '. '2003-04-28T14:10:01 2003-04-28T14:10:03', "hourly, dtstart, bysecond" ); # MONTHLY $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( months => 2 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-05-28T12:10:45 2003-06-28T12:10:45', "monthly, dtstart" ); # MONTHLY BYMONTHDAY $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, bymonthday => [ 1, 3 ] ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( months => 2 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-05-01T12:10:45 2003-05-03T12:10:45 '. '2003-06-01T12:10:45 2003-06-03T12:10:45', "monthly, dtstart, bymonthday" ); } DateTime-Event-ICal-0.11/t/02interval.t000644 000765 000024 00000002023 11545402422 020036 0ustar00fglockstaff000000 000000 #!/bin/perl -w use strict; use Test::More tests => 1; use DateTime; use DateTime::Event::ICal; { 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' ); my ( $set, @dt, $r ); # MINUTELY $set = DateTime::Event::ICal->recur( freq => 'minutely', dtstart => $dt1, interval => 3, count => 3 ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( minutes => 30 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-28T12:10:45 2003-04-28T12:13:45 2003-04-28T12:16:45', "minutely, dtstart, dtend, interval, count" ); } DateTime-Event-ICal-0.11/t/03by.t000644 000765 000024 00000007502 11545402422 016634 0ustar00fglockstaff000000 000000 #!/bin/perl -w use strict; use Test::More tests => 7; use DateTime; use DateTime::Event::ICal; { my $dt1 = new DateTime( year => 2003, month => 4, day => 28, hour => 12, minute => 10, second => 45, time_zone => 'UTC' ); # $dt1 is monday, week 18 my ( $set, @dt, $r ); # DAILY BYMONTH $set = DateTime::Event::ICal->recur( freq => 'daily', dtstart => $dt1, bymonth => [ 2, 12 ], interval => 10 ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-04T12:10:45 2003-12-14T12:10:45 2003-12-24T12:10:45 '. '2004-02-02T12:10:45 2004-02-12T12:10:45 2004-02-22T12:10:45', "daily, dtstart, interval, bymonth" ); # YEARLY BYMONTH BYMONTHDAY $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, bymonth => [ 2, 12 ], bymonthday => [ 3, 13 ] ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-03T12:10:45 2003-12-13T12:10:45 '. '2004-02-03T12:10:45 2004-02-13T12:10:45', "yearly, dtstart, bymonthday, bymonth" ); # YEARLY BYWEEKNO $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, byweekno => [ 2, 12 ], ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2004-01-05T12:10:45 2004-03-15T12:10:45', "yearly, dtstart, byweekno" ); # CHANGE DTSTART WEEKDAY $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1->clone->add( days => 1 ), byweekno => [ 2, 12 ], ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2004-01-06T12:10:45 2004-03-16T12:10:45', "yearly, dtstart, byweekno" ); # YEARLY BYDAY=1FR $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, byday => [ '1fr', '2fr', '-1tu' ], ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-30T12:10:45 2004-01-02T12:10:45 2004-01-09T12:10:45', "yearly, dtstart, byday=1fr,2fr,-1tu" ); # YEARLY BYDAY=1FR HOUR $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, byday => [ '1fr', '2fr', '-1tu' ], byhour => [ 10, 14 ], ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( years => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-12-30T10:10:45 2003-12-30T14:10:45 '. '2004-01-02T10:10:45 2004-01-02T14:10:45 '. '2004-01-09T10:10:45 2004-01-09T14:10:45', "yearly, dtstart, byday=1fr,2fr,-1tu, byhour" ); # MONTHLY BYSETPOS $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, bymonthday => [ -1, -2, -3, -4, -5, -6 ], bysetpos => [ 3, -2 ], ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( months => 3 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2003-04-29T12:10:45 '. '2003-05-28T12:10:45 '. '2003-05-30T12:10:45 2003-06-27T12:10:45 2003-06-29T12:10:45 '. '2003-07-28T12:10:45', "monthly, bymonthday, bysetpos" ); } DateTime-Event-ICal-0.11/t/04rfc2445.t000644 000765 000024 00000143302 11545402422 017313 0ustar00fglockstaff000000 000000 #!/bin/perl -w # 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. # # modified from Date::Set tests # use strict; # use warnings; use Test::More tests => 42; use DateTime::Span; BEGIN { use_ok('DateTime::Event::ICal') }; sub str { my $iter = $_[0]->iterator; my @result; while ( my $dt = $iter->next ) { push @result, $dt->datetime if ref( $dt ); }; return join( ',', @result ); } my ($title, $a, $a2, $b, $period, $RFC); # DATES my $dt19950101 = DateTime->new( year => 1995 ); my $dt19961105T090000 = DateTime->new( year => 1996, month => 11, day => 05, hour => 9, # time_zone => 'US-Eastern', ); my $dt19990101 = DateTime->new( year => 1999 ); my $dt19970101T090000 = DateTime->new( year => 1997, month => 1, day => 1, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970310T090000 = DateTime->new( year => 1997, month => 3, day => 10, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970610T090000 = DateTime->new( year => 1997, month => 6, day => 10, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970805T090000 = DateTime->new( year => 1997, month => 8, day => 5, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970902T090000 = DateTime->new( year => 1997, month => 9, day => 2, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970904T090000 = $dt19970902T090000->clone->add( days => 2 ); my $dt19970905T090000 = DateTime->new( year => 1997, month => 9, day => 5, hour => 9, # time_zone => 'US-Eastern', ); my $dt19970902T170000 = DateTime->new( year => 1997, month => 9, day => 2, hour => 17, # time_zone => 'US-Eastern', ); my $dt19971007T000000= DateTime->new( year => 1997, month => 10, day => 7, # time_zone => 'US-Eastern', ); my $dt19971224T000000 = DateTime->new( year => 1997, month => 12, day => 24, # time_zone => 'US-Eastern', ); my $dt19980101T090000 = DateTime->new( year => 1998, month => 1, day => 1, hour => 9, # time_zone => 'US-Eastern', ); my $dt19980201T000000 = DateTime->new( year => 1998, month => 2, day => 1, # time_zone => 'US-Eastern', ); my $dt20000131T090000 = DateTime->new( year => 2000, month => 1, day => 31, hour => 9, # time_zone => 'US-Eastern', ); # PERIODS my $period_1995_19970904T090000 = DateTime::Span->new( start => $dt19950101, end => $dt19970904T090000 ); my $period_1995_1999 = DateTime::Span->new( start => $dt19950101, end => $dt19990101 ); my $period_1995_1998 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->subtract( years => 1 ) ); my $period_1995_19980201 = DateTime::Span->new( start => $dt19950101, end => $dt19980201T000000 ); my $period_1995_19980301 = DateTime::Span->new( start => $dt19950101, end => $dt19980201T000000->clone->add( months => 1 ) ); my $period_1995_19980401 = DateTime::Span->new( start => $dt19950101, end => $dt19980201T000000->clone->add( months => 2 ) ); my $period_1995_2000 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->add( years => 1 ) ); my $period_1995_2001 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->add( years => 2 ) ); my $period_1995_2004 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->add( years => 5 ) ); my $period_1995_2005 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->add( years => 6 ) ); my $period_1995_2007 = DateTime::Span->new( start => $dt19950101, end => $dt19990101->clone->add( years => 8 ) ); # TESTS $title="*** Daily for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=DAILY;COUNT=10 # # ==> (1997 9:00 AM EDT)September 2-11 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'daily', count => 10 ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-03T09:00:00,' . '1997-09-04T09:00:00,1997-09-05T09:00:00,' . '1997-09-06T09:00:00,1997-09-07T09:00:00,' . '1997-09-08T09:00:00,1997-09-09T09:00:00,' . '1997-09-10T09:00:00,1997-09-11T09:00:00', $title); $title="*** Daily until December 24, 1997 ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=DAILY;UNTIL=1997-12-24T00:00:00 # # ==> (1997 9:00 AM EDT)September 2-30;October 1-25 # (1997 9:00 AM EST)October 26-31;November 1-30;December 1-23 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'daily', until => $dt19971224T000000 ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-03T09:00:00,' . '1997-09-04T09:00:00,1997-09-05T09:00:00,' . '1997-09-06T09:00:00,1997-09-07T09:00:00,' . '1997-09-08T09:00:00,1997-09-09T09:00:00,' . '1997-09-10T09:00:00,1997-09-11T09:00:00,' . '1997-09-12T09:00:00,1997-09-13T09:00:00,' . '1997-09-14T09:00:00,1997-09-15T09:00:00,' . '1997-09-16T09:00:00,1997-09-17T09:00:00,' . '1997-09-18T09:00:00,1997-09-19T09:00:00,' . '1997-09-20T09:00:00,1997-09-21T09:00:00,' . '1997-09-22T09:00:00,1997-09-23T09:00:00,' . '1997-09-24T09:00:00,1997-09-25T09:00:00,' . '1997-09-26T09:00:00,1997-09-27T09:00:00,' . '1997-09-28T09:00:00,1997-09-29T09:00:00,' . '1997-09-30T09:00:00,1997-10-01T09:00:00,' . '1997-10-02T09:00:00,1997-10-03T09:00:00,' . '1997-10-04T09:00:00,1997-10-05T09:00:00,' . '1997-10-06T09:00:00,1997-10-07T09:00:00,' . '1997-10-08T09:00:00,1997-10-09T09:00:00,' . '1997-10-10T09:00:00,1997-10-11T09:00:00,' . '1997-10-12T09:00:00,1997-10-13T09:00:00,' . '1997-10-14T09:00:00,1997-10-15T09:00:00,' . '1997-10-16T09:00:00,1997-10-17T09:00:00,' . '1997-10-18T09:00:00,1997-10-19T09:00:00,' . '1997-10-20T09:00:00,1997-10-21T09:00:00,' . '1997-10-22T09:00:00,1997-10-23T09:00:00,' . '1997-10-24T09:00:00,1997-10-25T09:00:00,' . '1997-10-26T09:00:00,1997-10-27T09:00:00,' . '1997-10-28T09:00:00,1997-10-29T09:00:00,' . '1997-10-30T09:00:00,1997-10-31T09:00:00,' . '1997-11-01T09:00:00,1997-11-02T09:00:00,' . '1997-11-03T09:00:00,1997-11-04T09:00:00,' . '1997-11-05T09:00:00,1997-11-06T09:00:00,' . '1997-11-07T09:00:00,1997-11-08T09:00:00,' . '1997-11-09T09:00:00,1997-11-10T09:00:00,' . '1997-11-11T09:00:00,1997-11-12T09:00:00,' . '1997-11-13T09:00:00,1997-11-14T09:00:00,' . '1997-11-15T09:00:00,1997-11-16T09:00:00,' . '1997-11-17T09:00:00,1997-11-18T09:00:00,' . '1997-11-19T09:00:00,1997-11-20T09:00:00,' . '1997-11-21T09:00:00,1997-11-22T09:00:00,' . '1997-11-23T09:00:00,1997-11-24T09:00:00,' . '1997-11-25T09:00:00,1997-11-26T09:00:00,' . '1997-11-27T09:00:00,1997-11-28T09:00:00,' . '1997-11-29T09:00:00,1997-11-30T09:00:00,' . '1997-12-01T09:00:00,1997-12-02T09:00:00,' . '1997-12-03T09:00:00,1997-12-04T09:00:00,' . '1997-12-05T09:00:00,1997-12-06T09:00:00,' . '1997-12-07T09:00:00,1997-12-08T09:00:00,' . '1997-12-09T09:00:00,1997-12-10T09:00:00,' . '1997-12-11T09:00:00,1997-12-12T09:00:00,' . '1997-12-13T09:00:00,1997-12-14T09:00:00,' . '1997-12-15T09:00:00,1997-12-16T09:00:00,' . '1997-12-17T09:00:00,1997-12-18T09:00:00,' . '1997-12-19T09:00:00,1997-12-20T09:00:00,' . '1997-12-21T09:00:00,1997-12-22T09:00:00,' . '1997-12-23T09:00:00' , $title); $title="*** Every other day - forever ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=DAILY;INTERVAL=2 # ==> (1997 9:00 AM EDT)September2,4,6,8...24,26,28,30; # October 2,4,6...20,22,24 # (1997 9:00 AM EST)October 26,28,30;November 1,3,5,7...25,27,29; # Dec 1,3,... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'daily', interval => 2 ) ->intersection( $period_1995_1998 ); is("". str($a), '1997-09-02T09:00:00,1997-09-04T09:00:00,' . '1997-09-06T09:00:00,1997-09-08T09:00:00,1997-09-10T09:00:00,' . '1997-09-12T09:00:00,1997-09-14T09:00:00,1997-09-16T09:00:00,' . '1997-09-18T09:00:00,1997-09-20T09:00:00,1997-09-22T09:00:00,' . '1997-09-24T09:00:00,1997-09-26T09:00:00,1997-09-28T09:00:00,' . '1997-09-30T09:00:00,1997-10-02T09:00:00,1997-10-04T09:00:00,' . '1997-10-06T09:00:00,1997-10-08T09:00:00,1997-10-10T09:00:00,' . '1997-10-12T09:00:00,1997-10-14T09:00:00,1997-10-16T09:00:00,' . '1997-10-18T09:00:00,1997-10-20T09:00:00,1997-10-22T09:00:00,' . '1997-10-24T09:00:00,1997-10-26T09:00:00,1997-10-28T09:00:00,' . '1997-10-30T09:00:00,1997-11-01T09:00:00,1997-11-03T09:00:00,' . '1997-11-05T09:00:00,1997-11-07T09:00:00,1997-11-09T09:00:00,' . '1997-11-11T09:00:00,1997-11-13T09:00:00,1997-11-15T09:00:00,' . '1997-11-17T09:00:00,1997-11-19T09:00:00,1997-11-21T09:00:00,' . '1997-11-23T09:00:00,1997-11-25T09:00:00,1997-11-27T09:00:00,' . '1997-11-29T09:00:00,1997-12-01T09:00:00,1997-12-03T09:00:00,' . '1997-12-05T09:00:00,1997-12-07T09:00:00,1997-12-09T09:00:00,' . '1997-12-11T09:00:00,1997-12-13T09:00:00,1997-12-15T09:00:00,' . '1997-12-17T09:00:00,1997-12-19T09:00:00,1997-12-21T09:00:00,' . '1997-12-23T09:00:00,1997-12-25T09:00:00,1997-12-27T09:00:00,' . '1997-12-29T09:00:00,1997-12-31T09:00:00', $title); $title="*** Every 10 days, 5 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=DAILY;INTERVAL=10;COUNT=5 # # ==> (1997 9:00 AM EDT)September 2,12,22;October 2,12 # # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'daily', interval => 10, count => 5 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-12T09:00:00,1997-09-22T09:00:00,' . '1997-10-02T09:00:00,1997-10-12T09:00:00', $title); $title="*** Everyday in January, for 3 years ***"; # # DTSTART;TZID=US-Eastern:19980101T090000 # recur_by_rule:FREQ=YEARLY;UNTIL=2000-01-31T09:00:00; # BYMONTH=1;BYDAY=SU,MO,TU,WE,TH,FR,SA # or # recur_by_rule:FREQ=DAILY;UNTIL=2000-01-31T09:00:00;BYMONTH=1 # # ==> (1998 9:00 AM EDT)January 1-31 # (1999 9:00 AM EDT)January 1-31 # (2000 9:00 AM EDT)January 1-31 # # FIRST FORM $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'yearly', until => $dt20000131T090000, bymonth => [ 1 ], byday => [ qw( su mo tu we th fr sa ) ] ) ->intersection( $period_1995_2001 ); is("".str($a), '1998-01-01T09:00:00,1998-01-02T09:00:00,' . '1998-01-03T09:00:00,1998-01-04T09:00:00,1998-01-05T09:00:00,' . '1998-01-06T09:00:00,1998-01-07T09:00:00,1998-01-08T09:00:00,' . '1998-01-09T09:00:00,1998-01-10T09:00:00,1998-01-11T09:00:00,' . '1998-01-12T09:00:00,1998-01-13T09:00:00,1998-01-14T09:00:00,' . '1998-01-15T09:00:00,1998-01-16T09:00:00,1998-01-17T09:00:00,' . '1998-01-18T09:00:00,1998-01-19T09:00:00,1998-01-20T09:00:00,' . '1998-01-21T09:00:00,1998-01-22T09:00:00,1998-01-23T09:00:00,' . '1998-01-24T09:00:00,1998-01-25T09:00:00,1998-01-26T09:00:00,' . '1998-01-27T09:00:00,1998-01-28T09:00:00,1998-01-29T09:00:00,' . '1998-01-30T09:00:00,1998-01-31T09:00:00,' . '1999-01-01T09:00:00,1999-01-02T09:00:00,' . '1999-01-03T09:00:00,1999-01-04T09:00:00,1999-01-05T09:00:00,' . '1999-01-06T09:00:00,1999-01-07T09:00:00,1999-01-08T09:00:00,' . '1999-01-09T09:00:00,1999-01-10T09:00:00,1999-01-11T09:00:00,' . '1999-01-12T09:00:00,1999-01-13T09:00:00,1999-01-14T09:00:00,' . '1999-01-15T09:00:00,1999-01-16T09:00:00,1999-01-17T09:00:00,' . '1999-01-18T09:00:00,1999-01-19T09:00:00,1999-01-20T09:00:00,' . '1999-01-21T09:00:00,1999-01-22T09:00:00,1999-01-23T09:00:00,' . '1999-01-24T09:00:00,1999-01-25T09:00:00,1999-01-26T09:00:00,' . '1999-01-27T09:00:00,1999-01-28T09:00:00,1999-01-29T09:00:00,' . '1999-01-30T09:00:00,1999-01-31T09:00:00,' . '2000-01-01T09:00:00,2000-01-02T09:00:00,' . '2000-01-03T09:00:00,2000-01-04T09:00:00,2000-01-05T09:00:00,' . '2000-01-06T09:00:00,2000-01-07T09:00:00,2000-01-08T09:00:00,' . '2000-01-09T09:00:00,2000-01-10T09:00:00,2000-01-11T09:00:00,' . '2000-01-12T09:00:00,2000-01-13T09:00:00,2000-01-14T09:00:00,' . '2000-01-15T09:00:00,2000-01-16T09:00:00,2000-01-17T09:00:00,' . '2000-01-18T09:00:00,2000-01-19T09:00:00,2000-01-20T09:00:00,' . '2000-01-21T09:00:00,2000-01-22T09:00:00,2000-01-23T09:00:00,' . '2000-01-24T09:00:00,2000-01-25T09:00:00,2000-01-26T09:00:00,' . '2000-01-27T09:00:00,2000-01-28T09:00:00,2000-01-29T09:00:00,' . '2000-01-30T09:00:00,2000-01-31T09:00:00', $title); # SECOND FORM $a = DateTime::Event::ICal->recur( dtstart => $dt19980101T090000 , freq => 'daily', until => $dt20000131T090000, bymonth => [ 1 ], ) ->intersection( $period_1995_2001 ); is("".str($a), '1998-01-01T09:00:00,1998-01-02T09:00:00,' . '1998-01-03T09:00:00,1998-01-04T09:00:00,1998-01-05T09:00:00,' . '1998-01-06T09:00:00,1998-01-07T09:00:00,1998-01-08T09:00:00,' . '1998-01-09T09:00:00,1998-01-10T09:00:00,1998-01-11T09:00:00,' . '1998-01-12T09:00:00,1998-01-13T09:00:00,1998-01-14T09:00:00,' . '1998-01-15T09:00:00,1998-01-16T09:00:00,1998-01-17T09:00:00,' . '1998-01-18T09:00:00,1998-01-19T09:00:00,1998-01-20T09:00:00,' . '1998-01-21T09:00:00,1998-01-22T09:00:00,1998-01-23T09:00:00,' . '1998-01-24T09:00:00,1998-01-25T09:00:00,1998-01-26T09:00:00,' . '1998-01-27T09:00:00,1998-01-28T09:00:00,1998-01-29T09:00:00,' . '1998-01-30T09:00:00,1998-01-31T09:00:00,' . '1999-01-01T09:00:00,1999-01-02T09:00:00,' . '1999-01-03T09:00:00,1999-01-04T09:00:00,1999-01-05T09:00:00,' . '1999-01-06T09:00:00,1999-01-07T09:00:00,1999-01-08T09:00:00,' . '1999-01-09T09:00:00,1999-01-10T09:00:00,1999-01-11T09:00:00,' . '1999-01-12T09:00:00,1999-01-13T09:00:00,1999-01-14T09:00:00,' . '1999-01-15T09:00:00,1999-01-16T09:00:00,1999-01-17T09:00:00,' . '1999-01-18T09:00:00,1999-01-19T09:00:00,1999-01-20T09:00:00,' . '1999-01-21T09:00:00,1999-01-22T09:00:00,1999-01-23T09:00:00,' . '1999-01-24T09:00:00,1999-01-25T09:00:00,1999-01-26T09:00:00,' . '1999-01-27T09:00:00,1999-01-28T09:00:00,1999-01-29T09:00:00,' . '1999-01-30T09:00:00,1999-01-31T09:00:00,' . '2000-01-01T09:00:00,2000-01-02T09:00:00,' . '2000-01-03T09:00:00,2000-01-04T09:00:00,2000-01-05T09:00:00,' . '2000-01-06T09:00:00,2000-01-07T09:00:00,2000-01-08T09:00:00,' . '2000-01-09T09:00:00,2000-01-10T09:00:00,2000-01-11T09:00:00,' . '2000-01-12T09:00:00,2000-01-13T09:00:00,2000-01-14T09:00:00,' . '2000-01-15T09:00:00,2000-01-16T09:00:00,2000-01-17T09:00:00,' . '2000-01-18T09:00:00,2000-01-19T09:00:00,2000-01-20T09:00:00,' . '2000-01-21T09:00:00,2000-01-22T09:00:00,2000-01-23T09:00:00,' . '2000-01-24T09:00:00,2000-01-25T09:00:00,2000-01-26T09:00:00,' . '2000-01-27T09:00:00,2000-01-28T09:00:00,2000-01-29T09:00:00,' . '2000-01-30T09:00:00,2000-01-31T09:00:00', $title); $title="*** Weekly for 10 occurrence ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;COUNT=10 # # ==> (1997 9:00 AM EDT)September 2,9,16,23,30;October 7,14,21 # (1997 9:00 AM EST)October 28;November 4 # # 'FREQ=WEEKLY' MEANS THAT 'DTSTART' SPECIFIES DAY-OF-WEEK (=tuesday) $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'weekly', count => 10, ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-09T09:00:00,' . '1997-09-16T09:00:00,1997-09-23T09:00:00,1997-09-30T09:00:00,' . '1997-10-07T09:00:00,1997-10-14T09:00:00,1997-10-21T09:00:00,' . '1997-10-28T09:00:00,1997-11-04T09:00:00', $title); $title="*** Weekly until December 24, 1997 ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;UNTIL=1997-12-24T00:00:00 # # ==> (1997 9:00 AM EDT)September 2,9,16,23,30;October 7,14,21 # (1997 9:00 AM EST)October 28;November 4,11,18,25; # December 2,9,16,23 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'weekly', until => $dt19971224T000000, ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-09T09:00:00,' . '1997-09-16T09:00:00,1997-09-23T09:00:00,1997-09-30T09:00:00,' . '1997-10-07T09:00:00,1997-10-14T09:00:00,1997-10-21T09:00:00,' . '1997-10-28T09:00:00,' . '1997-11-04T09:00:00,1997-11-11T09:00:00,' . '1997-11-18T09:00:00,1997-11-25T09:00:00,' . '1997-12-02T09:00:00,1997-12-09T09:00:00,' . '1997-12-16T09:00:00,1997-12-23T09:00:00', $title); $title="*** Every other week - forever ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;INTERVAL=2;WKST=SU # # ==> (1997 9:00 AM EDT)September 2,16,30;October 14 # (1997 9:00 AM EST)October 28;November 11,25;December 9,23 # (1998 9:00 AM EST)January 6,20;February # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'weekly', interval => 2, wkst => 'su', ) ->intersection( $period_1995_19980201 ); is("". str($a), '1997-09-02T09:00:00,1997-09-16T09:00:00,1997-09-30T09:00:00,' . '1997-10-14T09:00:00,' . '1997-10-28T09:00:00,' . '1997-11-11T09:00:00,1997-11-25T09:00:00,' . '1997-12-09T09:00:00,1997-12-23T09:00:00,' . '1998-01-06T09:00:00,1998-01-20T09:00:00', $title); #### TEST 11 ########## $title="*** Weekly on Tuesday and Thursday for 5 weeks ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;UNTIL=1997-10-07T00:00:00;WKST=SU;BYDAY=TU,TH # or # # recur_by_rule:FREQ=WEEKLY;COUNT=10;WKST=SU;BYDAY=TU,TH # # ==> (1997 9:00 AM EDT)September 2,4,9,11,16,18,23,25,30;October 2 # # FIRST $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'weekly', until => $dt19971007T000000, wkst => 'su', byday => [ 'tu', 'th' ], ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-04T09:00:00,' . '1997-09-09T09:00:00,1997-09-11T09:00:00,1997-09-16T09:00:00,' . '1997-09-18T09:00:00,1997-09-23T09:00:00,1997-09-25T09:00:00,' . '1997-09-30T09:00:00,1997-10-02T09:00:00', $title); # SECOND $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'weekly', count => 10, wkst => 'su', byday => [ 'tu', 'th' ], ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-04T09:00:00,' . '1997-09-09T09:00:00,1997-09-11T09:00:00,1997-09-16T09:00:00,' . '1997-09-18T09:00:00,1997-09-23T09:00:00,1997-09-25T09:00:00,' . '1997-09-30T09:00:00,1997-10-02T09:00:00', $title); $title="*** Every other week on Monday, Wednesday and Friday until December 24 ***"; # 1997, but starting on Tuesday, September 2, 1997: # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;INTERVAL=2;UNTIL=1997-12-24T00:00:00;WKST=SU; # BYDAY=MO,WE,FR # ==> (1997 9:00 AM EDT)September 2,3,5,15,17,19,29;October # 1,3,13,15,17 # (1997 9:00 AM EST)October 27,29,31;November 10,12,14,24,26,28; # December 8,10,12,22 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'weekly', interval => 2, until => $dt19971224T000000, wkst => 'su', byday => [ 'mo', 'we', 'fr' ], ) ->union( $dt19970902T090000 ) ->intersection( $period_1995_1999 ); is("". str($a), '1997-09-02T09:00:00,1997-09-03T09:00:00,' . '1997-09-05T09:00:00,1997-09-15T09:00:00,1997-09-17T09:00:00,' . '1997-09-19T09:00:00,1997-09-29T09:00:00,' . '1997-10-01T09:00:00,1997-10-03T09:00:00,' . '1997-10-13T09:00:00,1997-10-15T09:00:00,1997-10-17T09:00:00,' . '1997-10-27T09:00:00,1997-10-29T09:00:00,1997-10-31T09:00:00,' . '1997-11-10T09:00:00,1997-11-12T09:00:00,' . '1997-11-14T09:00:00,1997-11-24T09:00:00,1997-11-26T09:00:00,' . '1997-11-28T09:00:00,1997-12-08T09:00:00,1997-12-10T09:00:00,' . '1997-12-12T09:00:00,1997-12-22T09:00:00', $title); ######## TEST 14 $title="*** Every other week on Tuesday and Thursday, for 8 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=WEEKLY;INTERVAL=2;COUNT=8;WKST=SU;BYDAY=TU,TH # # ==> (1997 9:00 AM EDT)September 2,4,16,18,30;October 2,14,16 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'weekly', interval => 2, count => 8, wkst => 'su', byday => [ 'tu', 'th' ], ) ->union( $dt19970902T090000 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-04T09:00:00,' . '1997-09-16T09:00:00,1997-09-18T09:00:00,1997-09-30T09:00:00,' . '1997-10-02T09:00:00,1997-10-14T09:00:00,1997-10-16T09:00:00', $title); #### TEST 15 $title="*** Monthly on the 1st Friday for ten occurrences ***"; # # DTSTART;TZID=US-Eastern:19970905T090000 # recur_by_rule:FREQ=MONTHLY;COUNT=10;BYDAY=1FR # # ==> (1997 9:00 AM EDT)September 5;October 3 # (1997 9:00 AM EST)November 7;Dec 5 # (1998 9:00 AM EST)January 2;February 6;March 6;April 3 # (1998 9:00 AM EDT)May 1;June 5 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', count => 10, byday => [ '1fr' ], ) ->union( $dt19970905T090000 ) ->intersection( $period_1995_1999 ); is("".str($a), '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,' . '1998-06-05T09:00:00', $title); $title="*** Monthly on the 1st Friday until December 24, 1997 ***"; # # DTSTART;TZID=US-Eastern:19970905T090000 # recur_by_rule:FREQ=MONTHLY;UNTIL=1997-12-24T00:00:00;BYDAY=1FR # # ==> (1997 9:00 AM EDT)September 5;October 3 # (1997 9:00 AM EST)November 7;December 5 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', until => $dt19971224T000000, byday => [ '1fr' ], ) ->union( $dt19970905T090000 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-05T09:00:00,' . '1997-10-03T09:00:00,' . '1997-11-07T09:00:00,' . '1997-12-05T09:00:00', $title); $title="*** Every other month on the 1st and last Sunday of the month for 1 ***"; # occurrences: # # DTSTART;TZID=US-Eastern:19970907T090000 # recur_by_rule:FREQ=MONTHLY;INTERVAL=2;COUNT=10;BYDAY=1SU,-1SU # # ==> (1997 9:00 AM EDT)September 7,28 # (1997 9:00 AM EST)November 2,30 # # (1998 9:00 AM EST)January 4,25;March 1,29 # (1998 9:00 AM EDT)May 3,31 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', interval => 2, count => 10, byday => [ '1su', '-1su' ], ) # ->union( $dt19970905T090000 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-07T09:00:00,1997-09-28T09:00:00,' . '1997-11-02T09:00:00,1997-11-30T09:00:00,' . '1998-01-04T09:00:00,1998-01-25T09:00:00,' . '1998-03-01T09:00:00,1998-03-29T09:00:00,' . '1998-05-03T09:00:00,1998-05-31T09:00:00' , $title); $title="*** Monthly on the second to last Monday of the month for 6 months ***"; # # DTSTART;TZID=US-Eastern:19970922T090000 # recur_by_rule:FREQ=MONTHLY;COUNT=6;BYDAY=-2MO # # ==> (1997 9:00 AM EDT)September 22;October 20 # (1997 9:00 AM EST)November 17;December 22 # (1998 9:00 AM EST)January 19;February 16 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', count => 6, byday => [ '-2mo' ], ) # ->union( $dt19970905T090000 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-22T09:00:00,1997-10-20T09:00:00,' . '1997-11-17T09:00:00,1997-12-22T09:00:00,' . '1998-01-19T09:00:00,1998-02-16T09:00:00', $title); $title="*** Monthly on the third to the last day of the month, forever ***"; # # DTSTART;TZID=US-Eastern:19970928T090000 # recur_by_rule:FREQ=MONTHLY;BYMONTHDAY=-3 # # ==> (1997 9:00 AM EDT)September 28 # (1997 9:00 AM EST)October 29;November 28;December 29 # (1998 9:00 AM EST)January 29;February 26 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', bymonthday => [ -3 ], ) ->intersection( $period_1995_19980301 ); is("".str($a), '1997-09-28T09:00:00,' . '1997-10-29T09:00:00,1997-11-28T09:00:00,1997-12-29T09:00:00,' . '1998-01-29T09:00:00,1998-02-26T09:00:00', $title); $title="*** Monthly on the 2nd and 15th of the month for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=2,15 # # ==> (1997 9:00 AM EDT)September 2,15;October 2,15 # (1997 9:00 AM EST)November 2,15;December 2,15 # (1998 9:00 AM EST)January 2,15 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'monthly', count => 10, bymonthday => [ 2, 15 ], ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-15T09:00:00,' . '1997-10-02T09:00:00,1997-10-15T09:00:00,' . '1997-11-02T09:00:00,1997-11-15T09:00:00,' . '1997-12-02T09:00:00,1997-12-15T09:00:00,' . '1998-01-02T09:00:00,1998-01-15T09:00:00', $title); $title="*** Monthly on the first and last day of the month for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970930T090000 # recur_by_rule:FREQ=MONTHLY;COUNT=10;BYMONTHDAY=1,-1 # # ==> (1997 9:00 AM EDT)September 30;October 1 # (1997 9:00 AM EST)October 31;November 1,30;December 1,31 # (1998 9:00 AM EST)January 1,31;February 1 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', count => 10, bymonthday => [ 1, -1 ], ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-30T09:00:00,1997-10-01T09:00:00,' . '1997-10-31T09:00:00,1997-11-01T09:00:00,1997-11-30T09:00:00,' . '1997-12-01T09:00:00,1997-12-31T09:00:00,' . '1998-01-01T09:00:00,1998-01-31T09:00:00,' . '1998-02-01T09:00:00', $title); $title="*** Every 18 months on the 10th thru 15th of the month for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970910T090000 # recur_by_rule:FREQ=MONTHLY;INTERVAL=18;COUNT=10;BYMONTHDAY=10,11,12,13,14,15 # # ==> (1997 9:00 AM EDT)September 10,11,12,13,14,15 # (1999 9:00 AM EST)March 10,11,12,13 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970905T090000, freq => 'monthly', interval => 18, count => 10, bymonthday => [ 10 .. 15 ], ) ->intersection( $period_1995_2000 ); is("".str($a), '1997-09-10T09:00:00,1997-09-11T09:00:00,' . '1997-09-12T09:00:00,1997-09-13T09:00:00,' . '1997-09-14T09:00:00,1997-09-15T09:00:00,' . '1999-03-10T09:00:00,1999-03-11T09:00:00,' . '1999-03-12T09:00:00,1999-03-13T09:00:00' , $title); $title="*** Every Tuesday, every other month ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=MONTHLY;INTERVAL=2;BYDAY=TU # # ==> (1997 9:00 AM EDT)September 2,9,16,23,30 # (1997 9:00 AM EST)November 4,11,18,25 # (1998 9:00 AM EST)January 6,13,20,27;March 3,10,17,24,31 # ... $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000, freq => 'monthly', interval => 2, byday => [ 'tu' ], ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-09T09:00:00,' . '1997-09-16T09:00:00,1997-09-23T09:00:00,1997-09-30T09:00:00,' . '1997-11-04T09:00:00,1997-11-11T09:00:00,' . '1997-11-18T09:00:00,1997-11-25T09:00:00,' . '1998-01-06T09:00:00,1998-01-13T09:00:00,' . '1998-01-20T09:00:00,1998-01-27T09:00:00,' . '1998-03-03T09:00:00,1998-03-10T09:00:00,' . '1998-03-17T09:00:00,1998-03-24T09:00:00,1998-03-31T09:00:00,' . '1998-05-05T09:00:00,1998-05-12T09:00:00,' . '1998-05-19T09:00:00,1998-05-26T09:00:00,1998-07-07T09:00:00,' . '1998-07-14T09:00:00,1998-07-21T09:00:00,1998-07-28T09:00:00,' . '1998-09-01T09:00:00,1998-09-08T09:00:00,1998-09-15T09:00:00,' . '1998-09-22T09:00:00,1998-09-29T09:00:00,1998-11-03T09:00:00,' . '1998-11-10T09:00:00,1998-11-17T09:00:00,1998-11-24T09:00:00' , $title); $title="*** Yearly in June and July for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970610T090000 # recur_by_rule:FREQ=YEARLY;COUNT=10;BYMONTH=6,7 # ==> (1997 9:00 AM EDT)June 10;July 10 # (1998 9:00 AM EDT)June 10;July 10 # (1999 9:00 AM EDT)June 10;July 10 # (2000 9:00 AM EDT)June 10;July 10 # (2001 9:00 AM EDT)June 10;July 10 # Note: Since none of the BYDAY, BYMONTHDAY or BYYEARDAY components # are specified, the day is gotten from DTSTART # $a = DateTime::Event::ICal->recur( dtstart => $dt19970610T090000, freq => 'yearly', count => 10, bymonth => [ 6, 7 ], ) ->intersection( $period_1995_2005 ); is("".str($a), '1997-06-10T09:00:00,1997-07-10T09:00:00,' . '1998-06-10T09:00:00,1998-07-10T09:00:00,' . '1999-06-10T09:00:00,1999-07-10T09:00:00,' . '2000-06-10T09:00:00,2000-07-10T09:00:00,' . '2001-06-10T09:00:00,2001-07-10T09:00:00', $title); ###### TEST 25 $title="*** Every other year on January, February, and March for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970310T090000 # recur_by_rule:FREQ=YEARLY;INTERVAL=2;COUNT=10;BYMONTH=1,2,3 # # ==> (1997 9:00 AM EST)March 10 # (1999 9:00 AM EST)January 10;February 10;March 10 # (2001 9:00 AM EST)January 10;February 10;March 10 # (2003 9:00 AM EST)January 10;February 10;March 10 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970310T090000, freq => 'yearly', interval => 2, count => 10, bymonth => [ 1, 2, 3 ], ) ->intersection( $period_1995_2004 ); is("".str($a), '1997-03-10T09:00:00,' . '1999-01-10T09:00:00,1999-02-10T09:00:00,1999-03-10T09:00:00,' . '2001-01-10T09:00:00,2001-02-10T09:00:00,2001-03-10T09:00:00,' . '2003-01-10T09:00:00,2003-02-10T09:00:00,2003-03-10T09:00:00', $title); $title="*** Every 3rd year on the 1st, 100th and 200th day for 10 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970101T090000 # recur_by_rule:FREQ=YEARLY;INTERVAL=3;COUNT=10;BYYEARDAY=1,100,200 # # ==> (1997 9:00 AM EST)January 1 # (1997 9:00 AM EDT)April 10;July 19 # (2000 9:00 AM EST)January 1 # (2000 9:00 AM EDT)April 9;July 18 # (2003 9:00 AM EST)January 1 # (2003 9:00 AM EDT)April 10;July 19 # (2006 9:00 AM EST)January 1 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970101T090000 , freq => 'yearly', interval => 3, count => 10, byyearday => [ 1, 100, 200 ] ) ->intersection( $period_1995_2007 ); is("".str($a), '1997-01-01T09:00:00,' . '1997-04-10T09:00:00,1997-07-19T09:00:00,' . '2000-01-01T09:00:00,' . '2000-04-09T09:00:00,2000-07-18T09:00:00,' . '2003-01-01T09:00:00,2003-04-10T09:00:00,2003-07-19T09:00:00,' . '2006-01-01T09:00:00', $title); ########### TEST 27 $title="*** Every 20th Monday of the year, forever ***"; # # DTSTART;TZID=US-Eastern:19970519T090000 # recur_by_rule:FREQ=YEARLY;BYDAY=20MO # # ==> (1997 9:00 AM EDT)May 19 # (1998 9:00 AM EDT)May 18 # (1999 9:00 AM EDT)May 17 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970101T090000 , freq => 'yearly', byday => [ '20mo' ] ) ->intersection( $period_1995_2000 ); is("".str($a), '1997-05-19T09:00:00,1998-05-18T09:00:00,1999-05-17T09:00:00', $title); $title="*** Monday of week number 20 (where the default start of the week i ***"; # Monday), forever: # # DTSTART;TZID=US-Eastern:19970512T090000 # recur_by_rule:FREQ=YEARLY;BYWEEKNO=20;BYDAY=MO # # ==> (1997 9:00 AM EDT)May 12 # (1998 9:00 AM EDT)May 11 # (1999 9:00 AM EDT)May 17 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970101T090000 , freq => 'yearly', byweekno => [ 20 ], byday => [ 'mo' ] ) ->intersection( $period_1995_2000 ); is("".str($a), '1997-05-12T09:00:00,1998-05-11T09:00:00,1999-05-17T09:00:00', $title); $title="*** Every Thursday in March, forever ***"; # # DTSTART;TZID=US-Eastern:19970313T090000 # recur_by_rule:FREQ=YEARLY;BYMONTH=3;BYDAY=TH # # ==> (1997 9:00 AM EST)March 13,20,27 # (1998 9:00 AM EST)March 5,12,19,26 # (1999 9:00 AM EST)March 4,11,18,25 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970310T090000 , freq => 'yearly', bymonth => [ 3 ], byday => [ 'th' ] ) ->intersection( $period_1995_2000 ); is("".str($a), '1997-03-13T09:00:00,1997-03-20T09:00:00,1997-03-27T09:00:00,' . '1998-03-05T09:00:00,1998-03-12T09:00:00,' . '1998-03-19T09:00:00,1998-03-26T09:00:00,' . '1999-03-04T09:00:00,1999-03-11T09:00:00,' . '1999-03-18T09:00:00,1999-03-25T09:00:00', $title); $title="*** Every Thursday, but only during June, July, and August, forever ***"; # # DTSTART;TZID=US-Eastern:19970605T090000 # recur_by_rule:FREQ=YEARLY;BYDAY=TH;BYMONTH=6,7,8 # # ==> (1997 9:00 AM EDT)June 5,12,19,26;July 3,10,17,24,31; # August 7,14,21,28 # (1998 9:00 AM EDT)June 4,11,18,25;July 2,9,16,23,30; # August 6,13,20,27 # (1999 9:00 AM EDT)June 3,10,17,24;July 1,8,15,22,29; # August 5,12,19,26 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970310T090000 , freq => 'yearly', bymonth => [ 6, 7, 8 ], byday => [ 'th' ] ) ->intersection( $period_1995_2000 ); is("".str($a), '1997-06-05T09:00:00,1997-06-12T09:00:00,' . '1997-06-19T09:00:00,1997-06-26T09:00:00,' . '1997-07-03T09:00:00,1997-07-10T09:00:00,' . '1997-07-17T09:00:00,1997-07-24T09:00:00,1997-07-31T09:00:00,' . '1997-08-07T09:00:00,1997-08-14T09:00:00,' . '1997-08-21T09:00:00,1997-08-28T09:00:00,' . '1998-06-04T09:00:00,1998-06-11T09:00:00,' . '1998-06-18T09:00:00,1998-06-25T09:00:00,' . '1998-07-02T09:00:00,1998-07-09T09:00:00,' . '1998-07-16T09:00:00,1998-07-23T09:00:00,1998-07-30T09:00:00,' . '1998-08-06T09:00:00,1998-08-13T09:00:00,' . '1998-08-20T09:00:00,1998-08-27T09:00:00,' . '1999-06-03T09:00:00,1999-06-10T09:00:00,' . '1999-06-17T09:00:00,1999-06-24T09:00:00,' . '1999-07-01T09:00:00,1999-07-08T09:00:00,' . '1999-07-15T09:00:00,1999-07-22T09:00:00,1999-07-29T09:00:00,' . '1999-08-05T09:00:00,1999-08-12T09:00:00,' . '1999-08-19T09:00:00,1999-08-26T09:00:00', $title); $title="*** Every Friday the 13th, forever ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # EXDATE;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=MONTHLY;BYDAY=FR;BYMONTHDAY=13 # # ==> (1998 9:00 AM EST)February 13;March 13;November 13 # (1999 9:00 AM EDT)August 13 # (2000 9:00 AM EDT)October 13 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'monthly', bymonthday => [ 13 ], byday => [ 'fr' ] ) ->intersection( $period_1995_2001 ); # EXDATE doesn't make sense here, because the date is not in the set is("".str($a), '1998-02-13T09:00:00,1998-03-13T09:00:00,1998-11-13T09:00:00,' . '1999-08-13T09:00:00,2000-10-13T09:00:00', $title); $title="*** The first Saturday that follows the first Sunday of the month ***"; # forever: # # DTSTART;TZID=US-Eastern:19970913T090000 # recur_by_rule:FREQ=MONTHLY;BYDAY=SA;BYMONTHDAY=7,8,9,10,11,12,13 # # ==> (1997 9:00 AM EDT)September 13;October 11 # (1997 9:00 AM EST)November 8;December 13 # (1998 9:00 AM EST)January 10;February 7;March 7 # (1998 9:00 AM EDT)April 11;May 9;June 13... # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'monthly', bymonthday => [ 7,8,9,10,11,12,13 ], byday => [ 'sa' ] ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-13T09:00:00,1997-10-11T09:00:00,' . '1997-11-08T09:00:00,1997-12-13T09:00:00,' . '1998-01-10T09:00:00,1998-02-07T09:00:00,1998-03-07T09:00:00,' . '1998-04-11T09:00:00,1998-05-09T09:00:00,1998-06-13T09:00:00,' . '1998-07-11T09:00:00,1998-08-08T09:00:00,1998-09-12T09:00:00,' . '1998-10-10T09:00:00,1998-11-07T09:00:00,1998-12-12T09:00:00', $title); # test 33 $title="*** Every four years, the first Tuesday after a Monday in November ***"; # forever (U.S. Presidential Election day): # # DTSTART;TZID=US-Eastern:19961105T090000 # recur_by_rule:FREQ=YEARLY;INTERVAL=4;BYMONTH=11;BYDAY=TU;BYMONTHDAY=2,3,4, # 5,6,7,8 # # ==> (1996 9:00 AM EST)November 5 # (2000 9:00 AM EST)November 7 # (2004 9:00 AM EST)November 2 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19961105T090000 , freq => 'yearly', interval => 4, bymonthday => [ 2,3,4,5,6,7,8 ], byday => [ 'tu' ], bymonth => [ 11 ], ) ->intersection( $period_1995_2005 ); is("".str($a), '1996-11-05T09:00:00,2000-11-07T09:00:00,2004-11-02T09:00:00', $title); # test 34 $title="*** The 3rd instance into the month of one of Tuesday, Wednesday or Thursday, for the next 3 months: ***"; # # DTSTART;TZID=US-Eastern:19970904T090000 # recur_by_rule:FREQ=MONTHLY;COUNT=3;BYDAY=TU,WE,TH;BYSETPOS=3 # # ==> (1997 9:00 AM EDT)September 4;October 7 # (1997 9:00 AM EST)November 6 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970904T090000 , freq => 'monthly', count => 3, byday => [ 'tu', 'we', 'th' ], bysetpos => 3 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-04T09:00:00,1997-10-07T09:00:00,1997-11-06T09:00:00', $title); $title="*** The 2nd to last weekday of the month: ***"; # # DTSTART;TZID=US-Eastern:19970929T090000 # recur_by_rule:FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-2 # # ==> (1997 9:00 AM EDT)September 29 # (1997 9:00 AM EST)October 30;November 27;December 30 # (1998 9:00 AM EST)January 29;February 26;March 30 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970904T090000 , freq => 'monthly', byday => [ 'mo', 'tu', 'we', 'th', 'fr' ], bysetpos => -2 ) ->intersection( $period_1995_19980401 ); is("".str($a), '1997-09-29T09:00:00,1997-10-30T09:00:00,' . '1997-11-27T09:00:00,1997-12-30T09:00:00,1998-01-29T09:00:00,' . '1998-02-26T09:00:00,1998-03-30T09:00:00', $title); $title="*** Every 3 hours from 9:00 AM to 5:00 PM on a specific day ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=HOURLY;INTERVAL=3;UNTIL=1997-09-02T17:00:00 # # ==> (September 2, 1997 EDT)09:00,12:00,15:00 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'hourly', interval => 3, until => $dt19970902T170000 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-02T12:00:00,1997-09-02T15:00:00', $title); $title="*** Every 15 minutes for 6 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=MINUTELY;INTERVAL=15;COUNT=6 # # ==> (September 2, 1997 EDT)09:00,09:15,' . # '09:30,09:45,10:00,10:15 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'minutely', interval => 15, count => 6 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-02T09:15:00,' . '1997-09-02T09:30:00,1997-09-02T09:45:00,' . '1997-09-02T10:00:00,1997-09-02T10:15:00', $title); $title="*** Every hour and a half for 4 occurrences ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=MINUTELY;INTERVAL=90;COUNT=4 # # ==> (September 2, 1997 EDT)09:00,10:30;12:00;13:30 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'minutely', interval => 90, count => 4 ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-09-02T09:00:00,1997-09-02T10:30:00,' . '1997-09-02T12:00:00,1997-09-02T13:30:00', $title); ########## TEST 39 $title="*** Every 20 minutes from 9:00 AM to 4:40 PM every day ***"; # # DTSTART;TZID=US-Eastern:19970902T090000 # recur_by_rule:FREQ=DAILY;BYHOUR=9,10,11,12,13,14,15,16;BYMINUTE=0,20,40 # or # recur_by_rule:FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16 # # ==> (September 2, 1997 EDT)9:00,9:20,' . # '9:40,10:00,10:20, # ... 16:00,16:20,16:40 # (September 3, 1997 EDT)9:00,9:20,' . # '9:40,10:00,10:20, # ...16:00,16:20,16:40 # ... # $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'daily', byhour => [ 9,10,11,12,13,14,15,16 ], byminute => [ 0,20,40 ] ) ->intersection( $period_1995_19970904T090000 ); is("".str($a), '1997-09-02T09:00:00,1997-09-02T09:20:00,' . '1997-09-02T09:40:00,1997-09-02T10:00:00,1997-09-02T10:20:00,' . '1997-09-02T10:40:00,1997-09-02T11:00:00,' . '1997-09-02T11:20:00,1997-09-02T11:40:00,1997-09-02T12:00:00,' . '1997-09-02T12:20:00,1997-09-02T12:40:00,' . '1997-09-02T13:00:00,1997-09-02T13:20:00,1997-09-02T13:40:00,' . '1997-09-02T14:00:00,1997-09-02T14:20:00,' . '1997-09-02T14:40:00,1997-09-02T15:00:00,1997-09-02T15:20:00,' . '1997-09-02T15:40:00,1997-09-02T16:00:00,' . '1997-09-02T16:20:00,1997-09-02T16:40:00,' . '1997-09-03T09:00:00,1997-09-03T09:20:00,' . '1997-09-03T09:40:00,1997-09-03T10:00:00,1997-09-03T10:20:00,' . '1997-09-03T10:40:00,1997-09-03T11:00:00,' . '1997-09-03T11:20:00,1997-09-03T11:40:00,1997-09-03T12:00:00,' . '1997-09-03T12:20:00,1997-09-03T12:40:00,' . '1997-09-03T13:00:00,1997-09-03T13:20:00,1997-09-03T13:40:00,' . '1997-09-03T14:00:00,1997-09-03T14:20:00,' . '1997-09-03T14:40:00,1997-09-03T15:00:00,1997-09-03T15:20:00,' . '1997-09-03T15:40:00,1997-09-03T16:00:00,' . '1997-09-03T16:20:00,1997-09-03T16:40:00,1997-09-04T09:00:00', $title); # recur_by_rule:FREQ=MINUTELY;INTERVAL=20;BYHOUR=9,10,11,12,13,14,15,16 $a = DateTime::Event::ICal->recur( dtstart => $dt19970902T090000 , freq => 'minutely', interval => 20, byhour => [ 9,10,11,12,13,14,15,16 ], ) ->intersection( $period_1995_19970904T090000 ); is("".str($a), '1997-09-02T09:00:00,1997-09-02T09:20:00,' . '1997-09-02T09:40:00,1997-09-02T10:00:00,1997-09-02T10:20:00,' . '1997-09-02T10:40:00,1997-09-02T11:00:00,' . '1997-09-02T11:20:00,1997-09-02T11:40:00,1997-09-02T12:00:00,' . '1997-09-02T12:20:00,1997-09-02T12:40:00,' . '1997-09-02T13:00:00,1997-09-02T13:20:00,1997-09-02T13:40:00,' . '1997-09-02T14:00:00,1997-09-02T14:20:00,' . '1997-09-02T14:40:00,1997-09-02T15:00:00,1997-09-02T15:20:00,' . '1997-09-02T15:40:00,1997-09-02T16:00:00,' . '1997-09-02T16:20:00,1997-09-02T16:40:00,' . '1997-09-03T09:00:00,1997-09-03T09:20:00,' . '1997-09-03T09:40:00,1997-09-03T10:00:00,1997-09-03T10:20:00,' . '1997-09-03T10:40:00,1997-09-03T11:00:00,' . '1997-09-03T11:20:00,1997-09-03T11:40:00,1997-09-03T12:00:00,' . '1997-09-03T12:20:00,1997-09-03T12:40:00,' . '1997-09-03T13:00:00,1997-09-03T13:20:00,1997-09-03T13:40:00,' . '1997-09-03T14:00:00,1997-09-03T14:20:00,' . '1997-09-03T14:40:00,1997-09-03T15:00:00,1997-09-03T15:20:00,' . '1997-09-03T15:40:00,1997-09-03T16:00:00,' . '1997-09-03T16:20:00,1997-09-03T16:40:00,1997-09-04T09:00:00', $title); $title="*** An example where the days generated makes a difference because of WKST ***"; # # DTSTART;TZID=US-Eastern:19970805T090000 # recur_by_rule:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=MO # # ==> (1997 EDT)Aug 5,10,19,24 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970805T090000 , freq => 'weekly', interval => 2, count => 4, byday => [ 'tu', 'su' ], wkst => 'mo' ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-08-05T09:00:00,1997-08-10T09:00:00,' . '1997-08-19T09:00:00,1997-08-24T09:00:00', $title); $title="*** changing only WKST from MO to SU, yields different results... ***"; # # DTSTART;TZID=US-Eastern:19970805T090000 # recur_by_rule:FREQ=WEEKLY;INTERVAL=2;COUNT=4;BYDAY=TU,SU;WKST=SU # ==> (1997 EDT)August 5,17,19,31 # $a = DateTime::Event::ICal->recur( dtstart => $dt19970805T090000 , freq => 'weekly', interval => 2, count => 4, byday => [ 'tu', 'su' ], wkst => 'su' ) ->intersection( $period_1995_1999 ); is("".str($a), '1997-08-05T09:00:00,1997-08-17T09:00:00,' . '1997-08-19T09:00:00,1997-08-31T09:00:00', $title); __END__ # another test using this result: is( "" . $a->exclude_by_date( list => ['1997-08-17T09:00:00', '1997-08-31T09:00:00'] ) , '1997-08-05T09:00:00,1997-08-19T09:00:00', "*** EXDATE removing 2 days ***" ); # yet another test using this result: is( "" . $a->recur_by_date( list => ['19970817Z', '19970831Z'] ) , '1997-08-05T09:00:00,19970817Z,1997-08-17T09:00:00,' . '1997-08-19T09:00:00,19970831Z,1997-08-31T09:00:00', "*** RDATE adding 2 days ***" ); $a = Date::Set->event( dtstart => '1970-03-29T02:00:00', rule => 'FREQ=MONTHLY;BYMONTH=3;BYDAY=-3SU', start=>'2003-01-01T00:00:00', end=>'2005-01-01T00:00:00' ); is ( "". $a , '2003-03-16T02:00:00,2004-03-14T02:00:00', 'BYDAY works well with FREQ=MONTH' ); $a = Date::Set->event( dtstart => '1970-03-29T02:00:00', rule => 'FREQ=YEARLY;BYMONTH=3;BYDAY=-3SU', start=> '2003-01-01T00:00:00', end=>'2005-01-01T00:00:00' ); is ( "". $a , '2003-03-16T02:00:00,2004-03-14T02:00:00', 'BYDAY works well with FREQ=YEARLY;BYMONTH' ); 1; DateTime-Event-ICal-0.11/t/05byday.t000644 000765 000024 00000012415 11545402422 017333 0ustar00fglockstaff000000 000000 #!/bin/perl -w use strict; use Test::More tests => 11; use DateTime; use DateTime::Event::ICal; # yearly { my $dt1 = new DateTime( year => 2000 ); my ( $set, @dt, $r ); # test contributed by John Bishop $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, dtend => $dt1->clone->add( years => 3 ), bymonth => 7, byday => '3mo' ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-07-17T00:00:00 2001-07-16T00:00:00 2002-07-15T00:00:00', "yearly, bymonth, byday" ); $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, dtend => $dt1->clone->add( years => 3 ), bymonth => 7, byday => '3mo', byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-07-17T10:00:00 2001-07-16T10:00:00 2002-07-15T10:00:00', "yearly, bymonth, byday, byhour" ); $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, dtend => $dt1->clone->add( years => 1 ), bymonth => 7, byday => ['3mo', 'fr' ], byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-07-07T10:00:00 2000-07-14T10:00:00 2000-07-17T10:00:00 2000-07-21T10:00:00 2000-07-28T10:00:00', "yearly, bymonth, byday index+nonindex, byhour" ); $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, dtend => $dt1->clone->add( years => 3 ), interval => 2, bymonth => 7, byday => ['3mo', 'fr' ], byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-07-07T10:00:00 2000-07-14T10:00:00 2000-07-17T10:00:00 2000-07-21T10:00:00 2000-07-28T10:00:00 '. '2002-07-05T10:00:00 2002-07-12T10:00:00 2002-07-15T10:00:00 2002-07-19T10:00:00 2002-07-26T10:00:00', "yearly, interval, bymonth, byday index+nonindex, byhour" ); # all months $set = DateTime::Event::ICal->recur( freq => 'yearly', dtstart => $dt1, dtend => $dt1->clone->add( years => 3 ), interval => 2, byday => ['3mo', 'fr' ], byhour => 10 ); @dt = $set->as_list( start => $dt1, end => $dt1->clone->add( months => 1 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-01-07T10:00:00 2000-01-14T10:00:00 2000-01-17T10:00:00 2000-01-21T10:00:00 2000-01-28T10:00:00', "(2000) yearly, interval, byday index+nonindex, byhour" ); @dt = $set->as_list( start => $dt1->clone->add( months => 12 ), end => $dt1->clone->add( months => 13 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '', "(2001 = empty) yearly, interval, byday index+nonindex, byhour" ); @dt = $set->as_list( start => $dt1->clone->add( months => 24 ), end => $dt1->clone->add( months => 25 ) ); $r = join(' ', map { $_->datetime } @dt); is( $r, '2002-01-04T10:00:00 2002-01-11T10:00:00 2002-01-18T10:00:00 2002-01-21T10:00:00 2002-01-25T10:00:00', "(2002) yearly, interval, byday index+nonindex, byhour" ); } # monthly { my $dt1 = new DateTime( year => 2000 ); my ( $set, @dt, $r ); $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, dtend => $dt1->clone->add( months => 4 ), byday => '3mo' ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-01-17T00:00:00 2000-02-21T00:00:00 2000-03-20T00:00:00 2000-04-17T00:00:00', "monthly, byday" ); $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, dtend => $dt1->clone->add( months => 4 ), byday => '3mo', byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-01-17T10:00:00 2000-02-21T10:00:00 2000-03-20T10:00:00 2000-04-17T10:00:00', "monthly, byday, byhour" ); $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, dtend => $dt1->clone->add( months => 2 ), byday => ['3mo', 'fr' ], byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-01-07T10:00:00 2000-01-14T10:00:00 2000-01-17T10:00:00 '. '2000-01-21T10:00:00 2000-01-28T10:00:00 2000-02-04T10:00:00 '. '2000-02-11T10:00:00 2000-02-18T10:00:00 2000-02-21T10:00:00 '. '2000-02-25T10:00:00', "monthly, byday index+nonindex, byhour" ); $set = DateTime::Event::ICal->recur( freq => 'monthly', dtstart => $dt1, dtend => $dt1->clone->add( months => 3 ), interval => 2, byday => ['3mo', 'fr' ], byhour => 10 ); @dt = $set->as_list; $r = join(' ', map { $_->datetime } @dt); is( $r, '2000-01-07T10:00:00 2000-01-14T10:00:00 2000-01-17T10:00:00 '. '2000-01-21T10:00:00 2000-01-28T10:00:00 '. '2000-03-03T10:00:00 '. '2000-03-10T10:00:00 2000-03-17T10:00:00 2000-03-20T10:00:00 '. '2000-03-24T10:00:00 2000-03-31T10:00:00', "monthly, byday index+nonindex, byhour" ); } DateTime-Event-ICal-0.11/lib/DateTime/000755 000765 000024 00000000000 12046257351 017673 5ustar00fglockstaff000000 000000 DateTime-Event-ICal-0.11/lib/DateTime/Event/000755 000765 000024 00000000000 12046257351 020754 5ustar00fglockstaff000000 000000 DateTime-Event-ICal-0.11/lib/DateTime/Event/ICal.pm000644 000765 000024 00000066665 12046256664 022153 0ustar00fglockstaff000000 000000 package DateTime::Event::ICal; use strict; require Exporter; use Carp; use DateTime; use DateTime::Set; use DateTime::Span; use DateTime::SpanSet; use DateTime::Event::Recurrence 0.11; use Params::Validate qw(:all); use vars qw( $VERSION @ISA ); @ISA = qw( Exporter ); $VERSION = '0.11'; use constant INFINITY => 100 ** 100 ** 100 ; use constant NEG_INFINITY => -1 * (100 ** 100 ** 100); my %weekdays = ( mo => 1, tu => 2, we => 3, th => 4, fr => 5, sa => 6, su => 7 ); my %freqs = ( secondly => { name => 'second', names => 'seconds' }, minutely => { name => 'minute', names => 'minutes' }, hourly => { name => 'hour', names => 'hours' }, daily => { name => 'day', names => 'days' }, monthly => { name => 'month', names => 'months' }, weekly => { name => 'week', names => 'weeks' }, yearly => { name => 'year', names => 'years' }, ); # internal debugging method - formats the argument list for error messages # the output from this routine is also used by DateTime::Format::ICal->format_recurrence() sub _param_str { my %param = @_; my @str; for ( qw( freq interval count ), qw( byyear bymonth byday ), sort keys %param ) { next unless exists $param{$_}; if ( ref( $param{$_} ) eq 'ARRAY' ) { push @str, "$_=". join( ',', @{$param{$_}} ) } elsif ( UNIVERSAL::can( $param{$_}, 'datetime' ) ) { if ( $DateTime::Format::ICal::VERSION ) { push @str, "$_=" . DateTime::Format::ICal->format_datetime( $param{$_} ); } else { push @str, "$_=". $param{$_}->datetime } } elsif ( defined $param{$_} ) { push @str, "$_=". $param{$_} } else { push @str, "$_=undef" } delete $param{$_}; } return join(';', @str); } # recurrence constructors sub _secondly_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; delete $$argsref{$_} for qw( interval ); return DateTime::Event::Recurrence->secondly( %by ); } sub _minutely_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; delete $$argsref{$_} for qw( interval bysecond ); return DateTime::Event::Recurrence->minutely( %by ); } sub _hourly_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; delete $$argsref{$_} for qw( interval byminute bysecond ); return DateTime::Event::Recurrence->hourly( %by ); } sub _daily_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; delete $$argsref{$_} for qw( interval bysecond byminute byhour ); # TODO: (maybe) - same thing if byweekno exists $$argsref{bymonthday} = [ 1 .. 31 ] if exists $args{bymonth} && ! exists $args{bymonthday}; return DateTime::Event::Recurrence->daily( %by ); } sub _weekly_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; $by{week_start_day} = $args{wkst} ? $args{wkst} : 'mo'; # -1fr works too $by{days} = exists $args{byday} ? [ map { $_ =~ s/[\-\+\d]+//; $weekdays{$_} } @{$args{byday}} ] : $dtstart->day_of_week ; # warn "weekly:"._param_str(%by); delete $$argsref{$_} for qw( interval bysecond byminute byhour byday ); return DateTime::Event::Recurrence->weekly( %by ); } sub _monthly_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; $by{week_start_day} = $args{wkst} ? $args{wkst} : '1mo'; if ( exists $args{bymonthday} ) { $by{days} = $args{bymonthday}; } elsif ( exists $args{byday} ) { $by{days} = [ 1 .. 31 ]; } else { $by{days} = $dtstart->day unless exists $by{days}; } my $set_byday; if ( exists $args{byday} ) { my $freq = 'monthly'; my %by; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; # process byday = "1FR" and "FR" $set_byday = _recur_1fr( %by, byday => $args{byday}, freq => $freq ); delete $$argsref{$_} for qw( byday ); } delete $$argsref{$_} for qw( interval bysecond byminute byhour bymonthday ); return DateTime::Event::Recurrence->monthly( %by )->intersection( $set_byday ) if $set_byday; return DateTime::Event::Recurrence->monthly( %by ); } sub _yearly_recurrence { my ($dtstart, $argsref) = @_; my %by; my %args = %$argsref; $by{interval} = $args{interval} if exists $args{interval}; $by{start} = $dtstart; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; $by{week_start_day} = $args{wkst} ? $args{wkst} : 'mo'; # warn "wkst $by{week_start_day}"; if ( exists $args{bymonth} ) { $by{months} = $args{bymonth}; delete $$argsref{bymonth}; $by{days} = $args{bymonthday} if exists $args{bymonthday}; $by{days} = [ 1 .. 31 ] if ! exists $by{days} && exists $args{byday}; $by{days} = $dtstart->day unless exists $by{days}; delete $$argsref{bymonthday}; } elsif ( exists $args{byweekno} ) { $by{weeks} = $args{byweekno}; delete $$argsref{byweekno}; $by{days} = $args{byday} if exists $args{byday}; $by{days} = $dtstart->day_of_week unless exists $by{days}; delete $$argsref{byday}; } elsif ( exists $args{byyearday} ) { $by{days} = $args{byyearday}; delete $$argsref{byyearday}; } elsif ( exists $args{byday} ) { $by{months} = [ 1 .. 12 ]; $by{days} = $args{bymonthday} if exists $args{bymonthday}; $by{days} = [ 1 .. 31 ] if ! exists $by{days}; $by{days} = $dtstart->day unless exists $by{days}; delete $$argsref{bymonthday}; } else { $by{months} = $dtstart->month; $by{days} = $args{bymonthday} if exists $args{bymonthday}; $by{days} = $dtstart->day unless exists $by{days}; delete $$argsref{bymonthday}; } my $set_byday; if ( exists $args{byday} ) { my $freq = 'yearly'; $freq = 'monthly' if exists $args{bymonth}; my %by; $by{seconds} = $args{bysecond} if exists $args{bysecond}; $by{seconds} = $dtstart->second unless exists $by{seconds}; $by{minutes} = $args{byminute} if exists $args{byminute}; $by{minutes} = $dtstart->minute unless exists $by{minutes}; $by{hours} = $args{byhour} if exists $args{byhour}; $by{hours} = $dtstart->hour unless exists $by{hours}; # process byday = "1FR" and "FR" $set_byday = _recur_1fr( %by, byday => $args{byday}, freq => $freq ); delete $$argsref{$_} for qw( byday ); } delete $$argsref{$_} for qw( interval byday bysecond byminute byhour ); return DateTime::Event::Recurrence->yearly( %by )->intersection( $set_byday ) if $set_byday; return DateTime::Event::Recurrence->yearly( %by ); } # recurrence constructor for '1FR' specification sub _recur_1fr { # ( freq , interval, dtstart, byday[ week_count . week_day ] ) my %args = @_; my $base_set; my %days; my $base_duration; my @days_no_index; # parse byday $args{byday} = [ $args{byday} ] unless ref $args{byday} eq 'ARRAY'; for ( @{$args{byday}} ) { my ( $count, $day_name ) = $_ =~ /(.*)(\w\w)/; my $week_day = $weekdays{ $day_name }; die "invalid week day ($day_name)" unless $week_day; if ( $count ) { push @{$days{$day_name}}, $count; } else { # die "week count ($count) can't be zero" unless $count; push @days_no_index, $week_day; } } delete $args{byday}; my $result; if ( @days_no_index ) { my %_args = %args; $_args{days} = \@days_no_index; delete $_args{freq}; $result = DateTime::Event::Recurrence->weekly( %_args ); } for ( keys %days ) { my %_args = %args; $_args{weeks} = $days{$_}; $_args{week_start_day} = '1'.$_; # warn "creating set with $_ "._param_str( %_args ); if ( $_args{freq} eq 'monthly' ) { $base_duration = 'months'; delete $_args{freq}; # warn "creating base set with "._param_str( %args ); $base_set = DateTime::Event::Recurrence->monthly( %_args ) } elsif ( $_args{freq} eq 'yearly' ) { $base_duration = 'years'; delete $_args{freq}; $base_set = DateTime::Event::Recurrence->yearly( %_args ) } else { die "invalid freq ($_args{freq})"; } $result = $result ? $result->union( $base_set ) : $base_set; } return $result; } # bysetpos constructor sub _recur_bysetpos { # ( freq , interval, bysetpos, recurrence ) my %args = @_; # my $names = $freqs{ $args{freq} }{names}; # my $name = $freqs{ $args{freq} }{name}; no strict "refs"; my $freq = $args{freq}; my $base_set = DateTime::Event::Recurrence->$freq(); # die "invalid freq parameter ($args{freq})" # unless exists $DateTime::Event::Recurrence::truncate_interval{ $names }; #my $truncate_interval_sub = # $DateTime::Event::Recurrence::truncate_interval{ $names }; #my $next_unit_sub = # $DateTime::Event::Recurrence::next_unit{ $names }; #my $previous_unit_sub = # $DateTime::Event::Recurrence::previous_unit{ $names }; $args{bysetpos} = [ $args{bysetpos} ] unless ref( $args{bysetpos} ); # die "invalid bysetpos parameter [@{$args{bysetpos}}]" # unless @{$args{bysetpos}}; # print STDERR "bysetpos: [@{$args{bysetpos}}]\n"; for ( @{$args{bysetpos}} ) { $_-- if $_ > 0 } return DateTime::Set->from_recurrence ( next => sub { return $_[0] if $_[0]->is_infinite; ## return undef unless defined $_[0]; my $self = $_[0]->clone; # warn "bysetpos: next of ".$_[0]->datetime; # print STDERR " list [@{$args{bysetpos}}] \n"; # print STDERR " previous: ".$base_set->current( $_[0] )->datetime."\n"; my $start = $base_set->current( $_[0] ); while(1) { my $end = $base_set->next( $start->clone ); if ( $#{$args{bysetpos}} == 0 ) { # optimize by using 'next' instead of 'intersection' my $pos = $args{bysetpos}[0]; if ( $pos >= 0 ) { my $next = $start->clone; $next->subtract( nanoseconds => 1 ); while ( $pos-- >= 0 ) { # print STDERR " next: $pos ".$next->datetime."\n"; $next = $args{recurrence}->next( $next ) } return $next if $next > $self; } else { my $next = $end->clone; while ( $pos++ < 0 ) { # print STDERR " previous: $pos ".$next->datetime."\n"; $next = $args{recurrence}->previous( $next ) } return $next if $next > $self; } } else { # print STDERR " base: ".$start->datetime." ".$end->datetime."\n"; my $span = DateTime::Span->from_datetimes( start => $start, before => $end ); # print STDERR " done span\n"; my $subset = $args{recurrence}->intersection( $span ); my @list = $subset->as_list; # print STDERR " got list ".join(",", map{$_->datetime}@list)."\n"; # select my @l = @list[ @{$args{bysetpos}} ]; @l = grep { defined $_ } @l; @list = sort { $a <=> $b } @l; ## @list = sort { $a <=> $b } @list[ @{$args{bysetpos}} ]; # print STDERR " selected [@{$args{bysetpos}}]".join(",", map{$_->datetime}@list)."\n"; for ( @list ) { # print STDERR " choose: ".$_->datetime."\n" if $_ > $self; return $_ if $_ > $self; } } $start = $end; } # /while }, previous => sub { return $_[0] if $_[0]->is_infinite; my $self = $_[0]->clone; # warn "bysetpos: previous of ".$_[0]->datetime; # print STDERR " previous: ".$base_set->current( $_[0] )->datetime."\n"; my $start = $base_set->current( $_[0] ); my $end = $base_set->next( $start->clone ); my $count = 10; while(1) { # print STDERR " base: ".$start->datetime." ".$end->datetime."\n"; my $span = DateTime::Span->from_datetimes( start => $start, before => $end ); # print STDERR " done span\n"; my $subset = $args{recurrence}->intersection( $span ); my @list = $subset->as_list; # print STDERR " got list ".join(",", map{$_->datetime}@list)."\n"; # select my @l = @list[ @{$args{bysetpos}} ]; @l = grep { defined $_ } @l; @list = sort { $b <=> $a } @l; ## @list = sort { $a <=> $b } @list[ @{$args{bysetpos}} ]; # print STDERR " selected [@{$args{bysetpos}}]".join(",", map{$_->datetime}@list)."\n"; for ( @list ) { return $_ if $_ < $self; } return undef unless $count--; $end = $start; $start = $base_set->previous( $start ); } # /while } ); } # map frequencies to recurrence constructors { my %frequencies = ( secondly => \&_secondly_recurrence, minutely => \&_minutely_recurrence, hourly => \&_hourly_recurrence, daily => \&_daily_recurrence, monthly => \&_monthly_recurrence, weekly => \&_weekly_recurrence, yearly => \&_yearly_recurrence, ); sub _recur_by_freq { my ($freq,$dtstart,$args) = @_; return $frequencies{$freq}->($dtstart,$args) if exists $frequencies{$freq}; return undef; } } # main recurrence constructor sub recur { my $class = shift; my %args = @_; my %args_backup = @_; if ( exists $args{count} ) { # count my $n = $args{count}; delete $args{count}; my $count_inf = $class->recur( %args )->{set} ->select( count => $n ); return bless { set => $count_inf }, 'DateTime::Set'; } # warn "recur:"._param_str(%args); # stringify the argument list - will be used by format_recurrence ! my %tmp_args = @_; delete $tmp_args{dtstart}; delete $tmp_args{dtend}; my $recur_str = _param_str(%tmp_args); # dtstart / dtend / until my $span = exists $args{dtstart} ? DateTime::Span->from_datetimes( start => $args{dtstart} ) : DateTime::Set->empty_set->complement; $span = $span->complement( DateTime::Span->from_datetimes( after => delete $args{dtend} ) ) if exists $args{dtend}; $span = $span->complement( DateTime::Span->from_datetimes( after => delete $args{until} ) ) if exists $args{until}; # warn 'SPAN '. $span->{set}; $args{interval} = 1 unless $args{interval}; # setup the "default time" my $dtstart = exists $args{dtstart} ? delete $args{dtstart} : DateTime->new( year => 2000, month => 1, day => 1 ); # warn 'DTSTART '. $dtstart->datetime; # rewrite: daily-bymonth to yearly-bymonth-bymonthday[1..31] if ( $args{freq} eq 'daily' ) { if ( exists $args{bymonth} && $args{interval} == 1 ) { $args{freq} = 'yearly'; $args{bymonthday} = [ 1 .. 31 ] unless exists $args{bymonthday}; # warn "rewrite recur:"._param_str(%args); } } my $base_set; my %by; $base_set = _recur_by_freq($args{freq},$dtstart,\%args); unless (defined $base_set) { die "invalid freq ($args{freq})"; } delete $args{wkst}; # TODO: wkst # warn "\ncomplex recur:"._param_str(%args); %by = (); my $has_day = 0; my $by_year_day; if ( exists $args{byyearday} ) { $by_year_day = _yearly_recurrence($dtstart, \%args); } my $by_month_day; if ( exists $args{bymonthday} || exists $args{bymonth} ) { $by_month_day = _yearly_recurrence($dtstart, \%args); } my $by_week_day; # TODO: byweekno without byday if ( exists $args{byday} || exists $args{byweekno} ) { $by_week_day = _weekly_recurrence($dtstart, \%args); } my $by_hour; if ( exists $args{byhour} ) { my %by = %args; $by{byminute} = $args_backup{byminute} if $args_backup{byminute}; $by{byminute} = [ 0 .. 59 ] if $args{freq} eq 'minutely'; $by{bysecond} = $args_backup{bysecond} if $args_backup{bysecond}; $by{bysecond} = [ 0 .. 59 ] if $args{freq} eq 'secondly'; $by_hour = _daily_recurrence($dtstart, \%by); delete $args{byhour}; } # join the rules together $base_set = $base_set && $by_year_day ? $base_set->intersection( $by_year_day ) : ( $base_set ? $base_set : $by_year_day ); $base_set = $base_set && $by_month_day ? $base_set->intersection( $by_month_day ) : ( $base_set ? $base_set : $by_month_day ); $base_set = $base_set && $by_week_day ? $base_set->intersection( $by_week_day ) : ( $base_set ? $base_set : $by_week_day ); $base_set = $base_set && $by_hour ? $base_set->intersection( $by_hour ) : ( $base_set ? $base_set : $by_hour ); # TODO: # wkst # bysetpos if ( exists $args{bysetpos} ) { $base_set = _recur_bysetpos ( freq => $args{freq}, interval => $args{interval}, bysetpos => $args{bysetpos}, recurrence => $base_set ); delete $args{bysetpos}; } $base_set = $base_set->intersection( $span ) if $span; # check for nonprocessed arguments delete $args{freq}; my @args = %args; die "these arguments are not implemented: "._param_str(%args) if @args; bless $base_set, 'DateTime::Set::ICal'; $base_set->set_ical( include => [ uc('rrule:'.$recur_str) ] ); return $base_set; } __END__ =head1 NAME DateTime::Event::ICal - Perl DateTime extension for computing rfc2445 recurrences. =head1 SYNOPSIS use DateTime; use DateTime::Event::ICal; my $dt = DateTime->new( year => 2000, month => 6, day => 20, ); my $set = DateTime::Event::ICal->recur( dtstart => $dt, freq => 'daily', bymonth => [ 10, 12 ], byhour => [ 10 ] ); my $dt_next = $set->next( $dt ); my $dt_previous = $set->previous( $dt ); my $bool = $set->contains( $dt ); my @days = $set->as_list( start => $dt1, end => $dt2 ); my $iter = $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 rfc2445 style recurrences. =head1 USAGE =over 4 =item recur This method returns a C object representing the given recurrence. my $set = DateTime::Event::ICal->recur( %args ); This method takes parameters which correspond to the rule parts specified in section 4.3.10 of RFC 2445. Rather than rewrite that RFC here, you are encouraged to read that first if you want to understand what all these parameters represent. =over 4 =item * dtstart A DateTime object, which is the start date. This datetime is not included in the recurrence, unless it satisfies the recurrence's rules. A set can thus be used for creating exclusion rules (rfc2445 C), which don't include C. =item * until A DateTime object which specifies the recurrence's end date. Can also be specified as "dtend". =item * count A positive number which indicate the total number of recurrences. Giving both a "count" and an "until" parameter is pointless, though it is currently allowed. =item * freq One of: "yearly", "monthly", "weekly", "daily", "hourly", "minutely", "secondly" See the C documentation for more details on what these mean. =item * interval The interval between recurrences. This is a multiplier for the value specified by "freq". It defaults to 1. So if you specify a "freq" of "yearly" and an "interval" of 3, that means a recurrence that occurs every three years. =item * wkst Week start day. This can be one of: "mo", "tu", "we", "th", "fr", "sa", "su". The default is monday ("mo"). B =item * bysecond => [ list ], byminute => [ list ], byhour => [ list ] This should be one or more positive or numbers, specified as a scalar or array reference. Each number represents a second/minute/hour. See RFC 2445, section 4.3.10 for more details. =item * byday => [ list ] This should be a scalar or array reference containing days of the week, specified as "mo", "tu", "we", "th", "fr", "sa", "su" The day of week may have a prefix: "1tu", # the first tuesday of month or year "-2we" # the second to last wednesday of month or year See RFC 2445, section 4.3.10 for more details. =item * bymonthday => [ list ], byyearday => [ list ] A scalar or array reference containing positive or negative numbers, but not zero. For "bymonthday", the allowed ranges are -31 to -1. For "byyearday", the allowed ranges are -366 to -1, and 1 to 366. Day -1 is last day of month or year. See RFC 2445, section 4.3.10 for more details. =item * byweekno => [ list ] A scalar or array reference containing positive or negative numbers, but not zero. The allowed ranges are -53 to -1, and 1 to 53. The first week of year is week 1. The default week start day is monday. Week -1 is the last week of year. See RFC 2445, section 4.3.10 for more details. =item * bymonth => [ list ] A scalar or array reference containing positive or negative numbers, from -12 to -1 and 1 to 12. Month -1 is December. See RFC 2445, section 4.3.10 for more details. =item * bysetpos => [ list ] This can be either a scalar or an array reference of positive and negative numbers from -366 to -1, and 1 to 366. This parameter is used in conjuction with one of the other "by..." parameters. See RFC 2445, section 4.3.10 for more details. =back =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. =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 DateTime::Event::Recurrence - simple rule-based recurrences DateTime::Format::ICal - can parse rfc2445 recurrences DateTime::Set - recurrences defined by callback subroutines DateTime::Event::Cron - recurrences defined by "cron" rules DateTime::SpanSet RFC2445 - Internet Calendaring and Scheduling Core Object Specification - http://www.ietf.org/rfc/rfc2445.txt =cut