jasonwolf has asked for the wisdom of the Perl Monks concerning the following question:

Perl folks, I am looking for a calendar library that will enable me to create an appointment date, and have it recurrence pattern 1 month to the day for 'no end date'. Just like an Appointment Recurrence in Outlook or Thunderbird w/ calendar. I want to have a simple pattern in a text file and loop through it to create a detailed report. I suspect I could just add 30 days to a point in time; however, I suspect that would not be the best way since I will need to deal with shorter months or other time deviation. I am open to suggestions very crude example

---source.txt--- date length 2018-01-02 30 2018-01-07 30 2018-01-20 30 ---output_for_2018-01-02.txt--- 2018-01-02 2018-02-02 ~

Thank you

Replies are listed 'Best First'.
Re: Calendar library - appointment recurrance
by haukex (Archbishop) on Jan 24, 2018 at 14:30 UTC

    I like DateTime for all my date/time needs, and there is the extension DateTime::Event::Recurrence. And for more complex recurrences, you can use DateTime::Set. In addition, there is DateTime::Event::ICal.

    use warnings; use strict; use DateTime; use DateTime::Event::Recurrence; my $set = DateTime::Event::Recurrence->monthly(days=>7); my @list = $set->as_list( start => DateTime->new( year=>2018 ), end => DateTime->last_day_of_month( year=>2018, month=>12 ) ); print $_->ymd,"\n" for @list; __END__ 2018-01-07 2018-02-07 2018-03-07 2018-04-07 2018-05-07 2018-06-07 2018-07-07 2018-08-07 2018-09-07 2018-10-07 2018-11-07 2018-12-07

      I will work through your code and try it out. I am very new to Perl still. Thank you

Re: Calendar library - appointment recurrance
by thanos1983 (Parson) on Jan 24, 2018 at 16:15 UTC

    Hello jasonwolf,

    I personaly prefer Date::Manip.

    Sample of code:

    #!/usr/bin/perl use strict; use warnings; use Date::Manip; use Data::Dumper; # Y M W D H M S base''start''end' my @dates = ParseRecur("0:1:0:0:0:0:0","","today", "Jan 1 2019"); # my @dates = ParseRecur("0:1:0:0:0:0:0","","today", "01/01/2019"); # my @dates = ParseRecur("0:1:0:0:0:0:0","","today", "1st January 2019 +"); # my @dates = ParseRecur("0:1:0:0:0:0:0","","today", "First of January + 2019"); my @datesFormatted = map { UnixDate($_, '%Y-%m-%d') } @dates; print Dumper \@datesFormatted; __END__ $ perl test.pl $VAR1 = [ '2018-01-24', '2018-02-24', '2018-03-24', '2018-04-24', '2018-05-24', '2018-06-24', '2018-07-24', '2018-08-24', '2018-09-24', '2018-10-24', '2018-11-24', '2018-12-24' ];

    Update: Adding a few more different string inputs on the end date format.

    Hope this helps, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!
      Thank you!
Re: Calendar library - appointment recurrance
by trippledubs (Deacon) on Jan 24, 2018 at 15:38 UTC
    use strict; use warnings; use Time::Piece; use Time::Seconds; print localtime() + ONE_MONTH;
      Thank you very much!