Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-07 Thread Flavio S. Glock
DateTime-Event-Recurrence-0.19 is in CPAN, with
documentation patches related to the "week_start_day" parameter:

-- "week_start_day" parameter no longer marked "for internal use".
-- Fix "week day" examples. Pointed out by Eric Jensen and Zefram
   in a thread started by Andrew Martin in datetime@perl.org
-- Clarify that week_start_day defaults to "1mo", except for
   yearly recurrences that default to "mo". Patches by David Steinbrunner.
-- Updated contact email.


2017-03-02 5:00 GMT+01:00 Zefram :

> 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
>


Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Zefram
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


Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Eric Jensen
Hi all,

> On Mar 1, 2017, at 8:47 PM, Marius Feraru  wrote:
> 
> ++ make sure you agree with your party what's what, as, for instance, some 
> will say "second Friday of September 2017 is 15th", while others say to be 
> "8th"… and so on. Sorry, I know it's ugly. ;-)
> 

Marius, I didn’t understand your comment here.  Isn’t this a question with only 
one answer, not a matter of having to agree beforehand?  i.e. isn’t the second 
Friday of September 2017 *really* the 8th?  

Also, looking at the week_start_day parameter, wouldn’t ‘1fr’ work better?  
(Then we start counting on the first Friday, so we really get the second Friday 
correctly.)  For me, that gives Sept. 8 as the second Friday of Sept. 2017, 
anyway.  :-)   Likewise for Dec. 8. 

Also, I’ll note that the docs for DateTime::Event::Recurrence give an example 
that’s exactly like the original poster’s code:
# second tuesday of every month
my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days => 2 );
so maybe that should be clarified.  Also, since the docs say “The 
week_start_day parameter is intended for internal use…” that initially implied 
to me that it shouldn’t be set by a caller - so I wonder if there’s another way 
to clarify that in the docs. 

Eric



Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Marius Feraru
Hi Martin,

On Wed, Mar 1, 2017 at 1:34 AM, Andrew Martin  wrote:

> however 17-02-2017 is the Third Friday, the expected result is 10-02-2017
>
> I would appreciate any help, I'm baffled :-)
>
Check out D/E/R §The "week_start_day" Parameter

 documentation:
reading its default setting explanation will quickly help you realize
what's happening. :-)

> my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days =>5 );
>
By inserting ", week_start_day => 'mo'" into the line above, I get:
13-01-2017 Test event
*10*-02-2017 Test event
*10*-03-2017 Test event
14-04-2017 Test event
12-05-2017 Test event
*09*-06-2017 Test event
14-07-2017 Test event
*11*-08-2017 Test event
15-09-2017 Test event
13-10-2017 Test event
*10*-11-2017 Test event
15-12-2017 Test event

++ make sure you agree with your party what's what, as, for instance, some
will say "second Friday of September 2017 is 15th", while others say to be
"8th"… and so on. Sorry, I know it's ugly. ;-)

'HTH


Re: Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Flavio S. Glock
please check the week_start_day parameter, I believe it will fix
this problem:

http://search.cpan.org/~fglock/DateTime-Event-Recurrence-0.18/lib/DateTime/Event/Recurrence.pm#The_%22week_start_day%22_Parameter

Em terça-feira, 28 de fevereiro de 2017, Andrew Martin 
escreveu:

> Hi,
>
> The following code produces (for me) this output.. ( dd-mm-)
>
> 13-01-2017 Test event
> 17-02-2017 Test event
> 17-03-2017 Test event
> 14-04-2017 Test event
> 12-05-2017 Test event
> 16-06-2017 Test event
> 14-07-2017 Test event
> 18-08-2017 Test event
> 15-09-2017 Test event
> 13-10-2017 Test event
> 17-11-2017 Test event
> 15-12-2017 Test event
>
> Some of these dates are correct e.g. 14-04-2017 is the second Friday of
> April 2017,
>
> however 17-02-2017 is the Third Friday, the expected result is 10-02-2017
>
>
> I would appreciate any help, I'm baffled :-)
>
>
> Kind regards,
>
>
> Andrew Martin
>
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use DateTime;
> use DateTime::Event::Recurrence;
> my $year=2017;
> my $event="Test event";
>
> my $dt1 = DateTime->new( year   => $year,
>  month  => 1,
>  day=> 1,
>);
>
> my $dt2 = DateTime->new( year   => $year,
>  month  => 12,
>  day=> 31,
>);
>
> my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days =>5
> );
> my @days = $set->as_list( start => $dt1, end => $dt2 );
>
> foreach my $d (@days){
> print $d->dmy . " $event\n";
> }
>
>


Recurring set does not correctly calculate dates for second Friday of the month.

2017-03-01 Thread Andrew Martin

Hi,

The following code produces (for me) this output.. ( dd-mm-)

13-01-2017 Test event
17-02-2017 Test event
17-03-2017 Test event
14-04-2017 Test event
12-05-2017 Test event
16-06-2017 Test event
14-07-2017 Test event
18-08-2017 Test event
15-09-2017 Test event
13-10-2017 Test event
17-11-2017 Test event
15-12-2017 Test event

Some of these dates are correct e.g. 14-04-2017 is the second Friday of 
April 2017,


however 17-02-2017 is the Third Friday, the expected result is 10-02-2017


I would appreciate any help, I'm baffled :-)


Kind regards,


Andrew Martin


#!/usr/bin/perl

use strict;
use warnings;

use DateTime;
use DateTime::Event::Recurrence;
my $year=2017;
my $event="Test event";

my $dt1 = DateTime->new( year   => $year,
 month  => 1,
 day=> 1,
   );

my $dt2 = DateTime->new( year   => $year,
 month  => 12,
 day=> 31,
   );

my $set = DateTime::Event::Recurrence->monthly( weeks => 2, days =>5 );
my @days = $set->as_list( start => $dt1, end => $dt2 );

foreach my $d (@days){
print $d->dmy . " $event\n";
}