File Coverage

blib/lib/HTML/CalendarMonthSimple.pm
Criterion Covered Total %
statement 48 500 9.6
branch 0 248 0.0
condition 8 152 5.2
subroutine 7 67 10.4
pod 63 63 100.0
total 126 1030 12.2


line stmt bran cond sub pod time code
1             # HTML::CalendarMonthSimple.pm
2             # Generate HTML calendars. An alternative to HTML::CalendarMonth
3             # Herein, the symbol $self is used to refer to the object that's being passed around.
4              
5             package HTML::CalendarMonthSimple;
6             our $VERSION = "1.26";
7 2     2   143094 use strict;
  2         13  
  2         66  
8 2     2   13 use warnings;
  2         4  
  2         60  
9 2     2   972 use Date::Calc;
  2         17488  
  2         11308  
10              
11              
12             # Within the constructor is the only place where values are access directly.
13             # Methods are provided for accessing/changing values, and those methods
14             # are used even internally.
15             # Most of the constructor is assigning default values.
16             sub new {
17 2   33 2 1 197 my $class = shift; $class = ref($class) || $class;
  2         17  
18 2         6 my $self = {}; %$self = @_; # Load ourselves up from the args
  2         8  
19              
20             # figure out the current date (which may be specified as today_year, et al
21             # then figure out which year+month we're supposed to display
22             {
23 2         4 my($year,$month,$date) = Date::Calc::Today();
  2         112  
24 2   33     19 $self->{'today_year'} = $self->{'today_year'} || $year;
25 2   33     14 $self->{'today_month'} = $self->{'today_month'} || $month;
26 2   33     10 $self->{'today_date'} = $self->{'today_date'} || $date;
27 2   66     10 $self->{'month'} = $self->{'month'} || $self->{'today_month'};
28 2   66     9 $self->{'year'} = $self->{'year'} || $self->{'today_year'};
29 2         12 $self->{'monthname'} = Date::Calc::Month_to_Text($self->{'month'});
30             }
31              
32             # Some defaults
33 2         5 $self->{'border'} = 5;
34 2         8 $self->{'width'} = '100%';
35 2         4 $self->{'showdatenumbers'} = 1;
36 2         5 $self->{'showweekdayheaders'} = 1;
37 2         5 $self->{'cellalignment'} = 'left';
38 2         5 $self->{'vcellalignment'} = 'top';
39 2         5 $self->{'weekdayheadersbig'} = 1;
40 2         4 $self->{'nowrap'} = 0;
41              
42 2         9 $self->{'weekdays'} = [qw/Monday Tuesday Wednesday Thursday Friday/];
43 2         7 $self->{'sunday'} = "Sunday";
44 2         5 $self->{'saturday'} = "Saturday";
45              
46             # Set the default calendar header
47             $self->{'header'} = sprintf("
%s %d
",
48 2         18 Date::Calc::Month_to_Text($self->{'month'}),$self->{'year'});
49              
50             # Initialize the (empty) cell content so the keys are representative of the month
51 2         8 bless $self,$class;
52              
53 2         9 foreach my $datenumber ( 1 .. $self->Days_in_Month ) {
54 62         141 $self->{'content'}->{$datenumber} = '';
55 62         99 $self->{'datecellclass'}->{$datenumber} = '';
56 62         108 $self->{'datecolor'}->{$datenumber} = '';
57 62         96 $self->{'datebordercolor'}->{$datenumber} = '';
58 62         107 $self->{'datecontentcolor'}->{$datenumber} = '';
59 62         105 $self->{'href'}->{$datenumber} = '';
60             }
61              
62             # All done!
63 2         8 return $self;
64             }
65              
66              
67             sub as_HTML {
68 0     0 1 0 my $self = shift;
69 0         0 my %params = @_;
70 0         0 my $html = '';
71 0         0 my(@days,$weeks,$WEEK,$DAY);
72              
73             # To make the grid even, pad the start of the series with 0s
74 0         0 @days = (1 .. $self->Days_in_Month );
75 0 0       0 if ($self->weekstartsonmonday()) {
76 0         0 foreach (1 .. (Date::Calc::Day_of_Week($self->year(),
77             $self->month(),1) -1 )) {
78 0         0 unshift(@days,0);
79             }
80             }
81             else {
82 0         0 foreach (1 .. (Date::Calc::Day_of_Week($self->year(),
83             $self->month(),1)%7) ) {
84 0         0 unshift(@days,0);
85             }
86             }
87 0         0 $weeks = int((scalar(@days)+6)/7);
88             # And pad the end as well, to avoid "uninitialized value" warnings
89 0         0 foreach (scalar(@days)+1 .. $weeks*7) {
90 0         0 push(@days,0);
91             }
92              
93             # Define some scalars for generating the table
94 0         0 my $border = $self->border();
95 0         0 my $tablewidth = $self->width();
96 0         0 my $cellwidth = "*";
97 0 0 0     0 if (defined($tablewidth) and $tablewidth =~ m/^(\d+)(\%?)$/) {
98 0 0 0     0 $cellwidth = (int($1/7))||'14'; if ($2) { $cellwidth .= '%'; }
  0         0  
  0         0  
99             }
100 0         0 my $header = $self->header();
101 0         0 my $cellalignment = $self->cellalignment();
102 0         0 my $vcellalignment = $self->vcellalignment();
103 0         0 my $contentfontsize = $self->contentfontsize();
104 0         0 my $bgcolor = $self->bgcolor();
105 0   0     0 my $weekdaycolor = $self->weekdaycolor() || $self->bgcolor();
106 0   0     0 my $weekendcolor = $self->weekendcolor() || $self->bgcolor();
107 0   0     0 my $todaycolor = $self->todaycolor() || $self->bgcolor();
108 0   0     0 my $contentcolor = $self->contentcolor() || $self->contentcolor();
109 0   0     0 my $weekdaycontentcolor = $self->weekdaycontentcolor() || $self->contentcolor();
110 0   0     0 my $weekendcontentcolor = $self->weekendcontentcolor() || $self->contentcolor();
111 0   0     0 my $todaycontentcolor = $self->todaycontentcolor() || $self->contentcolor();
112 0   0     0 my $bordercolor = $self->bordercolor() || $self->bordercolor();
113 0   0     0 my $weekdaybordercolor = $self->weekdaybordercolor() || $self->bordercolor();
114 0   0     0 my $weekendbordercolor = $self->weekendbordercolor() || $self->bordercolor();
115 0   0     0 my $todaybordercolor = $self->todaybordercolor() || $self->bordercolor();
116 0   0     0 my $weekdayheadercolor = $self->weekdayheadercolor() || $self->bgcolor();
117 0   0     0 my $weekendheadercolor = $self->weekendheadercolor() || $self->bgcolor();
118 0   0     0 my $headercontentcolor = $self->headercontentcolor() || $self->contentcolor();
119 0   0     0 my $weekdayheadercontentcolor = $self->weekdayheadercontentcolor() || $self->contentcolor();
120 0   0     0 my $weekendheadercontentcolor = $self->weekendheadercontentcolor() || $self->contentcolor();
121 0   0     0 my $headercolor = $self->headercolor() || $self->bgcolor();
122 0         0 my $cellpadding = $self->cellpadding();
123 0         0 my $cellspacing = $self->cellspacing();
124 0         0 my $sharpborders = $self->sharpborders();
125 0         0 my $cellheight = $self->cellheight();
126 0         0 my $cellclass = $self->cellclass();
127 0         0 my $tableclass = $self->tableclass();
128 0   0     0 my $weekdaycellclass = $self->weekdaycellclass() || $self->cellclass();
129 0   0     0 my $weekendcellclass = $self->weekendcellclass() || $self->cellclass();
130 0   0     0 my $todaycellclass = $self->todaycellclass() || $self->cellclass();
131 0   0     0 my $headerclass = $self->headerclass() || $self->cellclass();
132 0         0 my $nowrap = $self->nowrap();
133              
134             # Get today's date, in case there's a todaycolor()
135 0         0 my($todayyear,$todaymonth,$todaydate) = ($self->today_year(),$self->today_month(),$self->today_date());
136              
137             # the table declaration - sharpborders wraps the table inside a table cell
138 0 0       0 if ($sharpborders) {
139 0         0 $html .= "\n"; \n\n
140 0 0       0 $html .= " class=\"$tableclass\"" if defined $tableclass;
141 0 0       0 $html .= " width=\"$tablewidth\"" if defined $tablewidth;
142 0         0 $html .= " cellpadding=\"0\" cellspacing=\"0\">\n";
143 0         0 $html .= "
144 0         0 $html .= "
145 0 0       0 $html .= " bgcolor=\"$bordercolor\"" if defined $bordercolor;
146 0         0 $html .= ">";
147 0         0 $html .= ""; \n"; \n"; \n"; \n"; \n"; \n";
148             }
149             else {
150 0         0 $html .= "
151 0 0       0 $html .= " class=\"$tableclass\"" if defined $tableclass;
152 0 0       0 $html .= " border=\"$border\"" if defined $border;
153 0 0       0 $html .= " width=\"$tablewidth\"" if defined $tablewidth;
154 0 0       0 $html .= " bgcolor=\"$bgcolor\"" if defined $bgcolor;
155 0 0       0 $html .= " bordercolor=\"$bordercolor\"" if defined $bordercolor;
156 0 0       0 $html .= " cellpadding=\"$cellpadding\"" if defined $cellpadding;
157 0 0       0 $html .= " cellspacing=\"$cellspacing\"" if defined $cellspacing;
158 0         0 $html .= ">\n";
159             }
160             # the header
161 0 0       0 if ($header) {
162 0         0 $html .= "
163 0 0       0 $html .= " bgcolor=\"$headercolor\"" if defined $headercolor;
164 0 0       0 $html .= " class=\"$headerclass\"" if defined $headerclass;
165 0         0 $html .= ">";
166 0 0       0 $html .= "" if defined $headercontentcolor;
167 0         0 $html .= $header;
168 0 0       0 $html .= "" if defined $headercontentcolor;
169 0         0 $html .= "
170             }
171             # the names of the days of the week
172 0 0       0 if ($self->showweekdayheaders) {
173 0 0       0 my $celltype = $self->weekdayheadersbig() ? "th" : "td";
174 0         0 my @weekdays = $self->weekdays();
175              
176 0 0       0 my $saturday_html = "<$celltype"
    0          
    0          
    0          
177             . ( defined $weekendheadercolor
178             ? qq| bgcolor="$weekendheadercolor"|
179             : '' )
180             . ( defined $weekendcellclass
181             ? qq| class="$weekendcellclass"|
182             : '' )
183             . ">"
184             . ( defined $weekendheadercontentcolor
185             ? qq||
186             : '' )
187             . $self->saturday()
188             . ( defined $weekendheadercontentcolor
189             ? qq||
190             : '' )
191             . "\n";
192              
193 0 0       0 my $sunday_html = "<$celltype"
    0          
    0          
    0          
194             . ( defined $weekendheadercolor
195             ? qq| bgcolor="$weekendheadercolor"|
196             : '' )
197             . ( defined $weekendcellclass
198             ? qq| class="$weekendcellclass"|
199             : '' )
200             . ">"
201             . ( defined $weekendheadercontentcolor
202             ? qq||
203             : '' )
204             . $self->sunday()
205             . ( defined $weekendheadercontentcolor
206             ? qq||
207             : '' )
208             . "\n";
209            
210 0         0 my $weekday_html = '';
211 0         0 foreach (@weekdays) { # draw the weekday headers
212              
213 0 0       0 $weekday_html .= "<$celltype"
    0          
    0          
    0          
214             . ( defined $weekendheadercolor
215             ? qq| bgcolor="$weekdayheadercolor"|
216             : '' )
217             . ( defined $weekendcellclass
218             ? qq| class="$weekdaycellclass"|
219             : '' )
220             . ">"
221             . ( defined $weekdayheadercontentcolor
222             ? qq||
223             : '' )
224             . $_
225             . ( defined $weekdayheadercontentcolor
226             ? qq||
227             : '' )
228             . "\n";
229             }
230              
231 0         0 $html .= "
232 0 0       0 if ($self->weekstartsonmonday()) {
233 0         0 $html .= $weekday_html
234             . $saturday_html
235             . $sunday_html;
236             }
237             else {
238 0         0 $html .= $sunday_html
239             . $weekday_html
240             . $saturday_html;
241             }
242 0         0 $html .= "
243             }
244              
245 0         0 my $_saturday_index = 6;
246 0         0 my $_sunday_index = 0;
247 0 0       0 if ($self->weekstartsonmonday()) {
248 0         0 $_saturday_index = 5;
249 0         0 $_sunday_index = 6;
250             }
251             # now do each day, the actual date-content-containing cells
252 0         0 foreach $WEEK (0 .. ($weeks-1)) {
253 0         0 $html .= "
254              
255            
256 0         0 foreach $DAY ( 0 .. 6 ) {
257 0         0 my($thiscontent,$thisday,$thisbgcolor,$thisbordercolor,$thiscontentcolor,$thiscellclass);
258 0         0 $thisday = $days[((7*$WEEK)+$DAY)];
259              
260             # Get the cell content
261 0 0       0 if (! $thisday) { # If it's a dummy cell, no content
262 0         0 $thiscontent = ' '; }
263             else { # A real date cell with potential content
264             # Get the content
265 0 0       0 if ($self->showdatenumbers()) {
266 0 0       0 if ( $self->getdatehref( $thisday )) {
267 0         0 $thiscontent = "

getdatehref($thisday);

268 0         0 $thiscontent .= "\">$thisday

\n";
269             } else {
270 0         0 $thiscontent = "

$thisday

\n";
271             }
272             }
273 0         0 $thiscontent .= $self->{'content'}->{$thisday};
274 0   0     0 $thiscontent ||= ' ';
275             }
276              
277             # Get the cell's coloration and CSS class
278 0 0 0     0 if ($self->year == $todayyear && $self->month == $todaymonth && $thisday == $todaydate)
    0 0        
      0        
279 0   0     0 { $thisbgcolor = $self->datecolor($thisday) || $todaycolor;
280 0   0     0 $thisbordercolor = $self->datebordercolor($thisday) || $todaybordercolor;
281 0   0     0 $thiscontentcolor = $self->datecontentcolor($thisday) || $todaycontentcolor;
282 0   0     0 $thiscellclass = $self->datecellclass($thisday) || $todaycellclass;
283             }
284 0   0     0 elsif (($DAY == $_sunday_index) || ($DAY == $_saturday_index)) { $thisbgcolor = $self->datecolor($thisday) || $weekendcolor;
285 0   0     0 $thisbordercolor = $self->datebordercolor($thisday) || $weekendbordercolor;
286 0   0     0 $thiscontentcolor = $self->datecontentcolor($thisday) || $weekendcontentcolor;
287 0   0     0 $thiscellclass = $self->datecellclass($thisday) || $weekendcellclass;
288             }
289 0   0     0 else { $thisbgcolor = $self->datecolor($thisday) || $weekdaycolor;
290 0   0     0 $thisbordercolor = $self->datebordercolor($thisday) || $weekdaybordercolor;
291 0   0     0 $thiscontentcolor = $self->datecontentcolor($thisday) || $weekdaycontentcolor;
292 0   0     0 $thiscellclass = $self->datecellclass($thisday) || $weekdaycellclass;
293             }
294              
295             # Done with this cell - push it into the table
296 0         0 $html .= "
297 0 0       0 $html .= " nowrap" if $nowrap;
298 0 0       0 $html .= " class=\"$thiscellclass\"" if defined $thiscellclass;
299 0 0       0 $html .= " height=\"$cellheight\"" if defined $cellheight;
300 0 0       0 $html .= " width=\"$cellwidth\"" if defined $cellwidth;
301 0 0       0 $html .= " valign=\"$vcellalignment\"" if defined $vcellalignment;
302 0 0       0 $html .= " align=\"$cellalignment\"" if defined $cellalignment;
303 0 0       0 $html .= " bgcolor=\"$thisbgcolor\"" if defined $thisbgcolor;
304 0 0       0 $html .= " bordercolor=\"$thisbordercolor\"" if defined $thisbordercolor;
305 0         0 $html .= ">";
306 0 0 0     0 $html .= "
307             defined $contentfontsize);
308 0 0       0 $html .= " color=\"$thiscontentcolor\"" if defined $thiscontentcolor;
309 0 0       0 $html .= " size=\"$contentfontsize\"" if defined $contentfontsize;
310 0 0 0     0 $html .= ">" if (defined $thiscontentcolor ||
311             defined $contentfontsize);
312 0         0 $html .= $thiscontent;
313 0 0 0     0 $html .= "" if (defined $thiscontentcolor ||
314             defined $contentfontsize);
315 0         0 $html .= "
316             }
317 0         0 $html .= "
318             }
319 0         0 $html .= "
\n";
320              
321             # if sharpborders, we need to break out of the enclosing table cell
322 0 0       0 if ($sharpborders) {
323 0         0 $html .= "
\n";
324             }
325              
326 0         0 return $html;
327             }
328              
329              
330              
331             sub sunday {
332 0     0 1 0 my $self = shift;
333 0         0 my $newvalue = shift;
334 0 0       0 $self->{'sunday'} = $newvalue if defined($newvalue);
335 0         0 return $self->{'sunday'};
336             }
337              
338             sub saturday {
339 0     0 1 0 my $self = shift;
340 0         0 my $newvalue = shift;
341 0 0       0 $self->{'saturday'} = $newvalue if defined($newvalue);
342 0         0 return $self->{'saturday'};
343             }
344              
345             sub weekdays {
346 0     0 1 0 my $self = shift;
347 0         0 my @days = @_;
348 0 0       0 $self->{'weekdays'} = \@days if (scalar(@days)==5);
349 0         0 return @{$self->{'weekdays'}};
  0         0  
350             }
351              
352             sub getdatehref {
353 0     0 1 0 my $self = shift;
354 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
355 0         0 return $self->{'href'}->{$dates[0]};
356             }
357              
358             sub setdatehref {
359 0     0 1 0 my $self = shift;
360 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
361 0   0     0 my $datehref = shift || '';
362              
363 0         0 foreach my $date (@dates) {
364 0 0       0 $self->{'href'}->{$date} = $datehref if defined($self->{'href'}->{$date});
365             }
366              
367 0         0 return(1);
368             }
369              
370             sub weekendcolor {
371 0     0 1 0 my $self = shift;
372 0         0 my $newvalue = shift;
373 0 0       0 if (defined($newvalue)) { $self->{'weekendcolor'} = $newvalue; }
  0         0  
374 0         0 return $self->{'weekendcolor'};
375             }
376              
377             sub weekendheadercolor {
378 0     0 1 0 my $self = shift;
379 0         0 my $newvalue = shift;
380 0 0       0 if (defined($newvalue)) { $self->{'weekendheadercolor'} = $newvalue; }
  0         0  
381 0         0 return $self->{'weekendheadercolor'};
382             }
383              
384             sub weekdayheadercolor {
385 0     0 1 0 my $self = shift;
386 0         0 my $newvalue = shift;
387 0 0       0 if (defined($newvalue)) { $self->{'weekdayheadercolor'} = $newvalue; }
  0         0  
388 0         0 return $self->{'weekdayheadercolor'};
389             }
390              
391             sub weekdaycolor {
392 0     0 1 0 my $self = shift;
393 0         0 my $newvalue = shift;
394 0 0       0 if (defined($newvalue)) { $self->{'weekdaycolor'} = $newvalue; }
  0         0  
395 0         0 return $self->{'weekdaycolor'};
396             }
397              
398             sub headercolor {
399 0     0 1 0 my $self = shift;
400 0         0 my $newvalue = shift;
401 0 0       0 if (defined($newvalue)) { $self->{'headercolor'} = $newvalue; }
  0         0  
402 0         0 return $self->{'headercolor'};
403             }
404              
405             sub bgcolor {
406 0     0 1 0 my $self = shift;
407 0         0 my $newvalue = shift;
408 0 0       0 if (defined($newvalue)) { $self->{'bgcolor'} = $newvalue; }
  0         0  
409 0         0 return $self->{'bgcolor'};
410             }
411              
412             sub todaycolor {
413 0     0 1 0 my $self = shift;
414 0         0 my $newvalue = shift;
415 0 0       0 if (defined($newvalue)) { $self->{'todaycolor'} = $newvalue; }
  0         0  
416 0         0 return $self->{'todaycolor'};
417             }
418              
419             sub bordercolor {
420 0     0 1 0 my $self = shift;
421 0         0 my $newvalue = shift;
422 0 0       0 if (defined($newvalue)) { $self->{'bordercolor'} = $newvalue; }
  0         0  
423 0         0 return $self->{'bordercolor'};
424             }
425              
426             sub highlightbordercolor {
427 0     0 1 0 my $self=shift;
428 0 0       0 $self->{"highlightbordercolorhighlight"}=shift if @_;
429             $self->{"highlightbordercolorhighlight"}="#2E2E2E"
430 0 0       0 unless defined($self->{"highlightbordercolorhighlight"});
431 0         0 return $self->{"highlightbordercolorhighlight"};
432             }
433              
434             sub weekdaybordercolor {
435 0     0 1 0 my $self = shift;
436 0         0 my $newvalue = shift;
437 0 0       0 if (defined($newvalue)) { $self->{'weekdaybordercolor'} = $newvalue; }
  0         0  
438 0         0 return $self->{'weekdaybordercolor'};
439             }
440              
441             sub weekendbordercolor {
442 0     0 1 0 my $self = shift;
443 0         0 my $newvalue = shift;
444 0 0       0 if (defined($newvalue)) { $self->{'weekendbordercolor'} = $newvalue; }
  0         0  
445 0         0 return $self->{'weekendbordercolor'};
446             }
447              
448             sub todaybordercolor {
449 0     0 1 0 my $self = shift;
450 0         0 my $newvalue = shift;
451 0 0       0 if (defined($newvalue)) { $self->{'todaybordercolor'} = $newvalue; }
  0         0  
452 0         0 return $self->{'todaybordercolor'};
453             }
454              
455             sub contentcolor {
456 0     0 1 0 my $self = shift;
457 0         0 my $newvalue = shift;
458 0 0       0 if (defined($newvalue)) { $self->{'contentcolor'} = $newvalue; }
  0         0  
459 0         0 return $self->{'contentcolor'};
460             }
461              
462             sub highlightcontentcolor {
463 0     0 1 0 my $self=shift;
464 0 0       0 $self->{"highlightcontentcolor"}=shift if @_;
465             $self->{"highlightcontentcolor"}="#FEFEE2"
466 0 0       0 unless defined $self->{"highlightcontentcolor"};
467 0         0 return $self->{"highlightcontentcolor"};
468             }
469              
470             sub headercontentcolor {
471 0     0 1 0 my $self = shift;
472 0         0 my $newvalue = shift;
473 0 0       0 if (defined($newvalue)) { $self->{'headercontentcolor'} = $newvalue; }
  0         0  
474 0         0 return $self->{'headercontentcolor'};
475             }
476              
477             sub weekdayheadercontentcolor {
478 0     0 1 0 my $self = shift;
479 0         0 my $newvalue = shift;
480 0 0       0 if (defined($newvalue)) { $self->{'weekdayheadercontentcolor'} = $newvalue; }
  0         0  
481 0         0 return $self->{'weekdayheadercontentcolor'};
482             }
483              
484             sub weekendheadercontentcolor {
485 0     0 1 0 my $self = shift;
486 0         0 my $newvalue = shift;
487 0 0       0 if (defined($newvalue)) { $self->{'weekendheadercontentcolor'} = $newvalue; }
  0         0  
488 0         0 return $self->{'weekendheadercontentcolor'};
489             }
490              
491             sub weekdaycontentcolor {
492 0     0 1 0 my $self = shift;
493 0         0 my $newvalue = shift;
494 0 0       0 if (defined($newvalue)) { $self->{'weekdaycontentcolor'} = $newvalue; }
  0         0  
495 0         0 return $self->{'weekdaycontentcolor'};
496             }
497              
498             sub weekendcontentcolor {
499 0     0 1 0 my $self = shift;
500 0         0 my $newvalue = shift;
501 0 0       0 if (defined($newvalue)) { $self->{'weekendcontentcolor'} = $newvalue; }
  0         0  
502 0         0 return $self->{'weekendcontentcolor'};
503             }
504              
505             sub todaycontentcolor {
506 0     0 1 0 my $self = shift;
507 0         0 my $newvalue = shift;
508 0 0       0 if (defined($newvalue)) { $self->{'todaycontentcolor'} = $newvalue; }
  0         0  
509 0         0 return $self->{'todaycontentcolor'};
510             }
511              
512             sub datecolor {
513 0     0 1 0 my $self = shift;
514 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
515 0         0 my $newvalue = shift;
516              
517 0 0       0 if (defined($newvalue)) {
518 0         0 foreach my $date (@dates) {
519 0 0       0 $self->{'datecolor'}->{$date} = $newvalue if defined($self->{'datecolor'}->{$date});
520             }
521             }
522              
523 0         0 return $self->{'datecolor'}->{$dates[0]};
524             }
525              
526             sub datebordercolor {
527 0     0 1 0 my $self = shift;
528 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
529 0         0 my $newvalue = shift;
530              
531 0 0       0 if (defined($newvalue)) {
532 0         0 foreach my $date (@dates) {
533 0 0       0 $self->{'datebordercolor'}->{$date} = $newvalue if defined($self->{'datebordercolor'}->{$date});
534             }
535             }
536              
537 0         0 return $self->{'datebordercolor'}->{$dates[0]};
538             }
539              
540             sub datecontentcolor {
541 0     0 1 0 my $self = shift;
542 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
543 0         0 my $newvalue = shift;
544              
545 0 0       0 if (defined($newvalue)) {
546 0         0 foreach my $date (@dates) {
547 0 0       0 $self->{'datecontentcolor'}->{$date} = $newvalue if defined($self->{'datecontentcolor'}->{$date});
548             }
549             }
550              
551 0         0 return $self->{'datecontentcolor'}->{$dates[0]};
552             }
553              
554             sub highlight {
555 0     0 1 0 my $self=shift;
556 0         0 my @day=@_;
557 0         0 foreach my $day (@day) {
558 0         0 $self->datebordercolor($day, $self->highlightbordercolor);
559 0         0 $self->datecolor($day, $self->highlightcontentcolor);
560             }
561 0         0 return(1);
562             }
563              
564             sub getcontent {
565 0     0 1 0 my $self = shift;
566 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
567 0         0 return $self->{'content'}->{$dates[0]};
568             }
569              
570             sub setcontent {
571 0     0 1 0 my $self = shift;
572 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
573 0   0     0 my $newcontent = shift || '';
574              
575 0         0 foreach my $date (@dates) {
576 0 0       0 $self->{'content'}->{$date} = $newcontent if defined($self->{'content'}->{$date});
577             }
578              
579 0         0 return(1);
580             }
581              
582             sub addcontent {
583 0     0 1 0 my $self = shift;
584 0 0       0 my @dates = $self->_date_string_to_numeric(shift); return() unless @dates;
  0         0  
585 0   0     0 my $newcontent = shift || return();
586              
587 0         0 foreach my $date (@dates) {
588 0 0       0 $self->{'content'}->{$date} .= $newcontent if defined($self->{'content'}->{$date});
589             }
590              
591 0         0 return(1);
592             }
593              
594             sub border {
595 0     0 1 0 my $self = shift;
596 0         0 my $newvalue = shift;
597 0 0       0 if (defined($newvalue)) { $self->{'border'} = int($newvalue); }
  0         0  
598 0         0 return $self->{'border'};
599             }
600              
601              
602             sub cellpadding {
603 0     0 1 0 my $self = shift;
604 0         0 my $newvalue = shift;
605 0 0       0 if (defined($newvalue)) { $self->{'cellpadding'} = $newvalue; }
  0         0  
606 0         0 return $self->{'cellpadding'};
607             }
608              
609             sub cellspacing {
610 0     0 1 0 my $self = shift;
611 0         0 my $newvalue = shift;
612 0 0       0 if (defined($newvalue)) { $self->{'cellspacing'} = $newvalue; }
  0         0  
613 0         0 return $self->{'cellspacing'};
614             }
615              
616             sub width {
617 0     0 1 0 my $self = shift;
618 0         0 my $newvalue = shift;
619 0 0       0 if (defined($newvalue)) { $self->{'width'} = $newvalue; }
  0         0  
620 0         0 return $self->{'width'};
621             }
622              
623             sub showdatenumbers {
624 0     0 1 0 my $self = shift;
625 0         0 my $newvalue = shift;
626 0 0       0 if (defined($newvalue)) { $self->{'showdatenumbers'} = $newvalue; }
  0         0  
627 0         0 return $self->{'showdatenumbers'};
628             }
629             sub showweekdayheaders {
630 0     0 1 0 my $self = shift;
631 0         0 my $newvalue = shift;
632 0 0       0 if (defined($newvalue)) { $self->{'showweekdayheaders'} = $newvalue; }
  0         0  
633 0         0 return $self->{'showweekdayheaders'};
634             }
635              
636             sub cellalignment {
637 0     0 1 0 my $self = shift;
638 0         0 my $newvalue = shift;
639 0 0       0 if (defined($newvalue)) { $self->{'cellalignment'} = $newvalue; }
  0         0  
640 0         0 return $self->{'cellalignment'};
641             }
642              
643             sub vcellalignment {
644 0     0 1 0 my $self = shift;
645 0         0 my $newvalue = shift;
646 0 0       0 if (defined($newvalue)) { $self->{'vcellalignment'} = $newvalue; }
  0         0  
647 0         0 return $self->{'vcellalignment'};
648             }
649              
650             sub contentfontsize {
651 0     0 1 0 my $self = shift;
652 0         0 my $newvalue = shift;
653 0 0       0 if (defined($newvalue)) { $self->{'contentfontsize'} = $newvalue; }
  0         0  
654 0         0 return $self->{'contentfontsize'};
655             }
656              
657             sub weekdayheadersbig {
658 0     0 1 0 my $self = shift;
659 0         0 my $newvalue = shift;
660 0 0       0 if (defined($newvalue)) { $self->{'weekdayheadersbig'} = $newvalue; }
  0         0  
661 0         0 return $self->{'weekdayheadersbig'};
662             }
663              
664             sub year {
665 3     3 1 6 my $self = shift;
666 3         18 return $self->{'year'};
667             }
668              
669             sub month {
670 3     3 1 5 my $self = shift;
671 3         25 return $self->{'month'};
672             }
673              
674             sub monthname {
675 0     0 1 0 my $self = shift;
676 0         0 return $self->{'monthname'};
677             }
678              
679             sub today_year {
680 0     0 1 0 my $self = shift;
681 0         0 return $self->{'today_year'};
682             }
683              
684             sub today_month {
685 0     0 1 0 my $self = shift;
686 0         0 return $self->{'today_month'};
687             }
688              
689             sub today_date {
690 0     0 1 0 my $self = shift;
691 0         0 return $self->{'today_date'};
692             }
693              
694              
695             sub header {
696 0     0 1 0 my $self = shift;
697 0         0 my $newvalue = shift;
698 0 0       0 if (defined($newvalue)) { $self->{'header'} = $newvalue; }
  0         0  
699 0         0 return $self->{'header'};
700             }
701              
702             sub nowrap {
703 0     0 1 0 my $self = shift;
704 0         0 my $newvalue = shift;
705 0 0       0 if (defined($newvalue)) { $self->{'nowrap'} = $newvalue; }
  0         0  
706 0         0 return $self->{'nowrap'};
707             }
708              
709             sub sharpborders {
710 0     0 1 0 my $self = shift;
711 0         0 my $newvalue = shift;
712 0 0       0 if (defined($newvalue)) { $self->{'sharpborders'} = $newvalue; }
  0         0  
713 0         0 return $self->{'sharpborders'};
714             }
715              
716             sub cellheight {
717 0     0 1 0 my $self = shift;
718 0         0 my $newvalue = shift;
719 0 0       0 if (defined($newvalue)) { $self->{'cellheight'} = $newvalue; }
  0         0  
720 0         0 return $self->{'cellheight'};
721             }
722              
723             sub cellclass {
724 0     0 1 0 my $self = shift;
725 0         0 my $newvalue = shift;
726 0 0       0 if (defined($newvalue)) { $self->{'cellclass'} = $newvalue; }
  0         0  
727 0         0 return $self->{'cellclass'};
728             }
729              
730             sub tableclass {
731 0     0 1 0 my $self = shift;
732 0         0 my $newvalue = shift;
733 0 0       0 if (defined($newvalue)) { $self->{'tableclass'} = $newvalue; }
  0         0  
734 0         0 return $self->{'tableclass'};
735             }
736              
737             sub weekdaycellclass {
738 0     0 1 0 my $self = shift;
739 0         0 my $newvalue = shift;
740 0 0       0 if (defined($newvalue)) { $self->{'weekdaycellclass'} = $newvalue; }
  0         0  
741 0         0 return $self->{'weekdaycellclass'};
742             }
743              
744             sub weekendcellclass {
745 0     0 1 0 my $self = shift;
746 0         0 my $newvalue = shift;
747 0 0       0 if (defined($newvalue)) { $self->{'weekendcellclass'} = $newvalue; }
  0         0  
748 0         0 return $self->{'weekendcellclass'};
749             }
750              
751             sub todaycellclass {
752 0     0 1 0 my $self = shift;
753 0         0 my $newvalue = shift;
754 0 0       0 if (defined($newvalue)) { $self->{'todaycellclass'} = $newvalue; }
  0         0  
755 0         0 return $self->{'todaycellclass'};
756             }
757              
758             sub datecellclass {
759 0     0 1 0 my $self = shift;
760 0 0 0     0 my $date = lc(shift) || return(); $date = int($date) if $date =~ m/^[\d\.]+$/;
  0         0  
761 0         0 my $newvalue = shift;
762 0 0       0 if (defined($newvalue)) { $self->{'datecellclass'}->{$date} = $newvalue; }
  0         0  
763 0         0 return $self->{'datecellclass'}->{$date};
764             }
765              
766             sub headerclass {
767 0     0 1 0 my $self = shift;
768 0         0 my $newvalue = shift;
769 0 0       0 if (defined($newvalue)) { $self->{'headerclass'} = $newvalue; }
  0         0  
770 0         0 return $self->{'headerclass'};
771             }
772              
773             sub weekstartsonmonday {
774 0     0 1 0 my $self = shift;
775 0         0 my $newvalue = shift;
776 0 0       0 if (defined($newvalue)) { $self->{'weekstartsonmonday'} = $newvalue; }
  0         0  
777 0 0       0 return $self->{'weekstartsonmonday'} ? 1 : 0;
778             }
779              
780             sub Days_in_Month {
781 3     3 1 616 my $self=shift;
782 3         26 return Date::Calc::Days_in_Month($self->year, $self->month);
783             }
784              
785             ### the following methods are internal-use-only methods
786              
787             # _date_string_to_numeric() takes a date string (e.g. 5, 'wednesdays', or '3friday')
788             # and returns the corresponding numeric date. For numerics, this sounds meaningless,
789             # but for the strings it's useful to have this all in one place.
790             # If it's a plural weekday (e.g. 'sundays') then an array of numeric dates is returned.
791             sub _date_string_to_numeric {
792 0     0     my $self = shift;
793 0   0       my $date = shift || return ();
794              
795 0           my($which,$weekday);
796 0 0         if ($date =~ m/^\d\.*\d*$/) { # first and easiest, simple numerics
    0          
    0          
797 0           return int($date);
798             }
799             elsif (($which,$weekday) = ($date =~ m/^(\d)([a-zA-Z]+)$/)) {
800 0           my($y,$m,$d) = Date::Calc::Nth_Weekday_of_Month_Year($self->year(),$self->month(),Date::Calc::Decode_Day_of_Week($weekday),$which);
801 0           return $d;
802             }
803             elsif (($weekday) = ($date =~ m/^(\w+)s$/i)) {
804 0           $weekday = Date::Calc::Decode_Day_of_Week($weekday); # now it's the numeric weekday
805 0           my @dates;
806 0           foreach my $which (1..5) {
807 0           my $thisdate = Date::Calc::Nth_Weekday_of_Month_Year($self->year(),$self->month(),$weekday,$which);
808 0 0         push(@dates,$thisdate) if $thisdate;
809             }
810 0           return @dates;
811             }
812             }
813              
814              
815              
816             __END__;