Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Determine if a given DateTime is a member of a DateTime::Set

by fglock (Vicar)
on May 15, 2013 at 09:27 UTC ( #1033647=note: print w/replies, xml ) Need Help??

in reply to Determine if a given DateTime is a member of a DateTime::Set

The problem is in the truncate('to' => 'day') step. What you need is to truncate to "14th day", which is not that easy.

Do you think you can do with DateTime::Event::Recurrence or DateTime::Event::ICal? These modules provide a large set of recurrence modes.

#!/usr/bin/perl use strict; use warnings; use DateTime::Event::Recurrence; print "DateTime::Event::Recurrence: ", $/; my $start = DateTime->today(); my $biweekly = DateTime::Event::Recurrence->daily( interval => 14, start => $start, ); print 'TESTING whether Date is in set...', $/; my $date = DateTime->today(); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/; $date->add('days' => 7); print $biweekly->contains($date), ' ', $date->ymd, $/;
DateTime::Event::Recurrence: TESTING whether Date is in set... 1 2013-05-15 0 2013-05-22 1 2013-05-29 0 2013-06-05 1 2013-06-12 0 2013-06-19

Replies are listed 'Best First'.
Re^2: Determine if a given DateTime is a member of a DateTime::Set
by vagabonding electron (Chaplain) on May 15, 2013 at 16:36 UTC

      DateTime::Set is fine to use, but calendar math has these mysterious details, and recurrence specifications are particularly hard.

      The specialised "DateTime::Event" subclasses can make life easier. DateTime::Event::Sunrise and DateTime::Event::Cron are other nice examples.

      About the endpoint that makes it work: when both endpoints of the set are known, it triggers an optimisation that pre-calculates the whole set. The internal representation then changes to a list. This "fixes" the problem, because no further recurrence math is involved.

        Thank you for your time and of course for the modules (I should mention this earlier).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033647]
[oakbox]: Anyone else having difficulty looking at
[oakbox]: I keep getting a proxy error.
[marto]: try http://metacpan. org/
[marto]: I can't access search.cpan right now either. I prefer the metacpan search and general formatting anyway. Also it seems faster
[oakbox]: Yeah, the front page of uses now for search results
[oakbox]: but there are a billion links 'out there' linking to
[marto]: yep :)
[Discipulus]: being her marto, can you explain what "Par for the course I'm afraid." means?
Discipulus here..

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-07-26 10:10 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (388 votes). Check out past polls.