Andrew Martin wrote:
>however 17-02-2017 is the Third Friday, the expected result is 10-02-2017

DateTime::Event::Recurrence->monthly doesn't really do "the Nth Fooday
of each month".  It gives you either "the Fooday of the Nth week that
is mostly contained in each month" or "the Fooday of the Nth week that
started in each month".  Its idea of a week always starts on a specified
day of the week; the first week that is mostly contained in a month may
start on any day from three days before the 1st of the month up to the
4th of the month.

You *can* use this to get the Nth Fooday of each month, by manipulating
how the weeks are delimited.  Observe that each week is mostly contained
in the month that contains its fourth day.  If you're only interested
in which month contains a specific day of the week, you just have to
arrange for that day to be the fourth of the week.  So to get the Nth
Friday of each month, you need to tell it that the week starts on Tuesday:

    my $set = DateTime::Event::Recurrence->monthly(weeks => 2,
        days => "fr", week_start_day => "tu");

Or you can use weeks starting in the month, and tell it that the day
you're interested in is the first day of the week:

    my $set = DateTime::Event::Recurrence->monthly(weeks => 2,
        days => "fr", week_start_day => "1fr");

The example in the module's documentation labelled "second tuesday of
every month" is incorrect.  It actually yields Tuesdays ranging from the
9th to the 15th of each month, because it is computing the Tuesdays of
the second week to start in each month, with the week starting on Monday.

-zefram

Reply via email to