Skip to content

Commit

Permalink
Time::R: add another example to synopsis
Browse files Browse the repository at this point in the history
  • Loading branch information
pink-mist committed Nov 4, 2016
1 parent 74c5e3f commit b2239a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/Time/R.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ use Function::Parameters qw/ :strict /;
# "2017-01-31T00:00:00Z"
my $next = $r->next();
# print out the first thursday of every month until January 2017
my $m = Time::R->new(Time::C->new(2016), months => 1, end => Time::C->new(2017));
while (my $n = $m->next()) {
$n->day++ while $n->day_of_week != 4;
print $n->strftime('%A %d %B %Y') . "\n"; #ex: Thursday 4 February 2016
}
=head1 DESCRIPTION
Convenient ways of handling recurrences.
Expand Down
23 changes: 22 additions & 1 deletion t/01-synopsis.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use utf8;

use Test::More;

plan tests => 33;
plan tests => 46;

use Time::C;
use Time::D;
Expand Down Expand Up @@ -97,4 +97,25 @@ is ($until[3], "2016-12-31T00:00:00Z", 'Fourth time in @until correct');

is ($r->next(), "2017-01-31T00:00:00Z", "next after until correct");

my $m = Time::R->new(Time::C->new(2016), months => 1, end => Time::C->new(2017));
my @res;
while (my $n = $m->next()) {
$n->day++ while $n->day_of_week != 4;
push @res, $n->strftime(format => '%A %-d %B %Y'); #ex: Thursday 4 February 2016
}

is (@res, 12, "right number of thursdays in result");
is ($res[0], "Thursday 4 February 2016", "first thursday correct");
is ($res[1], "Thursday 3 March 2016", "second thursday correct");
is ($res[2], "Thursday 7 April 2016", "third thursday correct");
is ($res[3], "Thursday 5 May 2016", "fourth thursday correct");
is ($res[4], "Thursday 2 June 2016", "fifth thursday correct");
is ($res[5], "Thursday 7 July 2016", "sixth thursday correct");
is ($res[6], "Thursday 4 August 2016", "seventh thursday correct");
is ($res[7], "Thursday 1 September 2016", "eigth thursday correct");
is ($res[8], "Thursday 6 October 2016", "ninth thursday correct");
is ($res[9], "Thursday 3 November 2016", "tenth thursday correct");
is ($res[10], "Thursday 1 December 2016", "eleventh thursday correct");
is ($res[11], "Thursday 5 January 2017", "twelfth thursday correct");

#done_testing;

0 comments on commit b2239a2

Please sign in to comment.