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.27";
7 2     2   227564 use strict;
  2         6  
  2         89  
8 2     2   26 use warnings;
  2         4  
  2         165  
9 2     2   1144 use Date::Calc;
  2         24965  
  2         14600  
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 459786 my $class = shift; $class = ref($class) || $class;
  2         18  
18 2         5 my $self = {}; %$self = @_; # Load ourselves up from the args
  2         10  
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         163  
24 2   33     24 $self->{'today_year'} = $self->{'today_year'} || $year;
25 2   33     13 $self->{'today_month'} = $self->{'today_month'} || $month;
26 2   33     11 $self->{'today_date'} = $self->{'today_date'} || $date;
27 2   66     12 $self->{'month'} = $self->{'month'} || $self->{'today_month'};
28 2   66     11 $self->{'year'} = $self->{'year'} || $self->{'today_year'};
29 2         42 $self->{'monthname'} = Date::Calc::Month_to_Text($self->{'month'});
30             }
31              
32             # Some defaults
33 2         8 $self->{'border'} = 5;
34 2         10 $self->{'width'} = '100%';
35 2         6 $self->{'showdatenumbers'} = 1;
36 2         5 $self->{'showweekdayheaders'} = 1;
37 2         28 $self->{'cellalignment'} = 'left';
38 2         6 $self->{'vcellalignment'} = 'top';
39 2         6 $self->{'weekdayheadersbig'} = 1;
40 2         6 $self->{'nowrap'} = 0;
41              
42 2         10 $self->{'weekdays'} = [qw/Monday Tuesday Wednesday Thursday Friday/];
43 2         6 $self->{'sunday'} = "Sunday";
44 2         6 $self->{'saturday'} = "Saturday";
45              
46             # Set the default calendar header
47             $self->{'header'} = sprintf("
%s %d
",
48 2         20 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         9 bless $self,$class;
52              
53 2         15 foreach my $datenumber ( 1 .. $self->Days_in_Month ) {
54 62         205 $self->{'content'}->{$datenumber} = '';
55 62         145 $self->{'datecellclass'}->{$datenumber} = '';
56 62         140 $self->{'datecolor'}->{$datenumber} = '';
57 62         168 $self->{'datebordercolor'}->{$datenumber} = '';
58 62         136 $self->{'datecontentcolor'}->{$datenumber} = '';
59 62         160 $self->{'href'}->{$datenumber} = '';
60             }
61              
62             # All done!
63 2         18 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 0         0 foreach $DAY ( 0 .. 6 ) {
256 0         0 my($thiscontent,$thisday,$thisbgcolor,$thisbordercolor,$thiscontentcolor,$thiscellclass);
257 0         0 $thisday = $days[((7*$WEEK)+$DAY)];
258              
259             # Get the cell content
260 0 0       0 if (! $thisday) { # If it's a dummy cell, no content
261 0         0 $thiscontent = ' '; }
262             else { # A real date cell with potential content
263             # Get the content
264 0 0       0 if ($self->showdatenumbers()) {
265 0 0       0 if ( $self->getdatehref( $thisday )) {
266 0         0 $thiscontent = "

getdatehref($thisday);

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

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

$thisday

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