develooper Front page | perl.datetime | Postings from March 2017

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

Thread Next
From:
Andrew Martin
Date:
March 2, 2017 00:51
Subject:
Recurring set does not correctly calculate dates for second Fridayof the month.
Message ID:
7b672f9a-110e-80e2-5aca-019f7e8d9f57@marnick.com
Hi,

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

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";
         }


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About