blib/lib/Calendar/Schedule.pm

filter: Statementstmt 49.7% 294 / 591 Branchbran 39.1% 116 / 296 Conditioncond 29.6% 24 / 81 MC/DCmcdc 21.5% 11 / 51 Subroutinesub 68.0% 17 / 25 Podpod 58.8% 10 / 17 totaltotal 44.4% 472 / 1061 CC 196 SCAR 65.3
CC
196
Cov
45%
add_entry
1917.6
generate_table
646.0
is_week_in_month
72.0
CRAP 688.6
↑ Summary bin/cal2html »
1 # Calendar::Schedule - Manage calendar schedules
2 # (c) 2002-2020 Vlado Keselj http://web.cs.dal.ca/~vlado vlado@dnlp.ca
3 # and contributing authors
4 #
5 # Some parts are updated with Starfish during development, such as the version
6 # number: <? read_starfish_conf !>
7  
8 package Calendar::Schedule;
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 require Exporter;
11 2 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # Exporter vars
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 our @ISA = qw(Exporter);
15  
16 2 our %EXPORT_TAGS = ( 'all' => [ qw( parse_time ) ] );
17 2 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
18 2 our @EXPORT = qw(new);
19  
20 #<?echo "our \$VERSION = '$Meta->{version}';"!>#+
21 2 our $VERSION = '1.21';#-
22  
23 # non-exported package globals
24 2 ▶use vars qw( $REweekday3 $REmonth3 $RE1st );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 $RE1st = qr/first|second|third|fourth|fifth|last|1st|2nd|3rd|4th|5th/;
26 2 $REweekday3 = qr/Mon|Tue|Wed|Thu|Fri|Sat|Sun/;
27 2 $REmonth3 = qr/Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec/;
28  
29 =head1 NAME
30  
31 Calendar::Schedule - manage calendar schedules
32  
33 =head1 SYNOPSIS
34  
35 use Calendar::Schedule qw/:all/;
36  
37 my $TTable = Calendar::Schedule->new();
38  
39 # manually adding an entry
40 $TTable->add_entry('2003-09-09 Tue 18-20 Some meeting');
41
42 # reading entries from a file
43 $TTable->add_entries_from("$ENV{'HOME'}/.calendar");
44  
45 # producing entries in HTML tables, one table per week
46 $TTable->set_first_week('now');
47 print "<p>\n" . $TTable->generate_table();
48 print "<p>\n" . $TTable->generate_table();
49 print "<p>\n" . $TTable->generate_table();
50  
51 # for more examples, see EXAMPLES section
52  
53 The file .calendar may look like this:
54  
55 # comments can start with #
56 * lines starting with * are treated as general todo entries ...
57 # empty lines are acceptable and ignored:
58  
59 Mon 9:00-10:00 this is a weekly entry
60 Mon 13-14 a biweekly entry :biweekly :start Mar 8, 2004
61 Mon,Wed,Fri 15:30-16:30 several-days-a-week entry
62 Wed :biweekly garbage collection
63  
64 2004-03-06 Sat 14-16 fixed entry. The week day is redundant, but may\
65 help to detect errors (error will be reported if a wrong\
66 weekday is entered). BTW, an entry can go for several lines as\
67 long as there is a backslash at the end of each line.
68  
69 May 6 birthday (yearly entry)
70  
71 # more examples in "Example entries" section
72  
73 =head1 DESCRIPTION
74  
75 The module is created with a purpose to provide functionality for handling a
76 personal calendar schedule in a transparent and simple way. The calendar
77 data is assumed to be kept in a plain file in a format easy to edit and
78 understand. It was inspired by the C<calendar> program on older Unix-like
79 systems, which used C<~/.calendar> file to produce entries for each day
80 and send them in the morning by email.
81  
82 Inspired by the C<~/.calendar> file, the format for recording scheduled
83 events is very simple, mostly contained in one line of text.
84  
85 The module currently supports generation of HTML weekly tables with visual
86 representation of scheduled events. The generated table is generated in
87 a simple HTML table, with a use of C<colspan> and C<rolspan> attributes to
88 represent overlapping events in parallel in the table.
89  
90 =head2 Planned Future Work
91  
92 In the development of the recording format for the event, there is an attempt
93 to model the data representation of the iCalendar standard (RFC2445).
94 Examples of the iCalendar fields are: DTSTART, DTEND, SUMMARY,
95 RRULE (e.g. RRULE:FREQ=WEEKLY, RRULE:FREQ=WEEKLY;INTERVAL=2 for
96 biweekly, RRULE:FREQ=WEEKLY;UNTIL=20040408 ) etc.
97 More examples:
98  
99 RRULE:FREQ=MONTHLY;BYDAY=TU;BYSETPOS=3
100  
101 Every third Tuesday in a month.
102  
103 =head1 EXAMPLES
104  
105 First example:
106  
107 use Calendar::Schedule qw/:all/;
108  
109 my $TTable = Calendar::Schedule->new();
110  
111 # manually adding an entry
112 $TTable->add_entry('2003-09-09 Tue 18-20 Some meeting');
113
114 # reading entries from a file
115 $TTable->add_entries_from("$ENV{'HOME'}/.calendar");
116  
117 # producing entries in HTML tables
118 $TTable->set_first_week('2003-12-15');
119 print "<p>\n" . $TTable->generate_table();
120 print "<p>\n" . $TTable->generate_table();
121 print "<p>\n" . $TTable->generate_table();
122  
123 Example with generating a weekly schedule (example2):
124  
125 use Calendar::Schedule;
126 $TTable = Calendar::Schedule->new();
127 $TTable->{'ColLabel'} = "%A";
128 $TTable->add_entries(<<EOT
129 Mon 15:30-16:30 Teaching (CSCI 3136)
130 Tue 10-11:30 Teaching (ECMM 6014)
131 Wed 13:30-14:30 DNLP
132 Wed 15:30-16:30 Teaching (CSCI 3136) :until Apr 8, 2005
133 Thu 10-11:30 Teaching (ECMM 6014)
134 Thu 16-17 WIFL
135 Fri 14:30-15:30 MALNIS
136 Fri 15:30-16:30 Teaching (CSCI 3136)
137 EOT
138 );
139 print "<p>\n" . $TTable->generate_table();
140  
141 This will produce the following HTML code (if run before Apr 8, 2005):
142  
143 =for html
144 <p>
145 <table width=100% border=2 cellspacing=1 cellpadding=1>
146 <tr>
147 <td valign=top>&nbsp;</td>
148 <th>Monday</th>
149 <th>Tuesday</th>
150 <th>Wednesday</th>
151 <th>Thursday</th>
152 <th>Friday</th>
153 <th>Saturday</th>
154 <th>Sunday</th>
155 </tr>
156 <tr><td>08:00</td>
157 <td align=center>&nbsp;</td>
158 <td align=center>&nbsp;</td>
159 <td align=center>&nbsp;</td>
160 <td align=center>&nbsp;</td>
161 <td align=center>&nbsp;</td>
162 <td align=center>&nbsp;</td>
163 <td align=center>&nbsp;</td>
164 </tr>
165 <tr><td>10:00</td>
166 <td align=center>&nbsp;</td>
167 <td align=center bgcolor=yellow>Teaching (ECMM 6014)</td>
168 <td align=center>&nbsp;</td>
169 <td align=center bgcolor=yellow>Teaching (ECMM 6014)</td>
170 <td align=center>&nbsp;</td>
171 <td align=center>&nbsp;</td>
172 <td align=center>&nbsp;</td>
173 </tr>
174 <tr><td>11:30</td>
175 <td align=center>&nbsp;</td>
176 <td align=center>&nbsp;</td>
177 <td align=center>&nbsp;</td>
178 <td align=center>&nbsp;</td>
179 <td align=center>&nbsp;</td>
180 <td align=center>&nbsp;</td>
181 <td align=center>&nbsp;</td>
182 </tr>
183 <tr><td>12:00</td>
184 <td align=center>&nbsp;</td>
185 <td align=center>&nbsp;</td>
186 <td align=center>&nbsp;</td>
187 <td align=center>&nbsp;</td>
188 <td align=center>&nbsp;</td>
189 <td align=center>&nbsp;</td>
190 <td align=center>&nbsp;</td>
191 </tr>
192 <tr><td>13:30</td>
193 <td align=center>&nbsp;</td>
194 <td align=center>&nbsp;</td>
195 <td align=center bgcolor=yellow>DNLP</td>
196 <td align=center>&nbsp;</td>
197 <td align=center>&nbsp;</td>
198 <td align=center>&nbsp;</td>
199 <td align=center>&nbsp;</td>
200 </tr>
201 <tr><td>14:30</td>
202 <td align=center>&nbsp;</td>
203 <td align=center>&nbsp;</td>
204 <td align=center>&nbsp;</td>
205 <td align=center>&nbsp;</td>
206 <td align=center bgcolor=yellow>MALNIS</td>
207 <td align=center>&nbsp;</td>
208 <td align=center>&nbsp;</td>
209 </tr>
210 <tr><td>15:30</td>
211 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136)</td>
212 <td align=center>&nbsp;</td>
213 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136) </td>
214 <td align=center>&nbsp;</td>
215 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136)</td>
216 <td align=center>&nbsp;</td>
217 <td align=center>&nbsp;</td>
218 </tr>
219 <tr><td>16:00</td>
220 <!-- continue -->
221 <td align=center>&nbsp;</td>
222 <!-- continue -->
223 <td align=center bgcolor=yellow rowspan=2>WIFL</td>
224 <!-- continue -->
225 <td align=center>&nbsp;</td>
226 <td align=center>&nbsp;</td>
227 </tr>
228 <tr><td>16:30</td>
229 <td align=center>&nbsp;</td>
230 <td align=center>&nbsp;</td>
231 <td align=center>&nbsp;</td>
232 <!-- continue -->
233 <td align=center>&nbsp;</td>
234 <td align=center>&nbsp;</td>
235 <td align=center>&nbsp;</td>
236 </tr>
237 <tr><td>17:00</td>
238 <td align=center>&nbsp;</td>
239 <td align=center>&nbsp;</td>
240 <td align=center>&nbsp;</td>
241 <td align=center>&nbsp;</td>
242 <td align=center>&nbsp;</td>
243 <td align=center>&nbsp;</td>
244 <td align=center>&nbsp;</td>
245 </tr>
246 </table>
247  
248 =head2 Conflicts
249  
250 Time conflicts are handled by producing several columns in a table for
251 the same day. For example, the following code (example3):
252  
253 use Calendar::Schedule;
254 $TTable = Calendar::Schedule->new();
255 $TTable->{'ColLabel'} = "%A";
256 $TTable->add_entries(<<EOT
257  
258 Mon 15:30-16:30 Teaching (CSCI 3136)
259 Tue 10-11:30 Teaching (ECMM 6014)
260 Wed 13:30-14:30 DNLP
261 Wed 15:30-16:30 Teaching (CSCI 3136) :until Apr 8, 2005
262 Thu 10-11:30 Teaching (ECMM 6014)
263 Thu 16-17 WIFL
264 Fri 14:30-15:30 MALNIS
265 Fri 15:30-16:30 Teaching (CSCI 3136)
266 Wed 15-16 meeting
267 Wed 15:30-18 another meeting
268  
269 EOT
270 );
271 print "<p>\n" . $TTable->generate_table();
272  
273 will produce the following table (if run before Apr 8, 2005):
274  
275 =for html
276 <p>
277 <table width=100% border=2 cellspacing=1 cellpadding=1>
278 <tr>
279 <td valign=top>&nbsp;</td>
280 <th>Monday</th>
281 <th>Tuesday</th>
282 <th colspan=3>Wednesday</th>
283 <th>Thursday</th>
284 <th>Friday</th>
285 <th>Saturday</th>
286 <th>Sunday</th>
287 </tr>
288 <tr><td>08:00</td>
289 <td align=center>&nbsp;</td>
290 <td align=center>&nbsp;</td>
291 <td align=center>&nbsp;</td>
292 <td align=center>&nbsp;</td>
293 <td align=center>&nbsp;</td>
294 <td align=center>&nbsp;</td>
295 <td align=center>&nbsp;</td>
296 <td align=center>&nbsp;</td>
297 <td align=center>&nbsp;</td>
298 </tr>
299 <tr><td>10:00</td>
300 <td align=center>&nbsp;</td>
301 <td align=center bgcolor=yellow>Teaching (ECMM 6014)</td>
302 <td align=center>&nbsp;</td>
303 <td align=center>&nbsp;</td>
304 <td align=center>&nbsp;</td>
305 <td align=center bgcolor=yellow>Teaching (ECMM 6014)</td>
306 <td align=center>&nbsp;</td>
307 <td align=center>&nbsp;</td>
308 <td align=center>&nbsp;</td>
309 </tr>
310 <tr><td>11:30</td>
311 <td align=center>&nbsp;</td>
312 <td align=center>&nbsp;</td>
313 <td align=center>&nbsp;</td>
314 <td align=center>&nbsp;</td>
315 <td align=center>&nbsp;</td>
316 <td align=center>&nbsp;</td>
317 <td align=center>&nbsp;</td>
318 <td align=center>&nbsp;</td>
319 <td align=center>&nbsp;</td>
320 </tr>
321 <tr><td>12:00</td>
322 <td align=center>&nbsp;</td>
323 <td align=center>&nbsp;</td>
324 <td align=center>&nbsp;</td>
325 <td align=center>&nbsp;</td>
326 <td align=center>&nbsp;</td>
327 <td align=center>&nbsp;</td>
328 <td align=center>&nbsp;</td>
329 <td align=center>&nbsp;</td>
330 <td align=center>&nbsp;</td>
331 </tr>
332 <tr><td>13:30</td>
333 <td align=center>&nbsp;</td>
334 <td align=center>&nbsp;</td>
335 <td align=center bgcolor=yellow>DNLP</td>
336 <td align=center>&nbsp;</td>
337 <td align=center>&nbsp;</td>
338 <td align=center>&nbsp;</td>
339 <td align=center>&nbsp;</td>
340 <td align=center>&nbsp;</td>
341 <td align=center>&nbsp;</td>
342 </tr>
343 <tr><td>14:30</td>
344 <td align=center>&nbsp;</td>
345 <td align=center>&nbsp;</td>
346 <td align=center>&nbsp;</td>
347 <td align=center>&nbsp;</td>
348 <td align=center>&nbsp;</td>
349 <td align=center>&nbsp;</td>
350 <td align=center bgcolor=yellow rowspan=2>MALNIS</td>
351 <td align=center>&nbsp;</td>
352 <td align=center>&nbsp;</td>
353 </tr>
354 <tr><td>15:00</td>
355 <td align=center>&nbsp;</td>
356 <td align=center>&nbsp;</td>
357 <td align=center>&nbsp;</td>
358 <td align=center bgcolor=yellow rowspan=2>meeting</td>
359 <td align=center>&nbsp;</td>
360 <td align=center>&nbsp;</td>
361 <!-- continue -->
362 <td align=center>&nbsp;</td>
363 <td align=center>&nbsp;</td>
364 </tr>
365 <tr><td>15:30</td>
366 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136)</td>
367 <td align=center>&nbsp;</td>
368 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136) </td>
369 <!-- continue -->
370 <td align=center bgcolor=yellow rowspan=4>another meeting</td>
371 <td align=center>&nbsp;</td>
372 <td align=center bgcolor=yellow rowspan=2>Teaching (CSCI 3136)</td>
373 <td align=center>&nbsp;</td>
374 <td align=center>&nbsp;</td>
375 </tr>
376 <tr><td>16:00</td>
377 <!-- continue -->
378 <td align=center>&nbsp;</td>
379 <!-- continue -->
380 <td align=center>&nbsp;</td>
381 <!-- continue -->
382 <td align=center bgcolor=yellow rowspan=2>WIFL</td>
383 <!-- continue -->
384 <td align=center>&nbsp;</td>
385 <td align=center>&nbsp;</td>
386 </tr>
387 <tr><td>16:30</td>
388 <td align=center>&nbsp;</td>
389 <td align=center>&nbsp;</td>
390 <td align=center>&nbsp;</td>
391 <td align=center>&nbsp;</td>
392 <!-- continue -->
393 <!-- continue -->
394 <td align=center>&nbsp;</td>
395 <td align=center>&nbsp;</td>
396 <td align=center>&nbsp;</td>
397 </tr>
398 <tr><td>17:00</td>
399 <td align=center>&nbsp;</td>
400 <td align=center>&nbsp;</td>
401 <td align=center>&nbsp;</td>
402 <td align=center>&nbsp;</td>
403 <!-- continue -->
404 <td align=center>&nbsp;</td>
405 <td align=center>&nbsp;</td>
406 <td align=center>&nbsp;</td>
407 <td align=center>&nbsp;</td>
408 </tr>
409 <tr><td>18:00</td>
410 <td align=center>&nbsp;</td>
411 <td align=center>&nbsp;</td>
412 <td align=center>&nbsp;</td>
413 <td align=center>&nbsp;</td>
414 <td align=center>&nbsp;</td>
415 <td align=center>&nbsp;</td>
416 <td align=center>&nbsp;</td>
417 <td align=center>&nbsp;</td>
418 <td align=center>&nbsp;</td>
419 </tr>
420 </table>
421  
422 =head2 Example entries
423  
424 These are some example of simple entries that are accepted by the
425 C<add_entry> function or C<add_entries_from> for reading from a file.
426 Each entry is on a line by itself, but it can be continued in the the
427 following lines by using \ (backslash) at the end of the current line.
428 The time specificantions are generally at the beginning of an entry.
429 Examples:
430  
431 # comments can start with #
432 # empty lines are acceptable and ignored:
433  
434 Mon 9:00-10:00 this is a weekly entry
435 Mon 13-14 a biweekly entry :biweekly :start Mar 8, 2004
436 Mon,Wed,Fri 15:30-16:30 several-days-a-week entry
437 Wed :biweekly garbage collection
438  
439 2004-03-06 Sat 14-16 fixed entry. The week day is redundant, but may\
440 help to detect errors (error will be reported if a wrong\
441 weekday is entered). BTW, an entry can go for several lines as\
442 long as there is a backslash at the end of each line.
443  
444 May 6 an example birthday (yearly entry)
445  
446 Wed 13:30-14:30 DNLP
447 Wed 15:30-16:30 Teaching (CSCI 3136) :until Apr 8, 2005
448 Wed 3-4:30pm meeting
449 Mon,Wed,Fri 10:30-11:30 meeting (product team)
450 Mon 13-14 seminar :biweekly :start Mar 8, 2004
451 Tue,Thu 10-11:30 Class (ECMM 6014) Location: MCCAIN ARTS&SS 2022 :until Apr 8, 2004
452 1st,3rd Tue 10-11 meeting
453 1st,last Mon,Fri 4-5 meeting (4 meetings every month)
454 4th Thu 11:30-13 meeting (fcm)
455  
456 =head1 STATE VARIABLES
457  
458 =over 4
459  
460 =item StartTime
461  
462 Used as C<$obj-E<gt>{StartTime}>. Start time for various uses.
463 Usually it is the the beginning of the first interesting week.
464  
465 =item DefaultRowLabels
466  
467 Used as C<$obj-E<gt>{DefaultRowLabels}>. Includes pre-defined labels
468 for rows of the generated HTML schedule tables. The pre-defined value
469 is:
470  
471 $self->{DefaultRowLabels} = [qw( 08:00 12:00 17:00 )];
472  
473 =back
474  
475 =head1 METHODS
476  
477 =over 4
478  
479 =item new()
480  
481 Creates a new C<Calendar::Schedule> object and returns it.
482  
483 =cut
484 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
485 2 my $proto = shift;
486 2 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
020
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
487 2 my $self = { VEvents => [ ],
488 Entries => [ ],
489 Entries1 => [ ],
490 DayEntries => [ ],
491 ToDo => [ ],
492 RowLabels => [ ],
493 StartTime => 0,
494 ColLabel => "%A<br>%Y-%m-%d",
495 ShowDays => 'all', # 'workdays'
496 };
497  
498 2 bless($self, $class);
499  
500 2 $self->{'DefaultRowLabels'} = [ qw( 08:00 12:00 17:00 ) ];
501 2 $self->{'RowLabels'} = [ @{ $self->{'DefaultRowLabels'} } ];
502  
503 2 $self->set_first_week(time);
504  
505 2 return $self;
506 }
507  
508 =item set_first_week(time)
509  
510 sets start time at the last Monday before given date. It is used in generate_table.
511 Examples:
512  
513 $TTable = Calendar::Schedule->new();
514 $TTable->set_first_week('now');
515 $TTable->set_first_week('2016-02-19');
516  
517 See parse_time for examples for specifying time.
518 =cut
519 3 ▶sub set_first_week {
Subroutine set_first_week: called CC=1 SCAR=0.0
Pod documented
520 3 my $self = shift;
521 3 my $arg = shift;
522 3 my $starttime = &parse_time($arg);
523  
524 3 $self->{'StartTime'} = $self->{'ContextTime'} =
525 &find_week_start($starttime);
526 }
527  
528 =item set_ColLabel(pattern)
529  
530 sets C<strftime> pattern for column (day) labels. The default pattern
531 is "C<%AE<lt>brE<gt>%Y-%m-%d>", which produces labels like:
532  
533 Friday
534 2003-12-19
535  
536 In order to have just a weekday name, use "C<%A>".
537  
538 =cut
539 0 ▶sub set_ColLabel {
Subroutine set_ColLabel: not called CC=1 SCAR=6.9
Pod documented
540 0 my $self = shift;
541 0 my $arg = shift;
542 0 $self->{'ColLabel'} = $arg;
543 }
544  
545 5 ▶sub find_week_start {
Subroutine find_week_start: called CC=5 SCAR=16.1
Pod undocumented
546 5 my $starttime = shift;
547  
548 5 ▶ while ((localtime($starttime))[6] != 1)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[6] != 1) 12 5 17
549 12 { $starttime -= 86400 }
550  
551 5 ▶ while ((localtime($starttime))[2] != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[2] != 0) 55 5 60
552 55 { $starttime -= 3600 }
553  
554 5 ▶ while ((localtime($starttime))[1] != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[1] != 0) 66 5 71
555 66 { $starttime -= 60 }
556  
557 5 ▶ while ((localtime($starttime))[0] != 0)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[0] != 0) 170 5 175
558 170 { $starttime -- }
559  
560 5 return $starttime;
561 }
562  
563 =item parse_time(time_specification[,prefix])
564  
565 Parses time specification and returns the calendar time (see mktime in
566 Perl). The functions dies if the time cannot be completely recognized.
567 If prefix is set to true (1), then only a prefix of the string can be
568 a time specification. If prefix is set to 1, then in an array context
569 it will return a 2-element list: the calendar time and the
570 remainder of the string. Format examples:
571  
572 2004-03-17
573 now
574 Mar 8, 2004
575 1-Jul-2005
576  
577 =cut
578 #mktime(sec,min,hour,mday,mon,year,wday=0,yday=0,isdst=0)
579 #mon,wday,yday start with 0,wday starts with Sun,year starts with 1900
580 # usually set last 3 to -1
581 # ('YYYY-MM-DD') now
582 3 ▶sub parse_time {
Subroutine parse_time: called CC=10 SCAR=27.4
Pod documented
583 3 my $time = shift;
584 3 my $prefix = shift;
585 3 ▶ my $endrex = ( $prefix ? qr// : qr/\s*$/ );
Branch: 1 branch
BranchTrueFalseTotal
$prefix ? : 0 3 3
586 3 my ($ret, $ret2);
587 3 my $monrex = $REmonth3;
588 3 ▶ if ($time =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d?):(\d\d)$endrex/)
Branch: 7 branches
BranchTrueFalseTotal
if ($time =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d\d?):(\d\d)$endrex/) { } 0 3 3
elsif ($time =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$endrex/) { } 0 3 3
elsif ($time =~ /^(\d\d)-(\d\d)-(\d\d\d\d)$endrex/) { } 0 3 3
elsif ($time =~ /^(\d?\d)-($monrex)-(\d\d\d\d)\b$endrex/) { } 0 3 3
elsif ($time =~ /^($monrex) (\d?\d), (\d\d\d\d)\b$endrex/) { } 0 3 3
elsif ($time =~ /^\d+$endrex/) { } 2 1 3
elsif ($time =~ /^now\b$endrex/) { } 1 0 1
589 0 { $ret = mktime(0,$5,$4,$3,$2-1,$1-1900,-1,-1,-1) }
590 elsif ($time =~ /^(\d\d\d\d)-(\d\d)-(\d\d)$endrex/)
591 0 { $ret = mktime(0,0,0,$3,$2-1,$1-1900,-1,-1,-1) }
592 elsif ($time =~ /^(\d\d)-(\d\d)-(\d\d\d\d)$endrex/)
593 0 { $ret = mktime(0,0,0,$1,$2-1,$3-1900,-1,-1,-1) }
594 elsif ($time =~ /^(\d?\d)-($monrex)-(\d\d\d\d)\b$endrex/)
595 0 { $ret = mktime(0,0,0,$1,&month_to_digits($2),$3-1900,-1,-1,-1) }
596 elsif ($time =~ /^($monrex) (\d?\d), (\d\d\d\d)\b$endrex/)
597 0 { $ret = mktime(0,0,0,$2,&month_to_digits($1),$3-1900,-1,-1,-1) }
598 2 elsif ($time =~ /^\d+$endrex/) { $ret = $time }
599 1 elsif ($time =~/^now\b$endrex/) { $ret = time }
600 0 ▶ else { use Carp; confess "cannot parse time:($time)" }
Subroutine BEGIN: called CC=1 SCAR=0.2
601 3 $ret2 = $';
602 3 ▶ return wantarray ? ($ret, $ret2) : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
603 }
604  
605 =item add_entries_from(file_name)
606  
607 Adds entries from a file. See method add_entries and add_entry for format explanation.
608  
609 =cut
610 0 ▶sub add_entries_from {
Subroutine add_entries_from: not called CC=1 SCAR=6.9
Pod documented
611 0 my $self = shift;
612 0 my $fname = shift;
613 0 return $self->add_entries(scalar(_getfile($fname)));
614 }
615  
616 =item add_entries(list_of_entries)
617  
618 Adds more entries. Each entry may contain several entries separated
619 by a new-line, except if the line ends with \.
620 Empty lines and lines that start with \s*# are ignored.
621 See add_entry for further explanation of format.
622  
623 =cut
624 11 ▶sub add_entries {
Subroutine add_entries: called CC=5 SCAR=16.2
Pod documented
625 11 my $self = shift;
626 11 ▶ while ($#_ > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ > -1) 11 11 22
627 11 my $entries = shift;
628 11 foreach my $en (split(/(?<!\\)\n/, $entries)) {
629 20 ▶ next if $en =~ /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if $en =~ /^\s*$/ 0 20 20
630 20 ▶ next if $en =~ /^\s*#/;
Branch: 1 branch
BranchTrueFalseTotal
if $en =~ /^\s*#/ 0 20 20
631 20 $en =~ s/\\\n/\n/g;
632 20 $self->add_entry($en);
633 }
634 }
635 }
636  
637 =item add_entry(list_of_entries)
638  
639 Adds more entries. It is different from add_entries because this
640 method does not break entries on new-lines, although it does accept a
641 list of entries as arguments.
642  
643 Examples:
644  
645 $TTable->add_entry('Mon 8-17', 'Labour Day');
646 $TTable->add_entry('2003-09-09 Tue 18-20 Some meeting');
647  
648 More format examples:
649  
650 Wed 3-4:30pm meeting
651 Mon,Wed,Fri 15:30-16:30 meeting (product team)
652 Mon 13-14 seminar :biweekly :start Mar 8, 2004
653 Tue,Thu 10-11:30 Class (ECMM 6014) Location: MCCAIN ARTS&SS 2022 :until Apr 8, 2004
654 1st,3rd Tue 10-11 meeting
655 1st,last Mon,Fri 4-5 meeting (4 meetings every month)
656  
657 More examples can be found in section "Example entries".
658  
659 =cut
660 20 ▶sub add_entry {
Subroutine add_entry: called CC=55 SCAR=75.6
Pod documented
661 20 my $self = shift;
662  
663 20 ▶ if ($#_ <= 1) { # entry not structured, needs to be
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ <= 1) { } 20 0 20
664 # parsed (string)
665 20 my $timeslot = shift;
666 20 my $description;
667 0 ▶ if ($#_ == 0) { $description = shift }
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == 0) { } 0 20 20
668 else {
669 20 local $_ = $timeslot;
670 #2003-09-09 Tue 18-20
671 20 ▶ if (/^\d\d\d\d-\d\d-\d\d $REweekday3 \d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /)
Branch: 8 branches
BranchTrueFalseTotal
if (/^\d\d\d\d-\d\d-\d\d $Calendar::Schedule::REweekday3 \d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /) { } 0 20 20
elsif (/^\d\d\d\d-\d\d-\d\d \d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /) { } 0 20 20
elsif (/^$Calendar::Schedule::REweekday3(?:,$Calendar::Schedule::REweekday3)*\s+\d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /) { } 20 0 20
elsif (/^$Calendar::Schedule::RE1st(,$Calendar::Schedule::RE1st)* \ $Calendar::Schedule::REweekday3(?:,$Calendar::Schedule::REweekday3)*\s+\d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)?\ /x) { } 0 0 0
elsif (/^(\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)- (\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)?/x) { } 0 0 0
elsif (/^(\d\d\d\d-\d\d-\d\d) / or /^(\d?\d-\w\w\w-\d\d\d\d) /) { } 0 0 0
elsif (/^\*\s*/) { } 0 0 0
elsif (/^($Calendar::Schedule::REweekday3)\b\s*/) { } 0 0 0
672 0 { $timeslot = $&; $description = $'; }
673 elsif (/^\d\d\d\d-\d\d-\d\d \d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /)
674 0 { $timeslot = $&; $description = $'; }
675 #<? $CP.="Wed 3-4:30pm meeting\n" !>
676 elsif (/^$REweekday3(?:,$REweekday3)*\s+\d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)? /)
677 20 { $timeslot = $&; $description = $'; }
678 #<? $CP.="3rd Tue 3-4:30pm meeting\n" !>
679 elsif (/^$RE1st(,$RE1st)*
680 \ $REweekday3(?:,$REweekday3)*\s+\d\d?(:\d\d)?-\d\d?(:\d\d)?([ap]m)?\ /x)
681 0 { $timeslot = $&; $description = $'; }
682 #iso8601 thanks to Mike Vasiljevs
683 elsif (/^(\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)-
684 (\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)?/x)
685 0 { $timeslot = $&; $description = $'; }
686 ▶ elsif (/^(\d\d\d\d-\d\d-\d\d) / ||
Condition0%0/3
/^(\d\d\d\d-\d\d-\d\d) / or /^(\d?\d-\w\w\w-\d\d\d\d) /
l!l&&r!l&&!r
000
MC/DC0%0/2
/^(\d\d\d\d-\d\d-\d\d) / or /^(\d?\d-\w\w\w-\d\d\d\d) /
/^(\d\d\d\d-\d\d-\d\d) / /^(\d?\d-\w\w\w-\d\d\d\d) /
Truth table0%0/3
A or B
A= /^(\d\d\d\d-\d\d-\d\d) /B= /^(\d?\d-\w\w\w-\d\d\d\d) /
ABresult
1X1
011
000
687 /^(\d?\d-\w\w\w-\d\d\d\d) /
688 )
689 {
690 0 $timeslot = parse_time($1);
691 0 $description = $';
692 0 push @{ $self->{'DayEntries'}},
693 { date => $timeslot, description => $description };
694 0 return;
695 }
696 elsif (/^\*\s*/) {
697 0 push @{ $self->{'ToDo'}}, { desc=>$' };
698 0 return;
699 }
700 #<? $CP.="Wed :biweekly garbage collection\n" !>
701 0 elsif (/^($REweekday3)\b\s*/) { $timeslot=$1; $description=$'; }
702 0 else { ($timeslot, $description) = parse_time($_, 1) }
703 20 $timeslot =~ s/\s+$//;
704 }
705  
706 20 my ($starttime, $endtime);
707  
708 20 ▶ if ($timeslot =~ /^($REweekday3(?:,$REweekday3)*)\s+(\d\d?(?::\d\d)?)-(\d\d?(?::\d\d)?)((?:[ap]m)?)$/) {
Branch: 6 branches
BranchTrueFalseTotal
if ($timeslot =~ /^($Calendar::Schedule::REweekday3(?:,$Calendar::Schedule::REweekday3)*)\s+(\d\d?(?::\d\d)?)-(\d\d?(?::\d\d)?)((?:[ap]m)?)$/) { } 20 0 20
elsif ($timeslot =~ /^($Calendar::Schedule::RE1st(?:,$Calendar::Schedule::RE1st)*)\s+ ($Calendar::Schedule::REweekday3(?:,$Calendar::Schedule::REweekday3)*)\s+ (\d\d?(?::\d\d)?)-(\d\d?(?::\d\d)?)([ap]m)?$ /xi) { } 0 0 0
elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)- (\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)$/x) { } 0 0 0
elsif ($timeslot =~ /^($Calendar::Schedule::REweekday3(?:,$Calendar::Schedule::REweekday3)*)$/) { } 0 0 0
elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)((?:\ $Calendar::Schedule::REweekday3)?) \ (\d\d?)((?::\d\d)?)-(\d\d?)((?::\d\d)?)(?:am)?$/x) { } 0 0 0
elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)((?: $Calendar::Schedule::REweekday3)?) (\d\d?)((?::\d\d)?)-(\d\d?)((?::\d\d)?)pm$/) { } 0 0 0
709 20 my ($days,$stime,$etime,$ampm) = ($1, $2, $3, $4);
710 20 $stime .= $ampm; $etime .= $ampm;
711  
712 20 my $rrule = 'FREQ=WEEKLY';
713 20 ▶ if ($description =~ /\s*:biweekly\b\s*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /\s*:biweekly\b\s*/) 0 20 20
714 0 $description = "$` $'";
715 0 $rrule .= ':INTERVAL=2';
716 }
717 20 ▶ if ($description =~ /\s*:until\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /\s*:until\s+/) 0 20 20
718 0 my $p1 = $`; my $p2 = $';
719 0 my ($t, $p2n) = parse_time($p2, 1);
720 0 $description = "$p1 $p2n";
721 0 $rrule .= ";UNTIL=".$self->find_next_time("23:59", $t);
722 }
723 20 my $starttime = $self->{'StartTime'};
724 20 ▶ if ($description =~ /:start\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /:start\s+/) 0 20 20
725 0 my $d1 = $`; my $d2 = $';
726 0 ($starttime, $d2) = parse_time($d2, 1);
727 0 $description = "$d1$d2";
728 }
729
730 20 foreach my $d (split(/,/, $days)) {
731 20 my %vevent = ();
732 20 $vevent{'RRULE'} = $rrule;
733 20 $vevent{'DTSTART'} = $self->find_next_time("$d $stime", $starttime);
734 20 $vevent{'DTEND'} = $self->find_next_time("$d $etime", $starttime);
735 20 ▶ while ($vevent{'DTEND'} < $vevent{'DTSTART'})
Branch: 1 branch
BranchTrueFalseTotal
if ($vevent{"DTEND"} < $vevent{"DTSTART"}) 0 20 20
736 0 { $vevent{'DTEND'} = $self->find_next_time("$d $etime", $vevent{'DTEND'}) }
737 20 $vevent{'SUMMARY'} = $description;
738 20 push @{ $self->{'VEvents'} }, \%vevent;
739 }
740 20 return;
741 }
742 # pattern 1:
743 elsif ($timeslot =~ /^($RE1st(?:,$RE1st)*)\s+
744 ($REweekday3(?:,$REweekday3)*)\s+
745 (\d\d?(?::\d\d)?)-(\d\d?(?::\d\d)?)([ap]m)?$
746 /ix) { # pattern 1:
747 0 my ($first,$days,$stime,$etime,$ampm) = ($1,$2,$3,$4,$5);
748 0 $stime .= $ampm; $etime .= $ampm;
749 # example: RRULE:FREQ=MONTHLY;BYDAY=+3TU
750 0 my $rrule = 'FREQ=MONTHLY'; my @first;
751 0 foreach my $f (split(/,/, $first)) {
752 0 my $f1;
753 0 ▶ if ($f =~ /^first|1st$/) { $f1 = '+1' }
Branch: 6 branches
BranchTrueFalseTotal
if ($f =~ /^first|1st$/) { } 0 0 0
elsif ($f =~ /^second|2nd$/) { } 0 0 0
elsif ($f =~ /^third|3rd$/) { } 0 0 0
elsif ($f =~ /^fourth|4th$/) { } 0 0 0
elsif ($f =~ /^fifth|5th$/) { } 0 0 0
elsif ($f =~ /^last$/) { } 0 0 0
754 0 elsif ($f =~ /^second|2nd$/) { $f1 = '+2' }
755 0 elsif ($f =~ /^third|3rd$/) { $f1 = '+3' }
756 0 elsif ($f =~ /^fourth|4th$/) { $f1 = '+4' }
757 0 elsif ($f =~ /^fifth|5th$/) { $f1 = '+5' }
758 0 elsif ($f =~ /^last$/) { $f1 = '-1' }
759 0 else {die}
760 0 ▶ push @first, $f1 unless grep {$f1 eq $_} @first;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$f1 eq $_;} @first 0 0 0
761 }
762 0 my @days; $rrule.=';BYDAY=';
763 0 my $startime = $self->{'StartTime'}; my ($st,$et);
764 0 foreach my $d (split(/,/, $days)) {
765 0 my $d1 = &weekday_to_WK($d);
766 0 ▶ push @days, $d1 unless grep {$d1 eq $_} @days;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$d1 eq $_;} @days 0 0 0
767 0 for my $f (@first) {
768 0 ▶ $rrule.=',' unless $rrule =~ /=$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $rrule =~ /=$/ 0 0 0
769 0 $rrule.="$f$d1";
770 0 my $t = $self->find_next_time("$d $stime", $starttime);
771 0 ▶ for (my $i=0;$i<=500;++$i,$t+=7*24*60*60) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= 500) 0 0 0
772 0 ▶ if (is_week_in_month($f,$t) and
Branch: 1 branch
BranchTrueFalseTotal
if (is_week_in_month($f, $t) and $t < $st || $st == 0) 0 0 0
Condition0%0/6
is_week_in_month($f, $t) and $t < $st || $st == 0
!ll&&!rl&&r
000
$t < $st or $st == 0
l!l&&r!l&&!r
000
MC/DC0%0/3
is_week_in_month($f, $t) and $t < $st || $st == 0
is_week_in_month($f, $t) $t < $st $st == 0
Truth table0%0/4
A and B or C
A= is_week_in_month($f, $t)B= $t < $stC= $st == 0
ABCresult
0XX0
1000
11X1
1011
773 ($t<$st or $st==0)) {
774 0 $st = $t;
775 0 $et = $self->find_next_time("$d $etime", $st);
776 }
777 }
778 }
779 }
780 0 my %vevent = ();
781 0 $vevent{'RRULE'} = $rrule;
782 0 $vevent{'DTSTART'} = $st;
783 0 $vevent{'DTEND'} = $et;
784 0 $vevent{'SUMMARY'} = $description;
785 0 push @{ $self->{'VEvents'} }, \%vevent;
786 0 return;
787 } # end of pattern 1:
788 # thanks to Mike Vasiljevs:
789 # 25 may 2006, adding matching for iso8601 dates
790 #
791 elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)-
792 (\d\d\d\d-\d\d-\d\d)T(\d\d:\d\d:\d\d)$/x) {
793 0 my ($hstart, $mstart, $sstart) = split(":", $2);
794 0 my ($hend, $mend, $send) = split(":", $4);
795 0 $starttime = parse_time("$1 $hstart:$mstart");
796 0 $endtime = parse_time("$1 $hend:$mend");
797 ##correct is to use second date in endtime, but it may lead to time leaks!?
798 #$endtime = parse_time("$3 $hend$mend");
799 }
800 elsif ($timeslot =~ /^($REweekday3(?:,$REweekday3)*)$/) {
801 0 my ($days) = ($1);
802  
803 0 my $rrule = 'FREQ=WEEKLY';
804 0 ▶ if ($description =~ /\s*:biweekly\b\s*/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /\s*:biweekly\b\s*/) 0 0 0
805 0 $description = "$` $'";
806 0 $rrule .= ':INTERVAL=2';
807 }
808 0 ▶ if ($description =~ /\s*:until\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /\s*:until\s+/) 0 0 0
809 0 my $p1 = $`; my $p2 = $';
810 0 my ($t, $p2n) = parse_time($p2, 1);
811 0 $description = "$p1 $p2n";
812 0 $rrule .= ";UNTIL=".$self->find_next_time("23:59", $t);
813 }
814 0 my $starttime = $self->{'StartTime'};
815 0 ▶ if ($description =~ /:start\s+/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($description =~ /:start\s+/) 0 0 0
816 0 my $d1 = $`; my $d2 = $';
817 0 ($starttime, $d2) = parse_time($d2, 1);
818 0 $description = "$d1$d2";
819 }
820
821 0 foreach my $d (split(/,/, $days)) {
822 0 my %vevent = ();
823 0 $vevent{'DTSTART'} = $self->find_next_time("$d 00:00", $starttime);
824 # not DTEND signals DayEntry
825 0 $vevent{'RRULE'} = $rrule;
826 0 $vevent{'SUMMARY'} = $description;
827 0 push @{ $self->{'VEvents'} }, \%vevent;
828 }
829 0 return;
830 }
831 elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)((?:\ $REweekday3)?)
832 \ (\d\d?)((?::\d\d)?)-(\d\d?)((?::\d\d)?)(?:am)?$/x) {
833 0 ▶ my $minstart = $4; $minstart = ":00" unless $minstart ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless $minstart ne "" 0 0 0
834 0 ▶ my $minend = $6; $minend = ":00" unless $minend ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless $minend ne "" 0 0 0
835 0 $starttime = parse_time("$1 $3$minstart");
836 0 $endtime = parse_time("$1 $5$minend");
837 0 my $w3 = $2; $w3 =~ s/^\s+//;
838 0 ▶ die "wrong weekday:($timeslot)" if $w3 ne '' &&
Branch: 1 branch
BranchTrueFalseTotal
if $w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3 0 0 0
Condition0%0/6
$w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3
!ll&&!rl&&r
000
strftime("%a", localtime $starttime) ne $w3 or strftime("%a", localtime $endtime) ne $w3
l!l&&r!l&&!r
000
MC/DC0%0/3
$w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3
$w3 ne "" strftime("%a", localtime $starttime) ne $w3 strftime("%a", localtime $endtime) ne $w3
Truth table0%0/4
A and B or C
A= $w3 ne ""B= strftime("%a", localtime $starttime) ne $w3C= strftime("%a", localtime $endtime) ne $w3
ABCresult
0XX0
1000
11X1
1011
839 (strftime("%a",localtime($starttime)) ne $w3 ||
840 strftime("%a",localtime($endtime)) ne $w3);
841 }
842 #2003-09-08 Mon 1-2pm
843 elsif ($timeslot =~ /^(\d\d\d\d-\d\d-\d\d)((?: $REweekday3)?) (\d\d?)((?::\d\d)?)-(\d\d?)((?::\d\d)?)pm$/) {
844 0 ▶ my $minstart = $4; $minstart = ":00" unless $minstart ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless $minstart ne "" 0 0 0
845 0 ▶ my $minend = $6; $minend = ":00" unless $minend ne '';
Branch: 1 branch
BranchTrueFalseTotal
unless $minend ne "" 0 0 0
846 0 $starttime = parse_time("$1 $3$minstart");
847 0 $endtime = parse_time("$1 $5$minend");
848  
849 0 ▶ if ($starttime < $endtime) { $starttime += 12*60*60 };
Branch: 1 branch
BranchTrueFalseTotal
if ($starttime < $endtime) 0 0 0
850 0 $endtime += 12*60*60;
851  
852 0 my $w3 = $2; $w3 =~ s/^\s+//;
853 0 ▶ die "wrong weekday:($timeslot)" if $w3 ne '' &&
Branch: 1 branch
BranchTrueFalseTotal
if $w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3 0 0 0
Condition0%0/6
$w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3
!ll&&!rl&&r
000
strftime("%a", localtime $starttime) ne $w3 or strftime("%a", localtime $endtime) ne $w3
l!l&&r!l&&!r
000
MC/DC0%0/3
$w3 ne "" and strftime("%a", localtime $starttime) ne $w3 || strftime("%a", localtime $endtime) ne $w3
$w3 ne "" strftime("%a", localtime $starttime) ne $w3 strftime("%a", localtime $endtime) ne $w3
Truth table0%0/4
A and B or C
A= $w3 ne ""B= strftime("%a", localtime $starttime) ne $w3C= strftime("%a", localtime $endtime) ne $w3
ABCresult
0XX0
1000
11X1
1011
854 (strftime("%a",localtime($starttime)) ne $w3 ||
855 strftime("%a",localtime($endtime)) ne $w3);
856 }
857 0 else { die "cannot parse timeslot:($timeslot)" }
858  
859 0 ▶ die "start>end: $timeslot" if $starttime > $endtime;
Branch: 1 branch
BranchTrueFalseTotal
if $starttime > $endtime 0 0 0
860  
861 0 push @{ $self->{'Entries1'}} , { starttime => $starttime,
862 endtime => $endtime,
863 description => $description };
864  
865 }
866 else {
867 0 my $col = shift;
868 0 my $start = shift;
869 0 my $end = shift;
870 0 my $text = shift;
871 0 push @{ $self->{'Entries'} }, { col => $col,
872 start => $start,
873 end => $end,
874 text => $text };
875 }
876  
877 } # end of add_entry
878  
879 =item find_next_time(time_spec[,start_time])
880  
881 Finds next time starting from start_time according to time_spec
882 specification and returns it. If the start_time is not given, the
883 variable StartTime is used.
884  
885 Examples:
886  
887 $t = $schedule->find_next_time("23:59", $t);
888  
889 =cut
890 40 ▶sub find_next_time {
Subroutine find_next_time: called CC=19 SCAR=36.9
Pod documented
891 40 my $self = shift;
892 40 my $timedesc = shift;
893  
894 40 ▶ my $starttime = ( $#_ == -1 ? $self->{'StartTime'} : shift @_ );
Branch: 1 branch
BranchTrueFalseTotal
$#_ == -1 ? : 0 40 40
895  
896 40 my $pattern_wday = '*';
897 40 my $pattern_hour = '*';
898 40 my $pattern_min = '*';
899 40 my $pattern_sec = 0;
900  
901 40 ▶ if ($timedesc =~ /^($REweekday3) (\d\d?(?::\d\d)?)((?:[ap]m)?)$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($timedesc =~ /^($Calendar::Schedule::REweekday3) (\d\d?(?::\d\d)?)((?:[ap]m)?)$/) { } 40 0 40
elsif ($timedesc =~ /^(\d?\d):(\d?\d)$/) { } 0 0 0
902 40 my $apm = $3;
903 40 $pattern_wday = weekday_to_digits($1);
904 40 $pattern_hour = $2;
905 40 $pattern_min = 0;
906 40 ▶ if ($pattern_hour =~ /:/) { $pattern_min=$'; $pattern_hour=$` }
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_hour =~ /:/) 26 14 40
907 40 $pattern_sec = 0;
908  
909 40 ▶ if ($apm eq 'pm') {
Branch: 2 branches
BranchTrueFalseTotal
if ($apm eq 'pm') { } 0 40 40
elsif ($apm eq 'am') { } 0 40 40
910 0 ▶ die unless $pattern_hour <= 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern_hour <= 12 0 0 0
911 0 ▶ if ($pattern_hour < 12) { $pattern_hour += 12 }
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_hour < 12) 0 0 0
912 }
913 elsif ($apm eq 'am') {
914 0 ▶ die unless $pattern_hour <= 12;
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern_hour <= 12 0 0 0
915 0 ▶ if ($pattern_hour == 12) { $pattern_hour = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_hour == 12) 0 0 0
916 }
917 } elsif ($timedesc =~ /^(\d?\d):(\d?\d)$/) {
918 0 $pattern_hour = $1; $pattern_min=$2;
919 0 } else { die "cannot parse:($timedesc)" }
920  
921 # find seconds
922 40 ▶ if ($pattern_sec ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_sec ne "*") 40 0 40
923 40 ▶ while ((localtime($starttime))[0] != $pattern_sec)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[0] != $pattern_sec) 0 40 40
924 0 { $starttime ++ }
925 }
926  
927 # find minutes
928 40 ▶ if ($pattern_min ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_min ne "*") 40 0 40
929 40 ▶ while ((localtime($starttime))[1] != $pattern_min)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[1] != $pattern_min) 780 40 820
930 780 { $starttime += 60 }
931 }
932  
933 # find hour
934 40 ▶ if ($pattern_hour ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_hour ne "*") 40 0 40
935 40 ▶ while ((localtime($starttime))[2] != $pattern_hour)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[2] != $pattern_hour) 576 40 616
936 576 { $starttime += 3600 }
937 }
938  
939 # find weekday
940 40 ▶ if ($pattern_wday ne '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern_wday ne "*") 40 0 40
941 40 ▶ while ((localtime($starttime))[6] != $pattern_wday)
Branch: 1 branch
BranchTrueFalseTotal
if ((localtime $starttime)[6] != $pattern_wday) 92 40 132
942 92 { $starttime += 3600*24 }
943 }
944  
945 40 return $starttime;
946 }
947  
948 40 ▶sub add_time_label {
Subroutine add_time_label: called CC=5 SCAR=16.1
Pod undocumented
949 40 my $self = shift;
950 40 my $t = shift;
951 40 my @r = ();
952 40 ▶ while (@{$self->{'RowLabels'}} and $t gt $self->{'RowLabels'}[0])
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->{"RowLabels"};} and $t gt $self->{"RowLabels"}[0]) 212 40 252
Condition100%3/3
@{$self->{"RowLabels"};} and $t gt $self->{"RowLabels"}[0]
!ll&&!rl&&r
238212
MC/DC100%2/2
@{$self->{"RowLabels"};} and $t gt $self->{"RowLabels"}[0]
@{$self->{"RowLabels"};} $t gt $self->{"RowLabels"}[0]
Truth table100%3/3
A and B
A= @{$self->{"RowLabels"};}B= $t gt $self->{"RowLabels"}[0]
ABresult
0X0
100
111
953 212 { push @r, shift(@{$self->{'RowLabels'}}) }
954 40 ▶ push @r, $t unless @{$self->{'RowLabels'}} and $t eq $self->{'RowLabels'}[0];
Branch: 1 branch
BranchTrueFalseTotal
unless @{$self->{"RowLabels"};} and $t eq $self->{"RowLabels"}[0] 18 22 40
Condition100%3/3
@{$self->{"RowLabels"};} and $t eq $self->{"RowLabels"}[0]
!ll&&!rl&&r
21622
MC/DC100%2/2
@{$self->{"RowLabels"};} and $t eq $self->{"RowLabels"}[0]
@{$self->{"RowLabels"};} $t eq $self->{"RowLabels"}[0]
Truth table100%3/3
A and B
A= @{$self->{"RowLabels"};}B= $t eq $self->{"RowLabels"}[0]
ABresult
0X0
100
111
955 40 push @r, @{$self->{'RowLabels'}};
956 40 $self->{'RowLabels'} = \@r;
957 }
958  
959 0 ▶sub todo_list {
Subroutine todo_list: not called CC=2 SCAR=17.9
Pod undocumented
960 0 my $self = shift;
961 0 my $r = "TO DO list: ";
962 0 ▶ if (! @{ $self->{'ToDo'} } ) { $r .= "<empty>" }
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$self->{'ToDo'};}) { } 0 0 0
963 else {
964 $r .= "<ol>\n".
965 0 join('', map { "<li> $_->{'desc'}\n" }
966 0 @{ $self->{'ToDo'} }).
967 "</ol>\n";
968 }
969 0 return $r;
970 }
971  
972 =item generate_table()
973  
974 Returns a weekly table in HTML. Starts with NextTableTime (or
975 StartTime if NextTableTime does not exist), and updates NextTableTime
976 so that consecutive call produces the table for the following week.
977  
978 The table column headers can be can be changed by setting the field
979 $obj->{ColLabel} to a format as used by the standard function
980 strftime. The default format is: ColLabel => "%AE<lt>E<gt>%Y-%m-%d", which
981 looks something like:
982  
983 Monday
984 2008-09-01
985  
986 The format "%A" would produce just the weekday name.
987  
988 Use $obj->{ShowDays} = 'workdays'; to display only work-days; i.e.,
989 Monday to Friday.
990  
991 The table rows include time labeles which are start times and end
992 times of the events that happend to fall in the table time range, with
993 additional labels from the variable C<$obj-E<gt>{DefaultRowLabels}>.
994 The default value of the variable DefaulRowLabels is defined as:
995  
996 $self->{DefaultRowLabels} = [qw( 08:00 12:00 17:00 )];
997  
998 =cut
999 2 ▶sub generate_table {
Subroutine generate_table: called CC=68 SCAR=64.7
Pod documented
1000 2 my $self = shift;
1001 2 my (@prepareEntries, @dayEntries);
1002  
1003 $self->{'NextTableTime'} = $self->{'StartTime'}
1004 2 ▶ if ! exists($self->{'NextTableTime'});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"NextTableTime"} 2 0 2
1005 2 my $mondaytime = $self->{'NextTableTime'};
1006  
1007 2 my @showdays = 0..6; # ShowDays: all, workdays
1008 0 ▶ if ($self->{ShowDays} eq 'workdays') { @showdays = 0..4 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ShowDays"} eq "workdays") 0 2 2
1009  
1010 2 my @col_label;
1011 {
1012 2 my $p = $self->{'ColLabel'};
1013 @col_label = map {
1014 2 strftime($p, localtime($mondaytime + $_*86400))
1015 } @showdays;
1016 }
1017  
1018 2 foreach my $ve ( @{ $self->{'VEvents'} } ) {
1019 20 ▶ if (exists($ve->{'RRULE'}) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $ve->{'RRULE'} and $ve->{'RRULE'} =~ /\bFREQ=WEEKLY\b/) { } 20 0 20
elsif (exists $ve->{'RRULE'} and $ve->{'RRULE'} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/) { } 0 0 0
Condition33%1/3
exists $ve->{"RRULE"} and $ve->{"RRULE"} =~ /\bFREQ=WEEKLY\b/
!ll&&!rl&&r
0020
MC/DC0%0/2
exists $ve->{"RRULE"} and $ve->{"RRULE"} =~ /\bFREQ=WEEKLY\b/
exists $ve->{"RRULE"} $ve->{"RRULE"} =~ /\bFREQ=WEEKLY\b/
Truth table33%1/3
A and B
A= exists $ve->{"RRULE"}B= $ve->{"RRULE"} =~ /\bFREQ=WEEKLY\b/
ABresult
0X0
100
111
1020 $ve->{'RRULE'} =~ /\bFREQ=WEEKLY\b/) {
1021 20 my $d = 0;
1022 20 my $interval = 1;
1023 0 ▶ if ($ve->{'RRULE'} =~ /\bINTERVAL=(\d+)/) { $interval = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ve->{"RRULE"} =~ /\bINTERVAL=(\d+)/) 0 20 20
1024 20 my $until = undef;
1025 0 ▶ if ($ve->{'RRULE'} =~ /\bUNTIL=(\d+)/) { $until = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ve->{"RRULE"} =~ /\bUNTIL=(\d+)/) 0 20 20
1026  
1027 20 ▶ while ($d + $ve->{'DTSTART'} < $mondaytime + 86400*scalar(@showdays)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d + $ve->{"DTSTART"} < $mondaytime + 86400 * scalar(@showdays)) 20 20 40
1028 0 ▶ if (defined($until) && $d+$ve->{'DTSTART'} > $until) { last }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $until and $d + $ve->{"DTSTART"} > $until) 0 20 20
Condition33%1/3
defined $until and $d + $ve->{"DTSTART"} > $until
!ll&&!rl&&r
2000
MC/DC0%0/2
defined $until and $d + $ve->{"DTSTART"} > $until
defined $until $d + $ve->{"DTSTART"} > $until
Truth table33%1/3
A and B
A= defined $untilB= $d + $ve->{"DTSTART"} > $until
ABresult
0X0
100
111
1029  
1030 20 ▶ if ($d+$ve->{'DTSTART'} >= $mondaytime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d + $ve->{"DTSTART"} >= $mondaytime) 20 0 20
1031 20 ▶ if (exists($ve->{'DTEND'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ve->{'DTEND'}) { } 20 0 20
1032 push @prepareEntries,
1033 { starttime => $d+$ve->{'DTSTART'},
1034 endtime => $d+$ve->{'DTEND'},
1035 20 description => $ve->{'SUMMARY'} };
1036 } else {
1037 push @dayEntries,
1038 { date => $d+$ve->{'DTSTART'},
1039 0 description => $ve->{'SUMMARY'} };
1040 }
1041 }
1042 20 my @a = localtime($d+$ve->{'DTSTART'});
1043 20 $d += 86400*7*$interval;
1044 20 my @b;
1045 20 ▶ if (exists($ve->{'DTEND'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ve->{'DTEND'}) { } 20 0 20
1046 20 @b = localtime($d+$ve->{'DTEND'});
1047 }
1048 0 else { @b = localtime($d+$ve->{'DTSTART'} + 60) }
1049 20 $d += ($a[8]-$b[8])*3600; # daylight saving
1050 }
1051 }
1052 # example: RRULE:FREQ=MONTHLY;BYDAY=+3TU
1053 ▶ elsif (exists($ve->{'RRULE'}) &&
Condition0%0/3
exists $ve->{"RRULE"} and $ve->{"RRULE"} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $ve->{"RRULE"} and $ve->{"RRULE"} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/
exists $ve->{"RRULE"} $ve->{"RRULE"} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/
Truth table0%0/3
A and B
A= exists $ve->{"RRULE"}B= $ve->{"RRULE"} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/
ABresult
0X0
100
111
1054 $ve->{'RRULE'} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/) {
1055 0 my $byday = $1;
1056 0 my $interval = 1;
1057 0 ▶ if ($ve->{'RRULE'} =~ /\bINTERVAL=(\d+)/) { $interval = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ve->{"RRULE"} =~ /\bINTERVAL=(\d+)/) 0 0 0
1058 0 my $until = undef;
1059 0 ▶ if ($ve->{'RRULE'} =~ /\bUNTIL=(\d+)/) { $until = $1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($ve->{"RRULE"} =~ /\bUNTIL=(\d+)/) 0 0 0
1060 0 my @byday = split(/,/,$byday);
1061 0 my @fwd = (); my %wds;
1062 0 for my $bd (@byday) {
1063 0 ▶ $bd =~ /^([+-][1-5])(\w\w)$/ or die;
Branch: 1 branch
BranchTrueFalseTotal
$bd =~ /^([+-][1-5])(\w\w)$/ or die 0 0 0
1064 0 my $f = $1, my $wd = $2; push @fwd, $f, $wd;
1065 0 $wds{$wd} = 1;
1066 }
1067  
1068 0 my $eventstarti = $ve->{'DTSTART'};
1069 0 ▶ my $daysincrement = (scalar(keys %wds)==1? 7 : 1);
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %wds == 1 ? : 0 0 0
1070 0 ▶ unless (defined($ve->{_cache_next}))
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ve->{"_cache_next"}) 0 0 0
1071 0 { $ve->{_cache_next} = { } }
1072 0 ▶ while ($eventstarti < $mondaytime + 86400*scalar(@showdays)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eventstarti < $mondaytime + 86400 * scalar(@showdays)) 0 0 0
1073 0 ▶ last if defined($until) && $eventstarti > $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $eventstarti > $until 0 0 0
Condition0%0/3
defined $until and $eventstarti > $until
!ll&&!rl&&r
000
MC/DC0%0/2
defined $until and $eventstarti > $until
defined $until $eventstarti > $until
Truth table0%0/3
A and B
A= defined $untilB= $eventstarti > $until
ABresult
0X0
100
111
1074 0 ▶ goto L1 if $eventstarti < $mondaytime;
Branch: 1 branch
BranchTrueFalseTotal
if $eventstarti < $mondaytime 0 0 0
1075 0 ▶ if ($eventstarti >= $mondaytime) {
Branch: 1 branch
BranchTrueFalseTotal
if ($eventstarti >= $mondaytime) 0 0 0
1076 0 ▶ if (exists($ve->{'DTEND'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ve->{'DTEND'}) { } 0 0 0
1077 push @prepareEntries,
1078 { starttime => $eventstarti,
1079 endtime => $eventstarti - $ve->{'DTSTART'}
1080 + $ve->{'DTEND'},
1081 0 description => $ve->{'SUMMARY'} };
1082 } else {
1083 push @dayEntries,
1084 { date => $eventstarti,
1085 0 description => $ve->{'SUMMARY'} };
1086 }
1087 }
1088
1089 L1:
1090 0 ▶ if (defined($ve->{_cache_next}{$eventstarti}))
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ve->{'_cache_next'}{$eventstarti}) { } 0 0 0
1091 0 { $eventstarti = $ve->{_cache_next}{$eventstarti} }
1092 else {
1093 0 my $t1 = $eventstarti;
1094 0 L2:
1095 my $t2 = days_increment_DSaware($t1,$daysincrement);
1096 0 ▶ last unless $t2 < $mondaytime + 86400*scalar(@showdays);
Branch: 1 branch
BranchTrueFalseTotal
unless $t2 < $mondaytime + 86400 * scalar(@showdays) 0 0 0
1097 0 ▶ last if defined($until) && $t2 > $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $t2 > $until 0 0 0
Condition0%0/3
defined $until and $t2 > $until
!ll&&!rl&&r
000
MC/DC0%0/2
defined $until and $t2 > $until
defined $until $t2 > $until
Truth table0%0/3
A and B
A= defined $untilB= $t2 > $until
ABresult
0X0
100
111
1098 0 ▶ if ($interval>1) { die "TODO" }
Branch: 1 branch
BranchTrueFalseTotal
if ($interval > 1) 0 0 0
1099 0 my $flag = '';
1100 0 ▶ for(my $i=0; $i<=$#fwd; $i+=2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#fwd) 0 0 0
1101 0 my $f = $fwd[$i]; my $wd = $fwd[$i+1];
1102 0 ▶ next unless weekday_to_digits($wd)==
Branch: 1 branch
BranchTrueFalseTotal
unless weekday_to_digits($wd) == (localtime $t2)[6] 0 0 0
1103 (localtime($t2))[6];
1104 0 ▶ next unless is_week_in_month($f, $t2);
Branch: 1 branch
BranchTrueFalseTotal
unless is_week_in_month($f, $t2) 0 0 0
1105 0 $flag = 1; last;
1106 }
1107 0 $t1 = $t2;
1108 0 ▶ goto L2 unless $flag;
Branch: 1 branch
BranchTrueFalseTotal
unless $flag 0 0 0
1109 0 $eventstarti = $ve->{_cache_next}{$eventstarti} = $t1;
1110 }
1111 }
1112 } # $ve->{'RRULE'} =~ /\bFREQ=MONTHLY;BYDAY=([^;]+)\b/
1113 } # foreach my $ve ( @{ $self->{'VEvents'} } ) {
1114  
1115 2 push @prepareEntries, @{ $self->{'Entries1'} };
1116  
1117 2 foreach my $entry ( @{ $self->{'Entries'} } ) {
1118 0 $self->add_time_label( $entry->{'start'} );
1119 0 $self->add_time_label( $entry->{'end'} );
1120 }
1121  
1122 2 foreach my $entry ( @prepareEntries ) {
1123 20 my $starttime = $entry->{'starttime'};
1124 20 my $endtime = $entry->{'endtime'};
1125  
1126 20 my $col = floor(($starttime - $mondaytime) / 86400);
1127 20 ▶ next if $col < 0 || $col >= scalar(@showdays);
Branch: 1 branch
BranchTrueFalseTotal
if $col < 0 or $col >= scalar @showdays 0 20 20
Condition33%1/3
$col < 0 or $col >= scalar @showdays
l!l&&r!l&&!r
0020
MC/DC0%0/2
$col < 0 or $col >= scalar @showdays
$col < 0 $col >= scalar @showdays
Truth table33%1/3
A or B
A= $col < 0B= $col >= scalar @showdays
ABresult
1X1
011
000
1128 20 my $startlabel = strftime("%H:%M", localtime($starttime));
1129 20 my $endlabel = strftime("%H:%M", localtime($endtime));
1130  
1131 20 $self->add_time_label($startlabel);
1132 20 $self->add_time_label($endlabel);
1133 }
1134  
1135 2 my %eprep;
1136 2 $self->{'overlap'} = [ ];
1137  
1138 2 foreach my $entry ( @{ $self->{'Entries'} } ) {
1139 0 my $col = $entry->{'col'};
1140 0 my $start = $entry->{'start'};
1141 0 my $end = $entry->{'end'};
1142 0 my $text = $entry->{'text'};
1143  
1144 0 $self->_table_add(\%eprep,$col, $start, $text, $end);
1145 }
1146  
1147 2 foreach my $entry ( @prepareEntries ) {
1148 20 my $starttime = $entry->{'starttime'};
1149 20 my $endtime = $entry->{'endtime'};
1150 20 my $description = $entry->{'description'};
1151  
1152 20 my $col = floor(($starttime - $mondaytime) / 86400);
1153 20 ▶ next if $col < 0 || $col >= scalar(@showdays);
Branch: 1 branch
BranchTrueFalseTotal
if $col < 0 or $col >= scalar @showdays 0 20 20
Condition33%1/3
$col < 0 or $col >= scalar @showdays
l!l&&r!l&&!r
0020
MC/DC0%0/2
$col < 0 or $col >= scalar @showdays
$col < 0 $col >= scalar @showdays
Truth table33%1/3
A or B
A= $col < 0B= $col >= scalar @showdays
ABresult
1X1
011
000
1154 20 my $startlabel = strftime("%H:%M", localtime($starttime));
1155 20 my $endlabel = strftime("%H:%M", localtime($endtime));
1156  
1157 20 $self->_table_add(\%eprep,$col, $startlabel, $description, $endlabel);
1158 }
1159  
1160 2 my $r = "<table width=100% border=2 cellspacing=1 cellpadding=1>\n".
1161 "<tr>\n".
1162 "<td valign=top>\&nbsp;</td>\n";
1163 2 my @op = @{ $self->{overlap} };
1164 2 foreach my $di (0 .. $#col_label) {
1165 14 ▶ $op[$di] = 0 unless defined($op[$di]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $op[$di] 4 10 14
1166 14 ▶ if ($op[$di] > 0) { $r.= "<th colspan=$op[$di]>" } else { $r.="<th>" }
Branch: 1 branch
BranchTrueFalseTotal
if ($op[$di] > 0) { } 2 12 14
1167 14 $r .= $col_label[$di]."</th>\n";
1168 }
1169 2 $r .= "</tr>\n";
1170  
1171 # check if there are any DayEntries
1172 push @dayEntries, grep { $_->{'date'} - $mondaytime >=0 &&
1173 0 ▶ $_->{'date'} - $mondaytime <= scalar(@showdays)*86400 }
Condition0%0/3
$_->{'date'} - $mondaytime >= 0 && $_->{'date'} - $mondaytime <= scalar(@showdays) * 86400
!ll&&!rl&&r
000
MC/DC0%0/2
$_->{'date'} - $mondaytime >= 0 && $_->{'date'} - $mondaytime <= scalar(@showdays) * 86400
$_->{'date'} - $mondaytime >= 0 $_->{'date'} - $mondaytime <= scalar(@showdays) * 86400
Truth table0%0/3
A && B
A= $_->{'date'} - $mondaytime >= 0B= $_->{'date'} - $mondaytime <= scalar(@showdays) * 86400
ABresult
0X0
100
111
1174 2 @{ $self->{'DayEntries'} };
1175 2 ▶ if ( @dayEntries ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dayEntries) 0 2 2
1176 0 $r .= '<tr><td>&nbsp;</td>';
1177 0 foreach my $i (0 .. $#col_label) {
1178
1179 0 my $r1;
1180 0 foreach my $de (grep { $_->{'date'} - $mondaytime == $i*86400 }
1181 @dayEntries )
1182 0 { $r1 .= $de->{'description'}."<br>\n" }
1183 0 ▶ $r1 = '&nbsp;' unless $r1;
Branch: 1 branch
BranchTrueFalseTotal
unless $r1 0 0 0
1184 0 ▶ $r .= ($op[$i]==0 ? "<td>" : "<td colspan=$op[$i]>") . "$r1</td>";
Branch: 1 branch
BranchTrueFalseTotal
$op[$i] == 0 ? : 0 0 0
1185 }
1186 0 $r .= "</tr>\n";
1187 }
1188  
1189 2 my $num_of_timelabels = @{$self->{'RowLabels'}};
1190 2 foreach my $ti (0 .. $num_of_timelabels - 1) {
1191  
1192 24 my $t = $self->{'RowLabels'}[$ti];
1193 24 $r.= "<tr><td>$t</td>\n";
1194 24 foreach my $di (0 .. $#col_label) {
1195 168 foreach my $oi (0 .. $op[$di]) {
1196 240 ▶ next if $oi == 1;
Branch: 1 branch
BranchTrueFalseTotal
if $oi == 1 24 216 240
1197 216 my @ind = (\%eprep, $di, $t);
1198 216 ▶ @ind = (\%eprep, $di, $t, $oi) if ($oi > 0);
Branch: 1 branch
BranchTrueFalseTotal
if $oi > 0 48 168 216
1199 216 ▶ if (! $self->_table_get(@ind)) { $r .= "<td align=center>\&nbsp;</td>\n" }
Branch: 2 branches
BranchTrueFalseTotal
if (not $self->_table_get(@ind)) { } 178 38 216
elsif ($self->_table_get(@ind) eq 'continue') { } 18 20 38
1200 18 elsif ($self->_table_get(@ind) eq 'continue') { $r.= "<!"."-- continue --".">\n" }
1201 else {
1202 20 my $counter = 1;
1203 20 my $j=$ti+1;
1204 20 my @ind1 = (\%eprep, $di, $self->{'RowLabels'}[$j]);
1205 20 ▶ @ind1 = (\%eprep, $di, $self->{'RowLabels'}[$j], $oi) if $oi > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $oi > 0 4 16 20
1206
1207 20 ▶ if ($oi == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oi == 0) { } 16 4 20
1208 16 ▶ while ($j <= $num_of_timelabels-1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j]) eq "continue") 10 16 26
Condition66%2/3
$j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j]) eq "continue"
!ll&&!rl&&r
01610
MC/DC50%1/2
$j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j]) eq "continue"
$j <= $num_of_timelabels - 1 $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j]) eq "continue"
Truth table66%2/3
A and B
A= $j <= $num_of_timelabels - 1B= $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j]) eq "continue"
ABresult
0X0
100
111
1209 $self->_table_get(\%eprep, $di,
1210 $self->{'RowLabels'}[$j]) eq
1211 'continue')
1212 10 { ++ $counter; ++$j }
1213 } else {
1214 4 ▶ while ($j <= $num_of_timelabels-1 &&
Branch: 1 branch
BranchTrueFalseTotal
if ($j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j], $oi) eq "continue") 8 4 12
Condition66%2/3
$j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j], $oi) eq "continue"
!ll&&!rl&&r
048
MC/DC50%1/2
$j <= $num_of_timelabels - 1 and $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j], $oi) eq "continue"
$j <= $num_of_timelabels - 1 $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j], $oi) eq "continue"
Truth table66%2/3
A and B
A= $j <= $num_of_timelabels - 1B= $self->_table_get(\%eprep, $di, $self->{"RowLabels"}[$j], $oi) eq "continue"
ABresult
0X0
100
111
1215 $self->_table_get(\%eprep, $di, $self->{'RowLabels'}[$j], $oi) eq 'continue')
1216 8 { ++ $counter; ++$j }
1217 }
1218 20 ▶ $r.= "<td align=center bgcolor=yellow".
Branch: 1 branch
BranchTrueFalseTotal
$counter > 1 ? : 14 6 20
1219 ($counter > 1 ? " rowspan=$counter" : '').
1220 ">".$self->_table_get(@ind)."</td>\n";
1221 }
1222 }
1223 }
1224 24 $r.= "</tr>\n";
1225 }
1226  
1227 2 $r.="</table>\n";
1228  
1229 $self->{'NextTableTime'} = # fix for daylight saving
1230 2 &find_week_start( $self->{'NextTableTime'} + 86400 * 7 + 7200 );
1231 2 $self->{'RowLabels'} = [ @{ $self->{'DefaultRowLabels'} } ];
1232 2 return $r;
1233 }
1234  
1235 =back
1236  
1237 =head1 FUNCTIONS
1238  
1239 =cut
1240  
1241 0 ▶sub is_week_in_month {
Subroutine is_week_in_month: not called CC=8 SCAR=42.8
Pod undocumented
1242 0 my $f = shift; # +1, +2, +3, +4, +5, or -1
1243 0 my $t = shift; # time in epoch sec
1244 0 my $d = (localtime($t))[3];
1245 0 my $m = (localtime($t))[4]; #0=Jan
1246 0 my ($lb,$ub);
1247 0 ▶ die if $f>5 or $f<-5;
Branch: 1 branch
BranchTrueFalseTotal
if $f > 5 or $f < -5 0 0 0
Condition0%0/3
$f > 5 or $f < -5
l!l&&r!l&&!r
000
MC/DC0%0/2
$f > 5 or $f < -5
$f > 5 $f < -5
Truth table0%0/3
A or B
A= $f > 5B= $f < -5
ABresult
1X1
011
000
1248 0 ▶ if ($f>0) { $lb = 7*$f-6; $ub = 7*$f; }
Branch: 2 branches
BranchTrueFalseTotal
if ($f > 0) { } 0 0 0
elsif ($f < 0) { } 0 0 0
1249 elsif ($f<0) {
1250 0 my $t1=$t;
1251 0 for(;;) { # find last day in the month
1252 0 $t1+=24*60*60;
1253 0 ▶ last if (localtime($t1))[4] != $m;
Branch: 1 branch
BranchTrueFalseTotal
if (localtime $t1)[4] != $m 0 0 0
1254 }
1255 0 $t1-=24*60*60;
1256 0 $ub = (localtime($t1))[3] + ($f+1)*7;
1257 0 $lb = $ub - 6;
1258 }
1259 0 else { return 1 }
1260 0 ▶ return 1 if $d>=$lb and $d<=$ub;
Branch: 1 branch
BranchTrueFalseTotal
if $d >= $lb and $d <= $ub 0 0 0
Condition0%0/3
$d >= $lb and $d <= $ub
!ll&&!rl&&r
000
MC/DC0%0/2
$d >= $lb and $d <= $ub
$d >= $lb $d <= $ub
Truth table0%0/3
A and B
A= $d >= $lbB= $d <= $ub
ABresult
0X0
100
111
1261 0 return 0;
1262 }
1263  
1264 =pod
1265  
1266 =head2 weekday_to_digits
1267  
1268 For example, changes all words "SUNDAY", "Sunday", "SUN", or "Sun" to "00", etc.
1269  
1270 =cut
1271  
1272 40 ▶sub weekday_to_digits {
Subroutine weekday_to_digits: called CC=1 SCAR=0.0
Pod documented
1273 40 local $_ = shift;
1274 40 s/\b(?:SUN?(?:DAY)?|Sun(?:day)?)\b/00/g;
1275 40 s/\b(?:MON?(?:DAY)?|Mon(?:day)?)\b/01/xg;
1276 40 s/\b(?:TUE?(?:SDAY)?|Tue(?:sday)?)\b/02/xg;
1277 40 s/\b(?:WED?(?:NESDAY)?|Wed(?:nesday)?)\b/03/xg;
1278 40 s/\b(?:THU?(?:RSDAY)?|Thu(?:rsday)?)\b/04/xg;
1279 40 s/\b(?:FRI?(?:DAY)?|Fri(?:day)?)\b/05/xg;
1280 40 s/\b(?:SAT?(?:URDAY)?|Sat(?:urday)?)\b/06/xg;
1281 40 return $_;
1282 }
1283  
1284 # weekday to two uppercase letters
1285 0 ▶sub weekday_to_WK {
Subroutine weekday_to_WK: not called CC=1 SCAR=6.9
Pod undocumented
1286 0 local $_ = shift;
1287 0 s/\b(?:SUN(?:DAY)?|Sun(?:day)?)\b /SU/xg;
1288 0 s/\b(?:MON(?:DAY)?|Mon(?:day)?)\b /MO/xg;
1289 0 s/\b(?:TUE(?:SDAY)?|Tue(?:sday)?)\b /TU/xg;
1290 0 s/\b(?:WED(?:NESDAY)?|Wed(?:nesday)?)\b/WE/xg;
1291 0 s/\b(?:THU(?:RSDAY)?|Thu(?:rsday)?)\b /TH/xg;
1292 0 s/\b(?:FRI(?:DAY)?|Fri(?:day)?)\b /FR/xg;
1293 0 s/\b(?:SAT(?:URDAY)?|Sat(?:urday)?)\b /SA/xg;
1294 0 return $_;
1295 }
1296  
1297 0 ▶sub month_to_digits {
Subroutine month_to_digits: not called CC=1 SCAR=6.9
Pod undocumented
1298 0 local $_ = shift;
1299 0 s/\b(?:JAN(?:UARY)?|Jan(?:uary)?)\b/00/g;
1300 0 s/\b(?:FEB(?:RUARY)?|Feb(?:ruary)?)\b/01/xg;
1301 0 s/\b(?:MAR(?:CH)?|Mar(?:ch)?)\b/02/xg;
1302 0 s/\b(?:APR(?:IL)?|Apr(?:il)?)\b/03/xg;
1303 0 s/\b(?:MAY(?:)?|May(?:)?)\b/04/xg;
1304 0 s/\b(?:JUN(?:E)?|Jun(?:e)?)\b/05/xg;
1305 0 s/\b(?:JUL(?:Y)?|Jul(?:y)?)\b/06/xg;
1306 0 s/\b(?:AUG(?:UST)?|Aug(?:ust)?)\b/07/xg;
1307 0 s/\b(?:SEP(?:TEMBER)?|Sep(?:tember)?)\b/08/xg;
1308 0 s/\b(?:OCT(?:OBER)?|Oct(?:ober)?)\b/09/xg;
1309 0 s/\b(?:NOV(?:EMBER)?|Nov(?:ember)?)\b/10/xg;
1310 0 s/\b(?:DEC(?:EMBER)?|Dec(?:ember)?)\b/11/xg;
1311 0 return $_;
1312 }
1313  
1314 # increment time for certain number of days, daylight saving aware
1315 0 ▶sub days_increment_DSaware {
Subroutine days_increment_DSaware: not called CC=4 SCAR=30.0
Pod undocumented
1316 0 my $t = shift; my $i = shift;
1317 0 my $t1 = $t + 86400*$i;
1318 0 my $t2 = $t; my $t3 = $t1;
1319 0 my @a = localtime($t2);
1320 0 ▶ if ($a[2]==0 && $a[1]==0) # problem with 0h and 23h
Branch: 2 branches
BranchTrueFalseTotal
if ($a[2] == 0 and $a[1] == 0) { } 0 0 0
elsif ($a[2] == 23) { } 0 0 0
Condition0%0/3
$a[2] == 0 and $a[1] == 0
!ll&&!rl&&r
000
MC/DC0%0/2
$a[2] == 0 and $a[1] == 0
$a[2] == 0 $a[1] == 0
Truth table0%0/3
A and B
A= $a[2] == 0B= $a[1] == 0
ABresult
0X0
100
111
1321 0 { $t2 += 60; $t3 += 60; @a = localtime($t2); }
1322 0 elsif ($a[2]==23) { $t2 -= 60; $t3 -= 60; @a = localtime($t2); }
1323  
1324 0 my @b = localtime($t3);
1325 0 $t1 += ($a[8]-$b[8])*3600; # daylight saving
1326 0 return $t1;
1327 }
1328  
1329 20 ▶sub _table_add {
Subroutine _table_add: called CC=19 SCAR=29.6
1330 20 my $self = shift;
1331 20 my $epr = shift;
1332 20 my $col = shift;
1333 20 my $row = shift;
1334 20 my $des = shift;
1335 20 my $end = shift;
1336  
1337 20 my @rows = @{$self->{'RowLabels'}};
1338 20 ▶ while (@rows && $rows[0] ne $row) { shift @rows }
Branch: 1 branch
BranchTrueFalseTotal
if (@rows and $rows[0] ne $row) 106 20 126
Condition66%2/3
@rows and $rows[0] ne $row
!ll&&!rl&&r
020106
MC/DC50%1/2
@rows and $rows[0] ne $row
@rows $rows[0] ne $row
Truth table66%2/3
A and B
A= @rowsB= $rows[0] ne $row
ABresult
0X0
100
111
1339 20 ▶ die unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 20 20
1340 0 ▶ if (!$end || $row eq $end) { splice(@rows,1) }
Branch: 1 branch
BranchTrueFalseTotal
if (not $end or $row eq $end) { } 0 20 20
Condition33%1/3
not $end or $row eq $end
l!l&&r!l&&!r
0020
MC/DC0%0/2
not $end or $row eq $end
not $end $row eq $end
Truth table33%1/3
not(A) or B
A= not $endB= $row eq $end
ABresult
1X1
011
000
1341 else {
1342 20 my @t = (shift @rows);
1343 20 ▶ while ($rows[0] ne $end) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rows[0] ne $end) 18 20 38
1344 18 ▶ die unless @rows;
Branch: 1 branch
BranchTrueFalseTotal
unless @rows 0 18 18
1345 18 push @t, ( shift @rows );
1346 }
1347 20 @rows = @t;
1348 }
1349  
1350 20 my $overlap = 0;
1351 {
1352 20 my @trows = @rows;
1353 20 ▶ while (@trows) {
Branch: 1 branch
BranchTrueFalseTotal
if (@trows) 50 20 70
1354 50 my $r = shift @trows;
1355 50 my $oldoverlap = $overlap;
1356 50 ▶ if ($overlap==0 && defined $epr->{$col, $r}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap == 0 and defined $$epr{join $;, $col, $r}) 4 46 50
Condition100%3/3
$overlap == 0 and defined $$epr{join $;, $col, $r}
!ll&&!rl&&r
18284
MC/DC100%2/2
$overlap == 0 and defined $$epr{join $;, $col, $r}
$overlap == 0 defined $$epr{join $;, $col, $r}
Truth table100%3/3
A and B
A= $overlap == 0B= defined $$epr{join $;, $col, $r}
ABresult
0X0
100
111
1357 #$epr->{$col, $r} .= " -CONFLICT- " . $des;
1358 4 $overlap = 2;
1359 }
1360 50 ▶ while ($overlap > 0 && defined($epr->{$col,$r,$overlap}))
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap > 0 and defined $$epr{join $;, $col, $r, $overlap}) 2 50 52
Condition100%3/3
$overlap > 0 and defined $$epr{join $;, $col, $r, $overlap}
!ll&&!rl&&r
28222
MC/DC100%2/2
$overlap > 0 and defined $$epr{join $;, $col, $r, $overlap}
$overlap > 0 defined $$epr{join $;, $col, $r, $overlap}
Truth table100%3/3
A and B
A= $overlap > 0B= defined $$epr{join $;, $col, $r, $overlap}
ABresult
0X0
100
111
1361 2 { ++ $overlap }
1362 50 ▶ if ($overlap > $oldoverlap) { push @trows, @rows }
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap > $oldoverlap) 4 46 50
1363 }
1364 }
1365 20 ▶ $self->{overlap}[$col] = 0 unless defined($self->{overlap}[$col]);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"overlap"}[$col] 10 10 20
1366 20 ▶ $self->{overlap}[$col] = $overlap if $overlap > $self->{overlap}[$col];
Branch: 1 branch
BranchTrueFalseTotal
if $overlap > $self->{"overlap"}[$col] 4 16 20
1367  
1368 20 $row = shift @rows;
1369 20 ▶ if ($overlap == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($overlap == 0) { } 16 4 20
1370 16 $epr->{$col, $row} = $des;
1371 16 foreach my $r (@rows)
1372 10 { $epr->{$col, $r} = 'continue' }
1373 } else {
1374 4 $epr->{$col, $row, $overlap} = $des;
1375 4 foreach my $r (@rows)
1376 8 { $epr->{$col, $r, $overlap } = 'continue';
1377 #$epr->{$col, $r} .= " -CONFLICT- continue";
1378 }
1379 }
1380 }
1381  
1382 312 ▶sub _table_get {
Subroutine _table_get: called CC=4 SCAR=13.9
1383 312 my $self = shift;
1384 312 my $epr = shift;
1385 312 my $col = shift;
1386 312 my $row = shift;
1387 312 ▶ my $overlap = shift; $overlap = 0 if !defined($overlap);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $overlap 236 76 312
1388 312 ▶ my $ret = $overlap > 0 ? $epr->{$col, $row, $overlap} : $epr->{$col, $row};
Branch: 1 branch
BranchTrueFalseTotal
$overlap > 0 ? : 76 236 312
1389 312 ▶ return defined($ret) ? $ret : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 116 196 312
1390 }
1391  
1392 =pod
1393  
1394 =cut
1395  
1396 0 ▶sub _getfile($) {
Subroutine _getfile: not called CC=3 SCAR=24.8
1397 0 my $f = shift;
1398 0 local *F;
1399 0 ▶ open(F, "<$f") or die "getfile:cannot open $f:$!";
Branch: 1 branch
BranchTrueFalseTotal
open F, "<$f" or die "getfile:cannot open ${f}:$!" 0 0 0
1400 0 my @r = <F>;
1401 0 close(F);
1402 0 ▶ return wantarray ? @r : join ('', @r);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1403 }
1404  
1405 2 1;
1406 __END__
↑ Summary bin/cal2html »