1 # This file is part of Email-Reminder.
3 # Email-Reminder is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License as
5 # published by the Free Software Foundation; either version 3 of the
6 # License, or (at your option) any later version.
8 # Email-Reminder is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 # General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with Email-Reminder; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 package EmailReminder
::MonthlyEvent
;
22 use overload
'""' => \
&str
;
27 use EmailReminder
::Event
;
28 use EmailReminder
::Utils
;
30 use base
qw(EmailReminder::Event);
33 __PACKAGE__
->mk_accessors(qw(day));
35 # Global date variables
36 my $current_time = ParseDate
("now");
37 my $current_date = ParseDate
(UnixDate
($current_time, "\%x"));
38 my $current_month = UnixDate
($current_time, "\%m");
39 my $current_year = UnixDate
($current_time, "\%Y");
43 return $self->get_type . ':' . $self->get_id . ') ' . $self->get_name . ' - ' . $self->get_day;
46 # Hard-coded value for this event's type (class method)
52 # Number of fields this event adds to its parent (class method)
56 return $self->SUPER::get_nb_fields
() + 2;
61 my ($class, $new_value) = @_;
63 if (!Scalar
::Util
::looks_like_number
($new_value)) {
67 # Make sure the value is a valid number
68 if ($new_value > 31) {
70 } elsif ($new_value < 1) {
77 sub get_current_occurence_date
79 my ($self, $modifier) = @_;
81 my $day = $self->get_day();
84 # Set the day of the month where the event occurs, make sure the date is valid
85 # (e.g. fix-up for event on the 31st when the month has only 30 days)
86 my $current_occurence_date = ParseDate
("$current_year-$current_month-$day");
87 while (UnixDate
($current_occurence_date, "\%d") != $day) {
89 $current_occurence_date = ParseDate
("$current_year-$current_month-$day");
92 my $modified_date = $current_occurence_date;
94 if ($modifier >= $day) {
95 # We are warning about an event in a few days, past the end of the current month
96 $modified_date = DateCalc
($modified_date, " + 1 month");
98 $modified_date = DateCalc
($modified_date, " - $modifier days");
101 return $modified_date;
107 return $self->get_name();
115 my $when = $self->{"WHEN"};
116 my $name = $self->get_name();
118 my $message = <<"MESSAGEEND";
119 I just want to remind you of the following event $when:
127 # Returns 1 if the event will occur in X days (X is a param)
131 my $modifier = shift;
133 # Apply the modifier to the event date
134 my $current_occurence_date = $self->get_current_occurence_date($modifier);
135 return 0 unless $current_occurence_date;
137 my $tomorrow = DateCalc
($current_date, " + 1 day");
138 if (Date_Cmp
($current_date, $current_occurence_date) == 0) {
140 } elsif (Date_Cmp
($current_date, $current_occurence_date) < 0 and
141 Date_Cmp
($tomorrow, $current_occurence_date) > 0) {
142 # e.g. if today is the 30, the reminder is on the 31st and tomorrow is the 1st