Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Finding the dates for the reminder mail system

by ikegami (Patriarch)
on Nov 08, 2008 at 20:33 UTC ( [id://722431]=note: print w/replies, xml ) Need Help??


in reply to Finding the dates for the reminder mail system

Isn't this as simple as running the script every Wed and Fri (say as a cron job), and sending an email for every due date that's [0..14] (or [1..14]*) days away from today?

For the last reminder,
On Wednesdays, check if the due date is [1..2] (or [0..1]**) days away from today.
On Fridays, check if the due date is [1..5] (or [0..4]**) days away from today.

* — If you don't want notifications on the due date.
** — If you want the special notification be to sent before the due date.

Update: Untested code:

use Date::Calc qw( Day_of_Week Delta_Days Today ); use List::Util qw( min ); my ($ty,$tm,$td) = Today(); for (...{ tasks }...) { my ($dy,$dm,$dd) = ...{ due date of task }...; my $delta = Delta_Days($ty,$tm,$td, $dy,$dm,$dd); next if $delta < 0; # Don't care about past-due tasks. next if $delta > 14; # Don't care about due dates that far ahead. my $ddow = Day_of_Week($dy,$dm,$dd); # $cc_super is true if this is the last # Wednesday or Friday before the due date. my $days_to_wed = (3 - $ddow) % 7; my $days_to_fri = (5 - $ddow) % 7; my $days_to_next = min $days_to_wed, $days_to_fri; my $cc_super = ( $delta > 0 && $delta <= $days_to_next ); send_reminder($cc_super, ...); }

Update: Fixed typo in code resulting in the error mentioned in reply.

Replies are listed 'Best First'.
Re^2: Finding the dates for the reminder mail system
by d-evil (Novice) on Nov 09, 2008 at 14:57 UTC
    hi ikegami,

    the code for finding the last wednesday or friday does not work for the following scenario

    due_date = Dec 15 2008 (Monday) Today_date = Dec 12 2008 (Friday) $delta = 3 $days_to_wed = 2, $days_to_fri = 4 $days_to_next = 2 $delta > 0 but $delta is not <= $days_to_next.
      Not using use strict; and use warnings; is bad enough. Asking why code doesn't work without turning them on and fixing the errors is even worse. It would have immediately pointed out why $days_to_wed and $days_to_fri contain the wrong values.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://722431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-18 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found