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

Date::Set not returning correct results.

by the_0ne (Pilgrim)
on Sep 06, 2003 at 14:47 UTC ( #289467=perlquestion: print w/ replies, xml ) Need Help??
the_0ne has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I'm having a problem with the Date::Set module. I need to work with recurrence and pretty detailed recurrence also. I've googled all kinds of searches on recurrence modules and the most advanced, so far I've found is Date::Set.

Now to my problem. I've found a few examples, but whenever I run them they never come up to what the example says it should. I tried Example 3 here... Example 3 (Not example 2.)
use Date::Set; # when the event occurs: every friday. my $set = Date::Set->event ( rule => 'FREQ=WEEKLY;BYDAY=FR'); # in what period we want occurences: december 2002 my $period = Date::Set->period (time => ['20021201', '20021231']); my @occurs = $set->during (at => $period)->list; print "occurences on ", join (" ,", @occurs), "\n";
I get this...
occurences on

There is nothing in the array when clearly there should be. That's the first problem. I've also tried a few small examples like this one...
use Date::Set; $a = Date::Set->event(); $a->event( rule => 'FREQ=MONTHLY;INTERVAL=2;' ); $a->event( start => '20030801', end => '20031201' ); @list = $a->list; foreach (@list) { print "$_\n"; }
This prints off...
19700820T200641Z

I've tried other examples like this...
$a = Date::Set->event( rule => 'FREQ=YEARLY;INTERVAL=2' ); $a->during( start => '20030801', end => '20200801' ); print $a . "\n";
This prints off...
19700820T200641Z

Am I missing something? Is there some kind of a time zone setting I need to make or am I not using the module correctly? A few examples I've used came right from the cpan module documentation. Also, Date::Set installed through cpan correctly, and all it's dependencies. I can duplicate these exact results on my small linux machine here at home and one of our linux servers at the office.

Thanks for any help you can provide.

Comment on Date::Set not returning correct results.
Select or Download Code
Re: Date::Set not returning correct results.
by asarih (Hermit) on Sep 06, 2003 at 17:14 UTC
    I get the same result on Solaris 9. I'm a little baffled by it, too, because at line 10, right before the print statement, $period has this structure:
    DB<1> x $period 0 Date::Set=HASH(0x5ef384) 'dtstart' => undef 'fixtype' => 1 'list' => ARRAY(0x1131ac) 0 HASH(0x606130) 'a' => Date::Set::ICal=HASH(0x605d94) 'epoch' => 20021201 'b' => Date::Set::ICal=HASH(0x497a74) 'epoch' => 20021231 'open_begin' => 0 'open_end' => 0 'tolerance' => 0 'type' => 'Date::Set::ICal' 'wkst' => 'MO'
    But if I print $period, I get
    DB<2> p $period [19700820T172641Z..19700820T172711Z]
    I suggest contacting the developer(s). I also noticed that one of the dependent modules warned about the API being in flux, so there is a possibility that changes in the API broke Date::Set. You might want to try older versions of those.

    Good luck.

      Thanks for the info. Maybe I'll post it to the comp.lang.perl newsgroup once and see what they say. Maybe the developers monitor that newsgroup. If not, I'll email Flavio.

      Thanks again.

      While I'm at it, does anybody know of any other recurrence modules that are pretty advanced? Our recurrence handles yearly, daily, weekly, weekday a month, date a month and a few others. I have seen others, but they were limited. That's what I liked about the Date::Set module.
Re: Date::Set not returning correct results.
by fglock (Vicar) on Sep 07, 2003 at 01:12 UTC

    The examples are wrong - you must specify 'Z' at the end of the dates (meaning UTC time):

    use Date::Set; $a = Date::Set->event(); $a->event( rule => 'FREQ=MONTHLY;INTERVAL=2;' ); $a->event( start => '20030801Z', end => '20031201Z' ); @list = $a->list; foreach (@list) { print "$_\n"; } # output 20030801Z 20031001Z 20031201Z

    I would recommend you to use the DateTime::Event::ICal or DateTime::Event::Recurrence modules instead, because these have a larger user base, and thus have been much better tested.

      Thanks for the reply and the code fix.

      The reason I chose the Date::Set module is it looks like the rule argument can use pretty much anything in the RFC. That doesn't look to be the case for the other 2 modules. (Of course this opinion comes from looking quickly over the documentation this weekend.) I will definitely do a more exhaustive search and test on Monday.
      However, I am looking over the 2 you mention and I'm thinking they just might fit what I need. We'll see.

      Thanks again for the reply.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://289467]
Approved by valdez
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2014-09-18 22:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (125 votes), past polls