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
;
31 our @ISA = ("EmailReminder::Event", "Exporter");
32 #our @EXPORT = qw(get_name valid_day);
34 # XML tags, attributes and values
36 my $NAME_TAG = 'name';
38 # Global date variables
39 my $current_time = ParseDate
("now");
40 my $current_date = ParseDate
(UnixDate
($current_time, "\%x"));
41 my $current_dayofweek = UnixDate
($current_time, "\%w");
45 return $this->get_type . ':' . $this->get_id . ') ' . $this->get_name . ' - ' . $this->get_day;
48 # Hard-coded value for this event's type (class method)
54 # Number of fields this event adds to its parent (class method)
57 return EmailReminder
::Event
->get_nb_fields() + 2;
63 my $name = EmailReminder
::Utils
::get_node_value
($this->{XML_NODE
}, $NAME_TAG);
69 my ($this, $new_value) = @_;
70 return EmailReminder
::Utils
::set_node_value
($this->{XML_NODE
}, $NAME_TAG, $new_value);
77 if (!Scalar
::Util
::looks_like_number
($new_value)) {
78 # Try to parse as a string
79 my $day = UnixDate
(ParseDate
($new_value), "\%w");
83 $new_value = 7; # Default: Sunday
87 if ($new_value > 7 or $new_value < 1) {
88 # Default to Sunday for out of range dates (since zero is
99 my $day = EmailReminder
::Utils
::get_node_value
($this->{XML_NODE
}, $DAY_TAG);
100 return valid_day
($day);
105 my ($this, $new_value) = @_;
106 return EmailReminder
::Utils
::set_node_value
($this->{XML_NODE
}, $DAY_TAG, valid_day
($new_value));
112 return $this->get_name();
120 my $first_name = shift;
123 my $when = $this->{"WHEN"};
124 my $name = $this->get_name();
126 my $message = <<MESSAGEEND;
129 I just want to remind you of the following event $when:
137 # Returns 1 if the event will occur in X days (X is a param)
141 my $modifier = shift;
143 # Apply the modifier to the event date
144 my $modified_day = $this->get_day();
145 return 0 unless $modified_day;
148 $modified_day -= $modifier;
149 while ($modified_day > 7) {
152 while ($modified_day < 1) {
157 if ($current_dayofweek == $modified_day) {