Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [klauslovgreen] Date challange

Quote Reply
Re: [klauslovgreen] Date challange In reply to
Wow... that's pretty awesome, actually.

If you have Date::Calc loaded, and some servers do, you can access the features you want from the recipies area at the end of the module:

Code:
12)
How can I send a reminder to members of a group on the day before a meeting which occurs every first Friday of a month?

use Date::Calc qw( Today Date_to_Days Add_Delta_YMD
Nth_Weekday_of_Month_Year );
($year,$month,$day) = Today();
$tomorrow = Date_to_Days($year,$month,$day) + 1;
$dow = 5; # 5 = Friday
$n = 1; # 1 = First of that day of week
$meeting_this_month = Date_to_Days(
Nth_Weekday_of_Month_Year($year,$month,$dow,$n) );
($year,$month,$day) = Add_Delta_YMD($year,$month,$day, 0,1,0);
$meeting_next_month = Date_to_Days(
Nth_Weekday_of_Month_Year($year,$month,$dow,$n) );
if (($tomorrow == $meeting_this_month) ||
($tomorrow == $meeting_next_month))
{
# Send reminder e-mail!
}

This should actually be the same for the module you pointed out, as well as two others I've found which were perl-only rewrites of date calc.

The major advantage of the module you pointed out above, is that it actually comes with the modules and example code to write out calendars (which saved me loads of time .... <G>)

Let me know again what you need, and how you want to do it.

I think what you want is a tag:

<%date_next_event%>

The global would simply need to get the current month, and return a formatted date string.

Code:
sub {
## not actually tested, but should work.
## takes into account the meeting date for the current month may have already passed.
##
use Date::Calc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);
my ($year,$month,$day) = Today();
my $dow = 2; # 2 = Tuesday
my $n = 3; # 3 = Third of that day of week

my ($year1,$month1,$day1) = Nth_Weekday_of_Month_Year($year,$month,$dow,$n); ## we want to capture the values for this month
my $meeting_this_month = Date_to_Days($year1,$month1,$day1); ## then format a date string

if ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) ) { ## if the meeting has not happened this month
return ( $meeting_this_month); ## this should insert the date at the point you called the subroutine
} else {
## return the date for next month's meeting.
my ($year2,$month2,$day2) = Add_Delta_YMD($year1,$month1,$day1, 0,1,0); ## we have to add a month to the current meeting date
my $meeting_next_month = Date_to_Days( Nth_Weekday_of_Month_Year($year2,$month2,$dow,$n) ); ## adjust for day of week/week of month
return ( $meeting_next_month); ## this should insert the date at the point you called the subroutine
}
}


If you don't have Date::Calc loaded, and can't get CPAN to compile it, you can try Date::Pcalc a pure perl replacement, from http://www.catcode.com/date/pcalc.html

The usage should be the same.

As an after thought, you could modify it to do something like this, as well:
Code:
....

if ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) ) { ## if the meeting has not happened this month
return ( $meeting_this_month); ## this should insert the date at the point you called the subroutine
} elsif ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) == '0' ) { ## if the meeting is today
return ( 'Today' );
} else {
## return the date for next month's meeting.
my ($year2,$month2,$day2) = Add_Delta_YMD($year1,$month1,$day1, 0,1,0); ## we have to add a month to the current meeting date
my $meeting_next_month = Date_to_Days( Nth_Weekday_of_Month_Year($year2,$month2,$dow,$n) ); ## adjust for day of week/week of month
return ( $meeting_next_month); ## this should insert the date at the point you called the subroutine
}



...


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.

Last edited by:

pugdog: Apr 22, 2003, 7:49 PM
Subject Author Views Date
Thread Date challange klauslovgreen 9392 Apr 20, 2003, 3:41 AM
Thread Re: [klauslovgreen] Date challange
pugdog 9253 Apr 22, 2003, 2:57 PM
Thread Re: [pugdog] Date challange
klauslovgreen 9265 Apr 22, 2003, 3:30 PM
Thread Re: [klauslovgreen] Date challange
pugdog 9244 Apr 22, 2003, 6:59 PM
Thread Re: [pugdog] Date challange
klauslovgreen 9277 Apr 22, 2003, 10:12 PM
Thread Re: [klauslovgreen] Date challange
pugdog 9253 Apr 23, 2003, 3:58 AM
Thread Re: [pugdog] Date challange
klauslovgreen 9241 Apr 23, 2003, 4:00 AM
Thread Re: [klauslovgreen] Date challange
pugdog 9214 Apr 23, 2003, 6:27 AM
Thread Re: [pugdog] Date challange
klauslovgreen 9188 Apr 24, 2003, 12:59 PM
Post Re: [klauslovgreen] Date challange
webmaster33 9202 Apr 24, 2003, 1:38 PM
Thread Re: [klauslovgreen] Date challange
Paul 9179 Apr 24, 2003, 1:53 PM
Thread Re: [Paul] Date challange
klauslovgreen 9174 Apr 24, 2003, 4:08 PM
Thread Re: [klauslovgreen] Date challange
Paul 9201 Apr 24, 2003, 4:10 PM
Thread Re: [Paul] Date challange
klauslovgreen 9169 Apr 24, 2003, 4:16 PM
Post Re: [klauslovgreen] Date challange
Paul 9152 Apr 24, 2003, 4:26 PM
Thread Re: [klauslovgreen] Date challange
webmaster33 9189 Apr 24, 2003, 4:30 PM
Thread Re: [webmaster33] Date challange
klauslovgreen 9175 Apr 24, 2003, 4:40 PM
Post Re: [klauslovgreen] Date challange
webmaster33 9130 Apr 24, 2003, 4:55 PM
Thread Re: [klauslovgreen] Date challange
pugdog 9182 Apr 24, 2003, 9:02 PM
Thread Re: [pugdog] Date challange
pugdog 9141 Apr 24, 2003, 9:15 PM
Thread Re: [pugdog] Date challange
Paul 9131 Apr 25, 2003, 2:01 AM
Post Re: [Paul] Date challange
pugdog 9112 Apr 25, 2003, 7:09 PM