Gossamer Forum
Quote Reply
Date challange
Hi,

We have an event the last tuesday every month - is it possible to make a global that list the date of the next event automatically?

Smile
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Hmmm... check out CPAN and see if a date package exists that can pick "Last Tues of the month" or "frist tuesday of the month"

If it does, I can hack the global easily <G>


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Date challange In reply to
Will this do the trick?
http://www.ajackson.org/software/plotcalendar/

http://www.ameinfo.com
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
Quote Reply
Re: [pugdog] Date challange In reply to
Thanks Pugdog - but I could not make it work - got a load of errors...

I guess GT::Date is not an option?

Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
The problem is Nth_Weekday_of_Month_Year

That is the key routine to picking off the day, and that is part of the Date::Calc routines. It might be able to be pulled out of the Pcalc module, depending on dependencies, but the real goal in this, is to create a utility that is portable, and doesn't reinvent the wheel.

Where were the errors? trying to install Date::Calc or Date::Pcalc, or in running the above subroutine? I'll grant the subroutine may have errors <G> I didn't get to test it, as I don't think I have Date::Calc loaded on my current test machine. I can try later today, if that was the problem.

If you can't load either of those date modules... <sigh> it's a bigger job, and means reinventing the wheel.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Date challange In reply to
It seems the problem is that I can't load the modules.. :-(

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Ok, try this.

Make a directory Date in your Plugins area.

Upload the Date::Pcalc.pm module to that directory (ascii)

Edit the top so that it says Package Plugins::Date::Pcalc

make the same change to the subroutine, use Plugins::Date::Pcalc

See if that works. I can't figure out what the .t files are in that archive, but they seem to be only examples.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Date challange In reply to
Hi,

Got this error now:
Undefined subroutine &Links::Today called at (eval 1464) line 5.

Any ideas?
Klaus

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Likely you did not load the proper module, so it misses the Today function...

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [klauslovgreen] Date challange In reply to
You need to change:

Code:
use Date::Calc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);

...to...

Code:
require Date::Calc;
import Date::Calc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);

Then change all subroutine calls for Date::Calc functions so they include the package name, so for example:

Code:
my ($year,$month,$day) = Today();

...would become:

Code:
my ($year,$month,$day) = Date::Calc::Today();

Last edited by:

Paul: Apr 24, 2003, 1:54 PM
Quote Reply
Re: [Paul] Date challange In reply to
Still get an error ...

Error:
Code:
Undefined subroutine &Links::DeltaDays called at (eval 57) line 11.

Pcalc.pm is located at /admin/Plugins/Date

My Global as it looks now:

Code:
sub {

require Plugins::Date::Pcalc;
import Plugins::Date::Pcalc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);

my ($year,$month,$day) = Plugins::Date::Pcalc::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);
my $meeting_this_month = Date_to_Days($year1,$month1,$day1);
if ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) ) {
return ( $meeting_this_month);
} elsif ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) == '0' ) {
return ( 'Today' );
} else {
my ($year2,$month2,$day2) = Add_Delta_YMD($year1,$month1,$day1, 0,1,0);
my $meeting_next_month = Date_to_Days( Nth_Weekday_of_Month_Year($year2,$month2,$dow,$n) );
return ( $meeting_next_month);
}
}

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Quote:
Then change all subroutine calls for Date::Calc functions so they include the package name,
Cool
Quote Reply
Re: [Paul] Date challange In reply to
What did I miss?

Code:
sub {

require Plugins::Date::Pcalc;
import Plugins::Date::Pcalc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);

my ($year,$month,$day) = Plugins::Date::Pcalc::Today();
my $dow = 2; # 2 = Tuesday
my $n = 3; # 3 = Third of that day of week
my ($year1,$month1,$day1) = Plugins::Date::Pcalc::Nth_Weekday_of_Month_Year($year,$month,$dow,$n);
my $meeting_this_month = Plugins::Date::Pcalc::Date_to_Days($year1,$month1,$day1);
if ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) ) {
return ( $meeting_this_month);
} elsif ( DeltaDays ($year,$month,$day, $year1,$month1,$day1) == '0' ) {
return ( 'Today' );
} else {
my ($year2,$month2,$day2) = Plugins::Date::Pcalc::Add_Delta_YMD($year1,$month1,$day1, 0,1,0);
my $meeting_next_month = Plugins::Date::Pcalc::Date_to_Days( Nth_Weekday_of_Month_Year($year2,$month2,$dow,$n) );
return ( $meeting_next_month);
}
}

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Two occurances of Delta_Days
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Change all DeltaDays to Delta_Days in the global.
Depends what is the original function name used in the module Plugins::Date::Pcalc.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [webmaster33] Date challange In reply to
That helped - thanks!

It returns:

'731320' ??? - does not look like the date of the coming Tuesday

the global ended up looking like:

Code:

sub {

require Plugins::Date::Pcalc;
import Plugins::Date::Pcalc qw( Today Date_to_Days Add_Delta_YMD Nth_Weekday_of_Month_Year Delta_Days);

my ($year,$month,$day) = Plugins::Date::Pcalc::Today();
my $dow = 2; # 2 = Tuesday
my $n = 3; # 3 = Third of that day of week
my ($year1,$month1,$day1) = Plugins::Date::Pcalc::Nth_Weekday_of_Month_Year($year,$month,$dow,$n);
my $meeting_this_month = Plugins::Date::Pcalc::Date_to_Days($year1,$month1,$day1);
if ( Plugins::Date::Pcalc::Delta_Days ($year,$month,$day, $year1,$month1,$day1) ) {
return ( $meeting_this_month);
} elsif ( Plugins::Date::Pcalc::Delta_Days ($year,$month,$day, $year1,$month1,$day1) == '0' ) {
return ( 'Today' );
} else {
my ($year2,$month2,$day2) = Plugins::Date::Pcalc::Add_Delta_YMD($year1,$month1,$day1, 0,1,0);
my $meeting_next_month = Plugins::Date::Pcalc::Date_to_Days( Plugins::Date::Pcalc::Nth_Weekday_of_Month_Year($year2,$month2,$dow,$n) );
return ( $meeting_next_month);
}
}

http://www.ameinfo.com
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Glad it helped!

However I don't know Date::Pcalc, Paul will likely help in the result problem.

Best regards,
Webmaster33


Paid Support
from Webmaster33. Expert in Perl programming & Gossamer Threads applications. (click here for prices)
Webmaster33's products (upd.2004.09.26) | Private message | Contact me | Was my post helpful? Donate my help...
Quote Reply
Re: [klauslovgreen] Date challange In reply to
Hi,

really simple....

Add

use lib 'path/to/admin' to the top of the subroutine.

Then, use this subroutine, I mis-interpreted the date calls:

Code:
sub {
## not actually tested, but should work.
## takes into account the meeting date for the current month may have already passed.
##
use lib '/path/to/admin';
use Plugins::Date::Pcalc qw( Today Date_to_Text_Long 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_Text_Long($year1,$month1,$day1);
## print "Meeting this month is: (early) ", $meeting_this_month ;
## then format a date string
if ( Delta_Days ($year,$month,$day, $year1,$month1,$day1) >= 0) {
## print "meeting is in ", Delta_Days ($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.
## print "meeting is in ", Delta_Days ($year,$month,$day, $year1,$month1,$day1);
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_Text_Long( 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
}
}

This *IS* working on my site.


You *might* be able to use:

use lib $CFG->{'admin_root_path'};

but I haven't tested this. ... just tested it, it does work, and will make the subroutine more generalized.


PUGDOG� Enterprises, Inc.

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

Last edited by:

pugdog: Apr 24, 2003, 9:07 PM
Quote Reply
Re: [pugdog] Date challange In reply to
Paul,

Can you suggest why:

if ( Delta_Days ($year,$month,$day, $year1,$month1,$day1) >= 0)

has to be used, rather than just,

if ( Delta_Days ($year,$month,$day, $year1,$month1,$day1) )

for the test? I thought that if a value was negative, like -9 in this case (for today) that this test would _FAIL_ . It doesn't. A value of -9 evaluated as "True" in the 'if' clause.

Since Delta_Days returns a value, isn't that what is used rather than a "success/fail" on the function itself?


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Date challange In reply to
A false value is 0 or undefined or something empty like an empty string. Something negative, although may seem to be false based on human interpretation, is still an actual value and so is true.

The following would be false...

if (0) {
if (undef) {
if ("") {
if (qw//) {

...but -9 is a real value and so must be true.
Quote Reply
Re: [Paul] Date challange In reply to
Hi,

I thought anything negative was a "false" value as well, in a boolean. -1 for example. That the only way to get a true response was to evaluate positive. Anything 0 or negative was 'false'.


PUGDOG� Enterprises, Inc.

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