collect-reminders also contains the year number
[email-reminder.git] / EmailReminder / Utils.pm
blob9eded839da49a0742801717f1a721c5cd6442475
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
16 # 02110-1301, USA.
18 package EmailReminder::Utils;
20 # Utility subroutines for the Email-Reminder program
22 use strict;
23 use XML::DOM;
25 our $VERSION = '0.7.5';
26 our $USER_CONFIG_FILE = '.email-reminders';
27 our $SPOOL_DIRECTORY = '/var/spool/email-reminder';
29 my %names = (
30 1 => "Paper",
31 2 => "Cotton",
32 3 => "Leather",
33 4 => "Linen",
34 5 => "Wood",
35 6 => "Iron",
36 7 => "Copper",
37 8 => "Bronze",
38 9 => "Pottery",
39 10 => "Tin",
40 11 => "Steel",
41 12 => "Silk",
42 13 => "Lace",
43 14 => "Ivory",
44 15 => "Crystal",
45 20 => "China",
46 25 => "Silver",
47 30 => "Pearl",
48 35 => "Jade",
49 40 => "Ruby",
50 45 => "Sapphire",
51 50 => "Golden",
52 55 => "Emerald",
53 60 => "Diamond",
56 sub get_node_value
58 my $node = shift;
59 my $tag_name = shift;
61 $node = $node->getElementsByTagName($tag_name, 0)->item(0);
62 return unless $node;
64 $node = $node->getFirstChild;
65 return unless $node;
67 return $node->getNodeValue;
70 sub set_node_value
72 my ($node, $tag_name, $new_value) = @_;
74 my $subnode = $node->getElementsByTagName($tag_name, 0)->item(0);
75 if (!defined($subnode))
77 $subnode = $node->getOwnerDocument()->createElement($tag_name);
78 $node->appendChild($subnode);
79 $subnode->addText($new_value);
81 else
83 my $textnode = $subnode->getFirstChild();
84 if (!defined($textnode))
86 $subnode->addText($new_value);
88 else
90 $textnode->setNodeValue($new_value);
93 return 1;
96 # Returns the proper English qualifier for this number
97 sub get_th
99 my $number = shift;
100 return unless defined($number);
102 if ($number >= 11 && $number <= 13) {
103 return "th";
104 } elsif ($number % 10 == 1) {
105 return "st";
106 } elsif ($number % 10 == 2) {
107 return "nd";
108 } elsif ($number % 10 == 3) {
109 return "rd";
110 } else {
111 return "th";
115 # Returns the traditional name for this occurence of the anniversary
116 # if applicable (e.g. Silver, Golden, Diamond)
117 # (see http://www.the-inspirations-store.com/acatalog/anniversary.html)
118 sub get_special_name
120 my $occurence = shift;
122 return unless exists $names{$occurence};
123 return "($names{$occurence}) ";