in reply to The next third tuesday of the month

#!/usr/bin/perl use strict; use warnings 'all'; use Date::Manip; foreach my $year (2002 .. 2004) { my @dates = ParseRecur "3rd tuesday of every month in $year"; foreach my $date (@dates) { print UnixDate $date => "F\n"; } } __END__ Tuesday, January 15, 2002 Tuesday, February 19, 2002 Tuesday, March 19, 2002 Tuesday, April 16, 2002 Tuesday, May 21, 2002 Tuesday, June 18, 2002 Tuesday, July 16, 2002 Tuesday, August 20, 2002 Tuesday, September 17, 2002 Tuesday, October 15, 2002 Tuesday, November 19, 2002 Tuesday, December 17, 2002 Tuesday, January 21, 2003 Tuesday, February 18, 2003 Tuesday, March 18, 2003 Tuesday, April 15, 2003 Tuesday, May 20, 2003 Tuesday, June 17, 2003 Tuesday, July 15, 2003 Tuesday, August 19, 2003 Tuesday, September 16, 2003 Tuesday, October 21, 2003 Tuesday, November 18, 2003 Tuesday, December 16, 2003 Tuesday, January 20, 2004 Tuesday, February 17, 2004 Tuesday, March 16, 2004 Tuesday, April 20, 2004 Tuesday, May 18, 2004 Tuesday, June 15, 2004 Tuesday, July 20, 2004 Tuesday, August 17, 2004 Tuesday, September 21, 2004 Tuesday, October 19, 2004 Tuesday, November 16, 2004 Tuesday, December 21, 2004

Abigail

Replies are listed 'Best First'.
Re: Re: The next third tuesday of the month
by Juerd (Abbot) on Nov 13, 2002 at 19:06 UTC

    Before using Date::Tie, I played (struggled) with Date::Manip's ParseRecur, but I didn't know, and was unable to find with Google, in which form the start and end times were supposed to be. Because I didn't want a list, just the next one, this was important.

    The module offered no clear examples. The synopsis only lists the available functions with their arguments, and the in the examples it is not clear in what format the date should be. Maybe it is somewhere in the documentation, but I didn't feel like reading this 41 (A4) page monster.

    Thanks for the post, though.

    - Yes, I reinvent wheels.
    - Spam: Visit eurotraQ.
    

      #!/usr/bin/perl use strict; use warnings 'all'; use Date::Manip; my $month = UnixDate ParseDate ("today"), "%B %Y"; my $date = ParseDate "3rd tuesday in $month"; if ($date lt ParseDate ("now")) { my $month = UnixDate ParseDate ("next month"), "%B %Y"; $date = ParseDate "3rd tuesday in $month"; } print UnixDate $date => "%F\n";

      The documentation of the module comes with lots of examples (not only the ones in the Examples section). The routines are discussed into detail in the Routines section, taking most of the 41 page documentation....

      Abigail

      I realize this is an old post to be replying to, but hit it when messing with &ParseRecur() and thought I'd chime in.

      The thing to keep in mind about Date::Manip is that it almost doesn't *care* what format you hand it dates. If you can parse it in your head to come out to a legitimate date, chances are good it can too. Admittedly you can get in a lot of trouble this way, but for amusement some time, take a form with a text input for a date field, release it to the general public and then just parse that field with Date::Manip; log results however you like.

      When I did this, I was astonished by the ludicrous number of what I would have considered to be bogus dates that Date::Manip did something intelligent with. It might have returned a partial date at times (and considering your own circumstances, this might be a very bad thing), but it successfully handled *far* more than I had hoped for.

      Yes, it's a beast of a module... it's still getting my vote for basic prototyping and all but the most speed-critical code. It's just too keen.