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
::WeeklyEvent
;
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_dayofweek = UnixDate
($current_time, "\%w");
42 return $self->get_type . ':' . $self->get_id . ') ' . $self->get_name . ' - ' . $self->get_day;
45 # Hard-coded value for this event's type (class method)
51 # Number of fields this event adds to its parent (class method)
55 return $self->SUPER::get_nb_fields
() + 2;
60 my ($class, $new_value) = @_;
62 if (!Scalar
::Util
::looks_like_number
($new_value)) {
63 # Try to parse as a string
64 my $day = UnixDate
(ParseDate
($new_value), "\%w");
68 $new_value = 7; # Default: Sunday
72 if ($new_value > 7 or $new_value < 1) {
73 # Default to Sunday for out of range dates (since zero is
84 return $self->get_name();
92 my $when = $self->{"WHEN"};
93 my $name = $self->get_name();
95 my $message = <<"MESSAGEEND";
96 I just want to remind you of the following event $when:
104 # Returns 1 if the event will occur in X days (X is a param)
108 my $modifier = shift;
110 # Apply the modifier to the event date
111 my $modified_day = $self->get_day();
112 return 0 unless $modified_day;
115 $modified_day -= $modifier;
116 while ($modified_day > 7) {
119 while ($modified_day < 1) {
124 if ($current_dayofweek == $modified_day) {