JSCalendar.pm

filter: Statementstmt 94.9% 1685 / 1775 Branchbran 82.6% 982 / 1188 Conditioncond 71.4% 538 / 753 MC/DCmcdc 47.6% 206 / 432 Subroutinesub 98.2% 113 / 115 Podpod 83.3% 10 / 12 totaltotal 82.6% 3534 / 4275 CC 962 SCAR 48.8
CC
962
Cov
86%
_vEventToEvent
385.9
_argsToVEvents
166.9
_expandRule
141.9
CRAP 132.1
« JSCalendar/TimeZones.pm ↑ Summary
1 #/usr/bin/perl -cw
2 19 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 19 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package Text::JSCalendar;
5  
6 19 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 19 ▶use Data::ICal;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 19 ▶use Data::ICal::Entry::Event;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 19 ▶use Data::ICal::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 19 ▶use Data::ICal::Entry::Alarm::Email;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 19 ▶use Data::ICal::Entry::Alarm::Display;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 19 ▶use DateTime::Format::ICal;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 19 ▶use DateTime::TimeZone;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 19 ▶use JSON::XS qw(encode_json);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 19 ▶use Text::JSCalendar::TimeZones;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 19 ▶use Text::VCardFast qw(vcard2hash);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 19 ▶use MIME::Base64 qw(encode_base64);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 19 ▶use MIME::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 19 ▶use Digest::SHA qw(sha1_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 19 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 19 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 19 ▶use Text::JSCalendar::TimeZones;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 # monkey patch like a bandit
26 19 ▶BEGIN {
Subroutine BEGIN: called CC=3 SCAR=11.0
27 19 my @alarm_properties = Data::ICal::Entry::Alarm::optional_unique_properties();
28 19 foreach my $want (qw(uid acknowledged)) {
29 38 ▶ push @alarm_properties, $want unless grep { $_ eq $want } @alarm_properties;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $want;} @alarm_properties 38 0 38
30 }
31 19 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 19 ▶ *Data::ICal::Entry::Alarm::optional_unique_properties = sub { @alarm_properties };
Subroutine __ANON__: called CC=1 SCAR=0.0
33 }
34  
35 19 our $UTC = DateTime::TimeZone::UTC->new();
36 19 our $FLOATING = DateTime::TimeZone::Floating->new();
37 19 our $LOCALE = DateTime::Locale->load('en_US');
38  
39 # MIME::Types->new is slow; made once, when an ATTACH first needs it
40 19 my $MimeTypes;
41  
42 # The vendor-specific property (jscalendarbis-22 1.8.1) that marks a
43 # master the reader made up; see "Synthetic masters" in the POD.
44 19 ▶use constant SYNTHETIC_MASTER => 'jscalendar.fastmail.com:syntheticMaster';
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 my (
47 19 %ValidDay,
48 %ValidFrequency,
49 %EventKeys,
50 %ColorNames,
51 %RecurrenceProperties,
52 %UTCLinks,
53 %MustBeTopLevel,
54 %OrganizerOnly,
55 );
56  
57 19 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
58 19 %ValidDay = map { $_ => 1 } qw(su mo tu we th fr sa);
59 19 %ValidFrequency = map { $_ => 1 } qw(yearly monthly weekly daily hourly minutely secondly);
60  
61 # Property name => [container, type, required, default], per object
62 # type (the key "" is the Event or Task itself). container is 0 for a
63 # single value, 1 for an array, 2 for an Id- or String-keyed map; type
64 # "object" recurses into the table of the same name and "patch" into
65 # a PatchObject. Defaults are jscalendarbis-22 (or RFC 8984 for the
66 # properties -22 reserved); only NormaliseEvent reads this table.
67 19 %EventKeys = (
68 '' => {
69 uid => [0, 'string', 1, undef],
70 relatedTo => [2, 'object', 0, undef],
71 keywords => [0, 'keywords', 0, undef],
72 categories => [0, 'keywords', 0, undef],
73 prodId => [0, 'string', 0, undef],
74 created => [0, 'utcdate', 0, undef],
75 updated => [0, 'utcdate', 1, undef],
76 sequence => [0, 'number', 0, 0],
77 method => [0, 'string', 0, undef],
78 title => [0, 'string', 0, ''],
79 description => [0, 'string', 0, ''],
80 descriptionContentType => [0, 'string', 0, "text/plain"], # jscalendarbis-22 3.2.3
81 links => [2, 'object', 0, undef],
82 locale => [0, 'string', 0, undef],
83 locations => [2, 'object', 0, undef],
84 virtualLocations => [2, 'object', 0, undef],
85 color => [0, 'string', 0, undef],
86 showWithoutTime => [0, 'bool', 0, $JSON::false],
87 start => [0, 'localdate', 1, undef],
88 timeZone => [0, 'timezone', 0, undef],
89 duration => [0, 'duration', 0, "PT0S"], # jscalendarbis-22 4.1.2
90 recurrenceRule => [0, 'object', 0, undef],
91 recurrenceOverrides => [2, 'patch', 0, undef],
92 recurrenceId => [0, 'localdate', 0, undef],
93 recurrenceIdTimeZone => [0, 'timezone', 0, undef],
94 status => [0, 'string', 0, "confirmed"], # jscalendarbis-22 4.1.4
95 freeBusyStatus => [0, 'string', 0, 'busy'],
96 privacy => [0, 'string', 0, 'public'],
97 priority => [0, 'number', 0, 0],
98 organizerCalendarAddress => [0, 'string', 0, undef],
99 sentBy => [0, 'string', 0, undef],
100 endTimeZone => [0, 'timezone', 0, undef],
101 participants => [2, 'object', 0, undef],
102 alerts => [2, 'object', 0, undef],
103 version => [0, 'string', 0, undef],
104 # Task-specific properties
105 due => [0, 'localdate', 0, undef],
106 estimatedDuration => [0, 'duration', 0, undef],
107 percentComplete => [0, 'number', 0, undef],
108 progress => [0, 'string', 0, undef],
109 },
110 links => {
111 href => [0, 'string', 1, undef],
112 contentType => [0, 'string', 0, undef],
113 size => [0, 'number', 0, undef],
114 rel => [0, 'string', 0, 'enclosure'], # jscalendarbis-22 1.5.11
115 title => [0, 'string', 0, undef],
116 display => [2, 'bool', 0, undef],
117 },
118 locations => {
119 name => [0, 'string', 0, undef],
120 coordinates => [0, 'string', 0, undef],
121 locationTypes => [0, 'keywords', 0, undef],
122 links => [2, 'object', 0, undef],
123 },
124 virtualLocations => {
125 name => [0, 'string', 0, ''],
126 uri => [0, 'string', 1, undef],
127 features => [0, 'keywords', 0, undef],
128 },
129 recurrenceRule => {
130 frequency => [0, 'string', 1, undef],
131 interval => [0, 'number', 0, 1], # jscalendarbis-22 3.3.3
132 rscale => [0, 'string', 0, 'gregorian'],
133 skip => [0, 'string', 0, 'omit'],
134 firstDayOfWeek => [0, 'string', 0, 'mo'],
135 byDay => [1, 'object', 0, undef],
136 byMonthDay => [1, 'number', 0, undef],
137 byMonth => [1, 'string', 0, undef],
138 byYearDay => [1, 'number', 0, undef],
139 byWeekNo => [1, 'number', 0, undef],
140 byHour => [1, 'number', 0, undef],
141 byMinute => [1, 'number', 0, undef],
142 bySecond => [1, 'number', 0, undef],
143 bySetPosition => [1, 'number', 0, undef],
144 count => [0, 'number', 0, undef],
145 until => [0, 'localdate', 0, undef],
146 },
147 relatedTo => {
148 relation => [2, 'bool', 0, undef],
149 },
150 byDay => {
151 day => [0, 'string', 1, undef],
152 nthOfPeriod => [0, 'number', 0, undef],
153 },
154 participants => {
155 name => [0, 'string', 1, undef],
156 email => [0, 'string', 1, undef],
157 calendarAddress => [0, 'string', 0, undef],
158 kind => [0, 'string', 0, undef], # no default (jscalendarbis-22 3.4.6)
159 roles => [2, 'bool', 1, undef],
160 locationId => [0, 'string', 0, undef],
161 participationStatus => [0, 'string', 0, 'needs-action'],
162 expectReply => [0, 'bool', 0, $JSON::false],
163 scheduleAgent => [0, 'string', 0, "server"], # RFC 8984 4.4.6
164 scheduleSequence => [0, 'number', 0, 0],
165 scheduleUpdated => [0, 'utcdate', 0, undef],
166 scheduleStatus => [1, 'string', 0, undef],
167 participationComment => [0, 'string', 0, undef],
168 invitedBy => [0, 'string', 0, undef],
169 memberOf => [2, 'bool', 0, undef],
170 sentBy => [0, 'string', 0, undef],
171 progress => [0, 'string', 0, undef],
172 progressUpdated => [0, 'utcdate', 0, undef],
173 delegatedFrom => [0, 'keywords', 0, undef],
174 delegatedTo => [0, 'keywords', 0, undef],
175 description => [0, 'string', 0, undef],
176 descriptionContentType => [0, 'string', 0, undef],
177 links => [2, 'object', 0, undef],
178 },
179 alerts => {
180 trigger => [0, 'object', 1, undef],
181 acknowledged => [0, 'string', 0, undef],
182 action => [0, 'string', 0, 'display'],
183 },
184 # the Alert trigger: an OffsetTrigger when @type is unset or
185 # "OffsetTrigger" (its defaultType, jscalendarbis-22 3.5.1); any other
186 # @type is kept as it is
187 trigger => {
188 offset => [0, 'string', 1, undef],
189 relativeTo => [0, 'string', 0, 'start'],
190 },
191 );
192  
193 19 %RecurrenceProperties = (
194 bymonthday => {
195 name => 'byMonthDay',
196 max => 31,
197 signed => 1,
198 },
199 byyearday => {
200 name => 'byYearDay',
201 max => 366,
202 signed => 1,
203 },
204 byweekno => {
205 name => 'byWeekNo',
206 max => 53,
207 signed => 1,
208 },
209 byhour => {
210 name => 'byHour',
211 max => 23,
212 },
213 byminute => {
214 name => 'byMinute',
215 max => 59,
216 },
217 bysecond => {
218 name => 'bySecond',
219 max => 60,
220 },
221 bysetpos => {
222 name => 'bySetPosition',
223 max => 366,
224 signed => 1,
225 },
226 );
227  
228 19 %MustBeTopLevel = map { $_ => 1 } SYNTHETIC_MASTER, qw{
229 @type
230 uid
231 prodId
232 showWithoutTime
233 recurrenceRule
234 recurrenceOverrides
235 organizerCalendarAddress
236 method
237 privacy
238 sentBy
239 recurrenceId
240 recurrenceIdTimeZone
241 };
242  
243 # Participant properties that convert to ORGANIZER parameters
244 19 %OrganizerOnly = map { $_ => 1 } qw{
245 @type
246 calendarAddress
247 email
248 name
249 roles
250 sentBy
251 };
252  
253 # Color names defined in CSS Color Module Level 3
254 # http://www.w3.org/TR/css3-color/
255  
256 %ColorNames
257 19 = map { $_ => 1 }
258 qw{
259 aliceblue
260 antiquewhite
261 aqua
262 aquamarine
263 azure
264 beige
265 bisque
266 black
267 blanchedalmond
268 blue
269 blueviolet
270 brown
271 burlywood
272 cadetblue
273 chartreuse
274 chocolate
275 coral
276 cornflowerblue
277 cornsilk
278 crimson
279 cyan
280 darkblue
281 darkcyan
282 darkgoldenrod
283 darkgray
284 darkgreen
285 darkgrey
286 darkkhaki
287 darkmagenta
288 darkolivegreen
289 darkorange
290 darkorchid
291 darkred
292 darksalmon
293 darkseagreen
294 darkslateblue
295 darkslategray
296 darkslategrey
297 darkturquoise
298 darkviolet
299 deeppink
300 deepskyblue
301 dimgray
302 dimgrey
303 dodgerblue
304 firebrick
305 floralwhite
306 forestgreen
307 fuchsia
308 gainsboro
309 ghostwhite
310 gold
311 goldenrod
312 gray
313 green
314 greenyellow
315 grey
316 honeydew
317 hotpink
318 indianred
319 indigo
320 ivory
321 khaki
322 lavender
323 lavenderblush
324 lawngreen
325 lemonchiffon
326 lightblue
327 lightcoral
328 lightcyan
329 lightgoldenrodyellow
330 lightgray
331 lightgreen
332 lightgrey
333 lightpink
334 lightsalmon
335 lightseagreen
336 lightskyblue
337 lightslategray
338 lightslategrey
339 lightsteelblue
340 lightyellow
341 lime
342 limegreen
343 linen
344 magenta
345 maroon
346 mediumaquamarine
347 mediumblue
348 mediumorchid
349 mediumpurple
350 mediumseagreen
351 mediumslateblue
352 mediumspringgreen
353 mediumturquoise
354 mediumvioletred
355 midnightblue
356 mintcream
357 mistyrose
358 moccasin
359 navajowhite
360 navy
361 oldlace
362 olive
363 olivedrab
364 orange
365 orangered
366 orchid
367 palegoldenrod
368 palegreen
369 paleturquoise
370 palevioletred
371 papayawhip
372 peachpuff
373 peru
374 pink
375 plum
376 powderblue
377 purple
378 red
379 rosybrown
380 royalblue
381 saddlebrown
382 salmon
383 sandybrown
384 seagreen
385 seashell
386 sienna
387 silver
388 skyblue
389 slateblue
390 slategray
391 slategrey
392 snow
393 springgreen
394 steelblue
395 tan
396 teal
397 thistle
398 tomato
399 turquoise
400 violet
401 wheat
402 white
403 whitesmoke
404 yellow
405 yellowgreen
406 };
407  
408 19 %UTCLinks = (
409 'Etc/GMT-0' => 1,
410 'Etc/GMT+0' => 1,
411 'Etc/GMT0' => 1,
412 'Etc/GMT' => 1,
413 'Etc/Greenwich' => 1,
414 'Etc/UCT' => 1,
415 'Etc/Universal' => 1,
416 'Etc/UTC' => 1,
417 'Etc/Zulu' => 1,
418 'GMT' => 1,
419 'UCT' => 1,
420 'UTC' => 1,
421 );
422 }
423  
424  
425 =head1 NAME
426  
427 Text::JSCalendar - convert between iCalendar and JSCalendar
428  
429 =head1 VERSION
430  
431 Version 0.11
432  
433 =cut
434  
435 19 our $VERSION = '0.11';
436  
437 =head1 SYNOPSIS
438  
439 This module implements a perl mapping between iCalendar:
440  
441 https://tools.ietf.org/html/rfc5545
442  
443 and JSCalendar:
444  
445 https://datatracker.ietf.org/doc/draft-ietf-calext-jscalendar/
446  
447 =head1 SUBROUTINES/METHODS
448  
449 =cut
450  
451 17 ▶sub new {
Subroutine new: called CC=2 SCAR=8.1
Pod undocumented
452 17 my $class = shift;
453 17 ▶ return bless {@_}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
0170
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
454 }
455  
456 =head2 Synthetic masters
457  
458 An iCalendar object may hold only some instances of a recurring event
459 (RECURRENCE-ID components without their master, as a CalDAV server
460 gives an attendee invited to one occurrence: jscalendar-icalendar-29
461 calls them stand-alone recurrence instances). C<vcalendarToEvents>
462 returns a single object per UID, so it makes up a master for them: its
463 C<start>, C<timeZone>, C<updated> and the properties an override may not
464 change come from the first instance, and every instance is one of its
465 C<recurrenceOverrides> (even one that patches nothing).
466  
467 Such a master is marked with the vendor-specific property
468  
469 "jscalendar.fastmail.com:syntheticMaster": true
470  
471 (jscalendarbis-22 1.8.1, so it cannot collide with a JSCalendar
472 property, and JSCalendar implementations must preserve it). The name is
473 the constant C<Text::JSCalendar::SYNTHETIC_MASTER>. It is in the object
474 rather than beside it so that it survives being stored and read back
475 before the object is written again.
476  
477 C<eventsToVCalendar> writes only the instances of a marked master, each
478 as a RECURRENCE-ID component (an excluded one is not written), and never
479 a component for the master itself. Every other object is written whole.
480 To turn a synthetic master into a real one, delete the property.
481 C<occurrences> of a synthetic master are its override keys, and
482 C<instance> gives the instance with the property removed.
483  
484 =head2 Text::JSCalendar->isSyntheticMaster($Event)
485  
486 True if C<$Event> is a master made up by the reader (see above). May
487 also be called on an object or as a function.
488  
489 =cut
490  
491 367 ▶sub isSyntheticMaster {
Subroutine isSyntheticMaster: called CC=3 SCAR=11.1
Pod documented
492 367 my $Event = pop;
493 367 ▶ return 0 unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 367 367
494 367 ▶ return $Event->{SYNTHETIC_MASTER()} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$Event->{'jscalendar.fastmail.com:syntheticMaster'} ? : 23 344 367
495 }
496  
497 =head2 $self->errors()
498  
499 What the last call to C<vcalendarToEvents> or C<eventsToVCalendar> (or
500 C<_argsToVCalendar>) had to drop. Neither dies because one component
501 is bad: an iCalendar VEVENT or VTODO, VALARM or RRULE that cannot be
502 converted is left out of the result, and so is a JSCalendar object or
503 alert that cannot be written. The rest of the calendar converts as
504 usual.
505  
506 Returns a list of hashes, empty when nothing was dropped:
507  
508 {
509 uid => 'abc@example.com', # the object's UID (undef if it had none)
510 component => 'RRULE', # what was dropped: VEVENT, VTODO,
511 # VALARM, RRULE (reading), or
512 # Event, Task, Alert (writing)
513 id => 'alarm-1', # the alarm or alert id, if known
514 message => 'Invalid recurrence FREQ (fortnightly)',
515 }
516  
517 The list is reset at the start of each of those calls, and so is
518 C<warnings>.
519  
520 =cut
521  
522 475 ▶sub errors {
Subroutine errors: called CC=2 SCAR=7.1
Pod documented
523 475 my $Self = shift;
524 475 ▶ return @{$Self->{_errors} || []};
Condition50%1/2
$Self->{'_errors'} || []
l!l
4750
MC/DC0%0/1
$Self->{'_errors'} || []
$Self->{'_errors'}
Truth table50%1/2
A
A= $Self->{'_errors'}
Aresult
11
00
525 }
526  
527 =head2 $self->warnings()
528  
529 What the last call to C<vcalendarToEvents> or C<eventsToVCalendar> (or
530 C<_argsToVCalendar>) found odd but converted anyway: an iCalendar
531 component with both DTEND and DURATION, a second component of one UID
532 without RECURRENCE-ID, a property Data::ICal says is missing. The same
533 shape as C<errors>, and reset with it. The module never writes these to
534 STDERR.
535  
536 =cut
537  
538 2 ▶sub warnings {
Subroutine warnings: called CC=2 SCAR=7.1
Pod documented
539 2 my $Self = shift;
540 2 ▶ return @{$Self->{_warnings} || []};
Condition50%1/2
$Self->{'_warnings'} || []
l!l
20
MC/DC0%0/1
$Self->{'_warnings'} || []
$Self->{'_warnings'}
Truth table50%1/2
A
A= $Self->{'_warnings'}
Aresult
11
00
541 }
542  
543 5 ▶sub _warning {
Subroutine _warning: called CC=1 SCAR=0.0
544 5 my ($Self, $uid, $component, $msg) = @_;
545 5 push @{$Self->{_warnings}}, {
546 uid => $uid,
547 component => $component,
548 message => $msg,
549 };
550 }
551  
552 630 ▶sub _resetDiagnostics {
Subroutine _resetDiagnostics: called CC=1 SCAR=0.0
553 630 my $Self = shift;
554 630 $Self->{_errors} = [];
555 630 $Self->{_warnings} = [];
556 }
557  
558 # Run $code with Data::ICal's carps caught: it warns about every property
559 # it does not know (COLOR, CONFERENCE, ...: most of what this module
560 # writes) and about missing mandatory ones. The first are expected; the
561 # second become warnings(). Any other warning goes on to the caller's
562 # handler. (This used to be a $SIG{__WARN__} replaced for the whole
563 # process when the module was loaded.)
564 469 ▶sub _withICalWarnings {
Subroutine _withICalWarnings: called CC=1 SCAR=0.4
565 469 my ($Self, $code) = @_;
566 469 my $outer = $SIG{__WARN__};
567 42 ▶ local $SIG{__WARN__} = sub {
Subroutine __ANON__: called CC=4 SCAR=16.6
568 42 my $msg = $_[0];
569 42 ▶ return if $msg =~ /^Unknown property for Data::ICal::Entry::/;
Branch: 1 branch
BranchTrueFalseTotal
if $msg =~ /^Unknown property for Data::ICal::Entry::/ 39 3 42
570 3 ▶ if ($msg =~ /^Mandatory property for (Data::ICal::\S+) missing: (\S+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($msg =~ /^Mandatory property for (Data::ICal::\S+) missing: (\S+)/) 3 0 3
571 3 $Self->_warning(undef, $1, "missing mandatory property $2");
572 3 return;
573 }
574 0 ▶ if (ref $outer eq 'CODE') { $outer->(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $outer eq 'CODE') { } 0 0 0
575 0 else { warn @_ }
576 469 };
577 469 return $code->();
578 }
579  
580 # Report a dropped component. $msg is a die message: only its first
581 # line is kept, without Carp's location.
582 19 ▶sub _error {
Subroutine _error: called CC=4 SCAR=14.0
583 19 my ($Self, $uid, $component, $msg, $id) = @_;
584 19 ▶ $msg = defined $msg ? "$msg" : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $msg ? : 19 0 19
585 19 $msg =~ s/\n.*//s;
586 19 $msg =~ s/ at \S+ line \d+\.?$//;
587 19 ▶ $msg = 'unknown error' unless length $msg;
Branch: 1 branch
BranchTrueFalseTotal
unless length $msg 0 19 19
588 19 ▶ push @{$Self->{_errors}}, {
Branch: 1 branch
BranchTrueFalseTotal
defined $id ? : 2 17 19
589 uid => $uid,
590 component => $component,
591 defined $id ? (id => $id) : (),
592 message => $msg,
593 };
594 }
595  
596 =head2 $self->tz($name)
597  
598 Returns a DateTime::TimeZone object for the given name, but caches
599 the result for speed.
600  
601 =cut
602  
603 2326 ▶sub tz {
Subroutine tz: called CC=4 SCAR=13.9
Pod documented
604 2326 my $Self = shift;
605 2326 my $tzName = shift;
606 2326 ▶ return $FLOATING unless defined $tzName;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tzName 13 2313 2326
607 2313 ▶ return $UTC if $UTCLinks{$tzName};
Branch: 1 branch
BranchTrueFalseTotal
if $UTCLinks{$tzName} 1543 770 2313
608 770 ▶ unless (exists $Self->{_tz}{$tzName}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $Self->{"_tz"}{$tzName}) 15 755 770
609 15 $Self->{_tz}{$tzName} = DateTime::TimeZone->new(name => $tzName);
610 }
611 770 return $Self->{_tz}{$tzName};
612 }
613  
614 0 ▶sub color {
Subroutine color: not called CC=1 SCAR=6.9
Pod undocumented
615 0 my $Self = shift;
616 0 my $color = shift;
617 0 return _fixColor($color);
618 }
619  
620 23 ▶sub _fixColor {
Subroutine _fixColor: called CC=7 SCAR=19.6
621 23 ▶ my $color = lc(shift || '');
Condition50%1/2
shift() || ''
l!l
230
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
622  
623 23 ▶ return $color if $ColorNames{$color};
Branch: 1 branch
BranchTrueFalseTotal
if $ColorNames{$color} 13 10 23
624 10 ▶ confess("unparseable color: $color") unless $color =~ m/^\s*(\#[a-f0-9]{3,8})\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $color =~ /^\s*(\#[a-f0-9]{3,8})\s*$/ 2 8 10
625 8 $color = $1;
626 8 ▶ return uc($color) if length($color) == 7;
Branch: 1 branch
BranchTrueFalseTotal
if length $color == 7 6 2 8
627  
628 # Optional digit is for transparency (RGBA)
629 2 ▶ if ( $color =~ m/^#(.)(.)(.).?$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($color =~ /^#(.)(.)(.).?$/) 1 1 2
630 1 return uc "#$1$1$2$2$3$3";
631 }
632  
633 # Last two digits are for transparency (RGBA)
634 1 ▶ if ( length($color) == 9 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $color == 9) 0 1 1
635 0 return uc(substr($color,0,7));
636 }
637  
638 1 confess("invalid color: $color"); # e.g. five or seven hex digits
639 }
640  
641 43 ▶sub _BYDAY2byDay {
Subroutine _BYDAY2byDay: called CC=7 SCAR=22.0
642 43 my ($BYDAY) = @_;
643  
644 43 my ($Count, $Day) = $BYDAY =~ /^([-+]?\d+)?(\w\w)$/;
645  
646 43 ▶ unless ($Day) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Day) 0 43 43
647 0 confess 'Recurrence BYDAY-weekday not specified';
648 }
649  
650 43 ▶ unless ($ValidDay{lc $Day}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{lc $Day}) 0 43 43
651 0 confess 'Invalid recurrence BYDAY-weekday';
652 }
653  
654 43 ▶ if ($Count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Count) 26 17 43
655 26 ▶ unless (($Count >= -53) and ($Count <= 53)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Count >= -53 and $Count <= 53) 0 26 26
Condition33%1/3
$Count >= -53 and $Count <= 53
!ll&&!rl&&r
0026
MC/DC0%0/2
$Count >= -53 and $Count <= 53
$Count >= -53 $Count <= 53
Truth table33%1/3
A and B
A= $Count >= -53B= $Count <= 53
ABresult
0X0
100
111
656 0 confess 'Recurrence BYDAY-ordwk is out of range';
657 }
658 }
659  
660 return {
661 43 ▶ '@type' => 'NDay',
Branch: 1 branch
BranchTrueFalseTotal
$Count ? : 26 17 43
662 day => lc $Day,
663 $Count ? (nthOfPeriod => int($Count)) : (),
664 };
665 }
666  
667 30 ▶sub _byDay2BYDAY {
Subroutine _byDay2BYDAY: called CC=6 SCAR=20.5
668 30 my ($byDay) = @_;
669  
670 30 ▶ unless (defined $byDay) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $byDay) 0 30 30
671 0 confess 'Invalid recurrence byDay';
672 }
673  
674 30 ▶ unless (ref $byDay eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $byDay eq "HASH") 0 30 30
675 0 confess 'Recurrence byDay is not an object';
676 }
677  
678 30 my $Day = $byDay->{day};
679 30 ▶ unless ($Day and $ValidDay{lc $Day}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Day and $ValidDay{lc $Day}) 0 30 30
Condition33%1/3
$Day and $ValidDay{lc $Day}
!ll&&!rl&&r
0030
MC/DC0%0/2
$Day and $ValidDay{lc $Day}
$Day $ValidDay{lc $Day}
Truth table33%1/3
A and B
A= $DayB= $ValidDay{lc $Day}
ABresult
0X0
100
111
680 0 confess 'Recurrence byDay is not a known day';
681 }
682  
683 30 my $Prefix = '';
684 30 ▶ $Prefix = int($byDay->{nthOfPeriod}) if $byDay->{nthOfPeriod};
Branch: 1 branch
BranchTrueFalseTotal
if $byDay->{"nthOfPeriod"} 18 12 30
685  
686 30 return $Prefix . uc($Day);
687 }
688  
689 1411 ▶sub _makeDateObj {
Subroutine _makeDateObj: called CC=4 SCAR=13.9
690 1411 my $Self = shift;
691 1411 my $DateStr = shift;
692 1411 my $TZStr = shift;
693 1411 my $TargetTz = shift;
694  
695 1411 my ($Date, $HasTime) = _vDate($DateStr);
696  
697 # if it's all day, return it immediately
698 1410 ▶ return ($Date, 1) unless $HasTime;
Branch: 1 branch
BranchTrueFalseTotal
unless $HasTime 58 1352 1410
699  
700 # Do the timezone manipulation as required
701 1352 ▶ $Date->set_time_zone($Self->tz($TZStr)) if $TZStr;
Branch: 1 branch
BranchTrueFalseTotal
if $TZStr 1340 12 1352
702 1352 ▶ $Date->set_time_zone($Self->tz($TargetTz)) if $TargetTz;
Branch: 1 branch
BranchTrueFalseTotal
if $TargetTz 625 727 1352
703  
704 1352 return ($Date, 0);
705 }
706  
707 1346 ▶sub _getDateObj {
Subroutine _getDateObj: called CC=2 SCAR=6.9
708 1346 my $Self = shift;
709 1346 my $Calendar = shift;
710 1346 my $VItem = shift;
711 1346 my $TargetTz = shift;
712  
713 1346 my $TimeZone = $Self->_getTimeZone($Calendar, $VItem);
714 1346 my ($Date, $IsAllDay) = $Self->_makeDateObj($VItem->{value}, $TimeZone, $TargetTz);
715  
716 1345 ▶ return (wantarray ? ($Date, $TimeZone, $IsAllDay) : $Date);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 720 625 1345
717 }
718  
719 29 ▶sub _getDateObjMulti {
Subroutine _getDateObjMulti: called CC=4 SCAR=13.9
720 29 my $Self = shift;
721 29 my $Calendar = shift;
722 29 my $VItem = shift;
723 29 my $TargetTz = shift;
724  
725 29 my @Dates;
726  
727 29 my $TimeZone = $Self->_getTimeZone($Calendar, $VItem);
728 29 foreach my $Value (split /,/, $VItem->{value}) {
729 # XXX - handle $V2 sanely
730 30 ▶ if (lc($VItem->{params}{value}[0] || '') eq 'period') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($VItem->{"params"}{"value"}[0] || "") eq "period") 0 30 30
Condition100%2/2
$VItem->{'params'}{'value'}[0] || ''
l!l
723
MC/DC100%1/1
$VItem->{'params'}{'value'}[0] || ''
$VItem->{'params'}{'value'}[0]
Truth table100%2/2
A
A= $VItem->{'params'}{'value'}[0]
Aresult
11
00
731 0 ($Value, my $V2) = split /\//, $Value;
732 }
733 30 my ($Date, $IsAllDay) = $Self->_makeDateObj($Value, $TimeZone, $TargetTz);
734 30 push @Dates, $Date;
735 }
736  
737 29 return @Dates;
738 }
739  
740 # Exclude DTSTAMP from auto uid generation
741 10 ▶sub _hexkey {
Subroutine _hexkey: called CC=3 SCAR=11.1
742 10 my $VEvent = shift;
743 10 ▶ my $extra = shift || '';
Condition50%1/2
shift() || ''
l!l
100
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
744 10 my $updated = delete $VEvent->{properties}->{updated};
745 10 my $d = Data::Dumper->new([$VEvent]);
746 10 $d->Indent(0);
747 10 $d->Sortkeys(1);
748 10 my $Key = sha1_hex($d->Dump() . $extra);
749 10 ▶ $VEvent->{properties}->{updated} = $updated if defined $updated;
Branch: 1 branch
BranchTrueFalseTotal
if defined $updated 0 10 10
750 10 return $Key;
751 }
752  
753 # An iCalendar INTEGER as a number, or undef if it is not one.
754 868 ▶sub _intValue {
Subroutine _intValue: called CC=3 SCAR=11.0
755 868 my $value = shift;
756 868 ▶ return undef unless defined $value and $value =~ /^\s*([-+]?\d+)\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and $value =~ /^\s*([-+]?\d+)\s*$/ 581 287 868
Condition100%3/3
defined $value and $value =~ /^\s*([-+]?\d+)\s*$/
!ll&&!rl&&r
5801287
MC/DC100%2/2
defined $value and $value =~ /^\s*([-+]?\d+)\s*$/
defined $value $value =~ /^\s*([-+]?\d+)\s*$/
Truth table100%3/3
A and B
A= defined $valueB= $value =~ /^\s*([-+]?\d+)\s*$/
ABresult
0X0
100
111
757 287 return int $1;
758 }
759  
760 439 ▶sub _saneuid {
Subroutine _saneuid: called CC=4 SCAR=14.6
761 439 my $uid = shift;
762 439 ▶ return unless $uid;
Branch: 1 branch
BranchTrueFalseTotal
unless $uid 0 439 439
763 439 ▶ return if $uid =~ m/\s/;
Branch: 1 branch
BranchTrueFalseTotal
if $uid =~ /\s/ 0 439 439
764 439 ▶ return if $uid =~ m/[\x7f-\xff]/;
Branch: 1 branch
BranchTrueFalseTotal
if $uid =~ /[\x7f-\xff]/ 0 439 439
765 # any other sanity checks?
766 439 return 1;
767 }
768  
769 # The key the reader gives a participant whose ATTENDEE/ORGANIZER carries
770 # no JSID: a hash of its address. The writer omits JSID when the key
771 # already matches this (jscalendar-icalendar 2.3.4, 2.3.29).
772 108 ▶sub _defaultParticipantKey {
Subroutine _defaultParticipantKey: called CC=3 SCAR=11.3
773 108 my $uri = shift;
774 108 ▶ return undef unless defined $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $uri 0 108 108
775 108 $uri =~ s/^mailto://i;
776 108 ▶ return undef if $uri eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq "" 0 108 108
777 108 return sha1_hex(lc $uri);
778 }
779  
780 # The JSID parameter (jscalendar-icalendar 4.2.1), or the older X-JMAP-ID,
781 # if it is a valid Id (jscalendarbis 1.4.1).
782 434 ▶sub _propJSID {
Subroutine _propJSID: called CC=5 SCAR=16.1
783 434 my $Prop = shift;
784 434 for my $param (qw(jsid x-jmap-id)) {
785 774 ▶ my $id = $Prop->{params}{$param} && $Prop->{params}{$param}[0];
Condition66%2/3
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
!ll&&!rl&&r
6680106
MC/DC50%1/2
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
$Prop->{'params'}{$param} $Prop->{'params'}{$param}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{$param}B= $Prop->{'params'}{$param}[0]
ABresult
0X0
100
111
786 774 ▶ return $id if defined $id and $id =~ m/\A[A-Za-z0-9_-]{1,255}\z/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/ 104 670 774
Condition100%3/3
defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
!ll&&!rl&&r
6682104
MC/DC100%2/2
defined $id and $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
defined $id $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
Truth table100%3/3
A and B
A= defined $idB= $id =~ /\A[A-Za-z0-9_-]{1,255}\z/
ABresult
0X0
100
111
787 }
788 330 return undef;
789 }
790  
791 # (title => ...) from the first of the named parameters that is set.
792 20 ▶sub _linkTitle {
Subroutine _linkTitle: called CC=5 SCAR=16.3
793 20 my ($Prop, @params) = @_;
794 20 for my $param (@params) {
795 20 ▶ my $v = $Prop->{params}{$param} && $Prop->{params}{$param}[0];
Condition66%2/3
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
!ll&&!rl&&r
8012
MC/DC50%1/2
$Prop->{'params'}{$param} && $Prop->{'params'}{$param}[0]
$Prop->{'params'}{$param} $Prop->{'params'}{$param}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{$param}B= $Prop->{'params'}{$param}[0]
ABresult
0X0
100
111
796 20 ▶ return (title => $v) if defined $v && length $v;
Branch: 1 branch
BranchTrueFalseTotal
if defined $v and length $v 12 8 20
Condition66%2/3
defined $v and length $v
!ll&&!rl&&r
8012
MC/DC50%1/2
defined $v and length $v
defined $v length $v
Truth table66%2/3
A and B
A= defined $vB= length $v
ABresult
0X0
100
111
797 }
798 8 return ();
799 }
800  
801 # The SENT-BY parameter of an ATTENDEE or ORGANIZER as an email address
802 # (the "mailto:" dropped), or undef.
803 4 ▶sub _mailto {
Subroutine _mailto: called CC=2 SCAR=7.2
804 4 my $addr = shift;
805 4 ▶ return $addr =~ /^[A-Za-z][A-Za-z0-9+.-]*:/ ? $addr : "mailto:$addr";
Branch: 1 branch
BranchTrueFalseTotal
$addr =~ /^[A-Za-z][A-Za-z0-9+.-]*:/ ? : 0 4 4
806 }
807  
808 262 ▶sub _sentByAddress {
Subroutine _sentByAddress: called CC=4 SCAR=14.0
809 262 my $Prop = shift;
810 262 ▶ my $v = $Prop->{params}{'sent-by'} && $Prop->{params}{'sent-by'}[0];
Condition66%2/3
$Prop->{'params'}{'sent-by'} && $Prop->{'params'}{'sent-by'}[0]
!ll&&!rl&&r
25606
MC/DC50%1/2
$Prop->{'params'}{'sent-by'} && $Prop->{'params'}{'sent-by'}[0]
$Prop->{'params'}{'sent-by'} $Prop->{'params'}{'sent-by'}[0]
Truth table66%2/3
A && B
A= $Prop->{'params'}{'sent-by'}B= $Prop->{'params'}{'sent-by'}[0]
ABresult
0X0
100
111
811 262 ▶ return undef unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 256 6 262
812 6 $v =~ s/^mailto://i;
813 6 ▶ return length $v ? $v : undef;
Branch: 1 branch
BranchTrueFalseTotal
length $v ? : 6 0 6
814 }
815  
816 # DELEGATED-FROM and DELEGATED-TO are lists of quoted cal-addresses
817 # (RFC 5545 3.2.4, 3.2.5), which the parser hands back joined with commas.
818 # Split them again, but only before something that starts a URI, so a
819 # comma inside an address survives.
820 13 ▶sub _splitCalAddresses {
Subroutine _splitCalAddresses: called CC=1 SCAR=0.0
821 13 return grep { length } map { split /,(?=[A-Za-z][A-Za-z0-9+.-]*:)/ } grep { defined } @_;
822 }
823  
824 195 ▶sub _makeParticipant {
Subroutine _makeParticipant: called CC=33 SCAR=35.9
825 195 my ($Self, $Calendar, $Participants, $VAttendee, $role, $AddrKeys) = @_;
826  
827 195 my $email = $VAttendee->{value};
828 195 ▶ return unless $email;
Branch: 1 branch
BranchTrueFalseTotal
unless $email 0 195 195
829 195 $email =~ s/^mailto://i;
830 195 ▶ return if $email eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $email eq "" 0 195 195
831 # jscalendar-icalendar 2.1.3: a JSID MUST be used as the key. ORGANIZER
832 # and ATTENDEE with the same address are one participant, so a JSID on
833 # either of them keys both.
834 my $id = _propJSID($VAttendee)
835 195 ▶ // ($AddrKeys && $AddrKeys->{lc $email})
Condition55%5/9
(_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}) // &sha1_hex(lc $email)
l!l&&r!l&&!r
401550
_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}
l!l&&r!l&&!r
400155
$AddrKeys and $$AddrKeys{lc $email}
!ll&&!rl&&r
01550
MC/DC0%0/4
(_propJSID($VAttendee) // $AddrKeys && $$AddrKeys{lc $email}) // &sha1_hex(lc $email)
_propJSID($VAttendee) $AddrKeys $$AddrKeys{lc $email} &sha1_hex(lc $email)
Truth table33%2/6
A // B and C // D
A= _propJSID($VAttendee)B= $AddrKeysC= $$AddrKeys{lc $email}D= &sha1_hex(lc $email)
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
836 // sha1_hex(lc $email);
837  
838 195 ▶ $Participants->{$id} ||= {};
Condition100%2/2
$Participants->{$id} ||= {}
l!l
35160
MC/DC100%1/1
$Participants->{$id} ||= {}
$Participants->{$id}
Truth table100%2/2
A
A= $Participants->{$id}
Aresult
11
00
839  
840 # XXX - if present on one but not the other, take the "best" version
841 195 ▶ $Participants->{$id}{name} = $VAttendee->{params}{"cn"}[0] // "";
Condition100%2/2
$VAttendee->{"params"}{"cn"}[0] // ""
l!l
13560
MC/DC100%1/1
$VAttendee->{"params"}{"cn"}[0] // ""
$VAttendee->{"params"}{"cn"}[0]
Truth table100%2/2
A
A= $VAttendee->{"params"}{"cn"}[0]
Aresult
11
00
842 195 ▶ $Participants->{$id}{email} = $VAttendee->{params}{"email"}[0] // $email;
Condition33%1/3
$VAttendee->{"params"}{"email"}[0] // $email
l!l&&r!l&&!r
01950
MC/DC0%0/2
$VAttendee->{"params"}{"email"}[0] // $email
$VAttendee->{"params"}{"email"}[0] $email
Truth table33%1/3
A // B
A= $VAttendee->{"params"}{"email"}[0]B= $email
ABresult
1X1
011
000
843 195 $Participants->{$id}{calendarAddress} = "mailto:$email";
844 $Participants->{$id}{kind} = lc $VAttendee->{params}{"cutype"}[0]
845 195 ▶ if $VAttendee->{params}{"cutype"};
Branch: 1 branch
BranchTrueFalseTotal
if $VAttendee->{"params"}{"cutype"} 10 185 195
846 195 $Participants->{$id}{roles}{$role} = $JSON::true;
847 # we don't support locationId yet
848 195 ▶ if ($VAttendee->{params}{"partstat"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"partstat"}) 79 116 195
849 79 ▶ $Participants->{$id}{participationStatus} = lc($VAttendee->{params}{"partstat"}[0] // "needs-action");
Condition50%1/2
$VAttendee->{"params"}{"partstat"}[0] // "needs-action"
l!l
790
MC/DC0%0/1
$VAttendee->{"params"}{"partstat"}[0] // "needs-action"
$VAttendee->{"params"}{"partstat"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"partstat"}[0]
Aresult
11
00
850 }
851 195 ▶ if ($VAttendee->{params}{"role"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"role"}) 47 148 195
852 47 ▶ my $ical_role = uc($VAttendee->{params}{"role"}[0] || '');
Condition50%1/2
$VAttendee->{'params'}{'role'}[0] || ''
l!l
470
MC/DC0%0/1
$VAttendee->{'params'}{'role'}[0] || ''
$VAttendee->{'params'}{'role'}[0]
Truth table50%1/2
A
A= $VAttendee->{'params'}{'role'}[0]
Aresult
11
00
853 47 ▶ if ($ical_role eq 'CHAIR') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ical_role eq "CHAIR") 4 43 47
854 4 $Participants->{$id}{roles}{chair} = $JSON::true;
855 }
856  
857 47 ▶ if ($ical_role eq 'OWNER') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ical_role eq "OWNER") 27 20 47
858 27 $Participants->{$id}{roles}{owner} = $JSON::true;
859 }
860  
861 47 ▶ $Participants->{$id}{roles}{optional} = $JSON::true
Branch: 1 branch
BranchTrueFalseTotal
if $ical_role eq "OPT-PARTICIPANT" 11 36 47
862 if $ical_role eq 'OPT-PARTICIPANT';
863  
864 47 ▶ $Participants->{$id}{roles}{informational} = $JSON::true
Branch: 1 branch
BranchTrueFalseTotal
if $ical_role eq "NON-PARTICIPANT" 1 46 47
865 if $ical_role eq 'NON-PARTICIPANT';
866 }
867 195 ▶ if ($VAttendee->{params}{"rsvp"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"rsvp"}) 12 183 195
868 12 ▶ $Participants->{$id}{expectReply} = lc($VAttendee->{params}{"rsvp"}[0] // "") eq 'yes' ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
lc($VAttendee->{'params'}{'rsvp'}[0] // '') eq 'yes' ? : 0 12 12
Condition50%1/2
$VAttendee->{"params"}{"rsvp"}[0] // ""
l!l
120
MC/DC0%0/1
$VAttendee->{"params"}{"rsvp"}[0] // ""
$VAttendee->{"params"}{"rsvp"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"rsvp"}[0]
Aresult
11
00
869 }
870 # SENT-BY is a cal-address; sentBy an email address (jscalendarbis-22
871 # 3.4.6, jscalendar-icalendar-29 2.3.4, 2.3.29)
872 195 ▶ if (my $SentBy = _sentByAddress($VAttendee)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $SentBy = _sentByAddress($VAttendee)) 4 191 195
873 4 $Participants->{$id}{sentBy} = $SentBy;
874 }
875 195 ▶ if (exists $VAttendee->{params}{"x-dtstamp"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VAttendee->{"params"}{"x-dtstamp"}) 17 178 195
876 17 my ($Date) = eval { $Self->_makeDateObj($VAttendee->{params}{"x-dtstamp"}[0], 'UTC', 'UTC') };
877 17 ▶ $Participants->{$id}{"scheduleUpdated"} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 17 0 17
878 }
879 # memberOf is not supported
880  
881 195 ▶ if (exists $VAttendee->{params}{"x-sequence"}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VAttendee->{"params"}{"x-sequence"}) 5 190 195
882 5 ▶ $Participants->{$id}{scheduleSequence} = $VAttendee->{params}{"x-sequence"}[0] // "";
Condition50%1/2
$VAttendee->{"params"}{"x-sequence"}[0] // ""
l!l
50
MC/DC0%0/1
$VAttendee->{"params"}{"x-sequence"}[0] // ""
$VAttendee->{"params"}{"x-sequence"}[0]
Truth table50%1/2
A
A= $VAttendee->{"params"}{"x-sequence"}[0]
Aresult
11
00
883 }
884  
885 195 ▶ if ($VAttendee->{params}{"schedule-agent"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"schedule-agent"}) 1 194 195
886 1 $Participants->{$id}{scheduleAgent} = lc($VAttendee->{params}{"schedule-agent"}[0]);
887 }
888  
889 195 ▶ if ($VAttendee->{params}{"delegated-from"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"delegated-from"}) 6 189 195
890 6 my %df;
891 6 for my $uri (_splitCalAddresses(@{$VAttendee->{params}{"delegated-from"}})) {
892 6 $df{$uri} = $JSON::true;
893 }
894 6 ▶ $Participants->{$id}{delegatedFrom} = \%df if %df;
Branch: 1 branch
BranchTrueFalseTotal
if %df 6 0 6
895 }
896  
897 195 ▶ if ($VAttendee->{params}{"delegated-to"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VAttendee->{"params"}{"delegated-to"}) 7 188 195
898 7 my %dt;
899 7 for my $uri (_splitCalAddresses(@{$VAttendee->{params}{"delegated-to"}})) {
900 9 $dt{$uri} = $JSON::true;
901 }
902 7 ▶ $Participants->{$id}{delegatedTo} = \%dt if %dt;
Branch: 1 branch
BranchTrueFalseTotal
if %dt 7 0 7
903 }
904 }
905  
906 516 ▶sub _make_duration {
Subroutine _make_duration: called CC=15 SCAR=27.3
907 516 my ($Self, $dtdur, $IsAllDay) = @_;
908  
909 516 my ($w, $d, $H, $M, $S) = (
910 $dtdur->weeks,
911 $dtdur->days,
912 $dtdur->hours,
913 $dtdur->minutes,
914 $dtdur->seconds,
915 );
916  
917 516 ▶ return 'PT0S' unless ($w || $d || $H || $M || $S);
Branch: 1 branch
BranchTrueFalseTotal
unless $w or $d or $H or $M or $S 209 307 516
Condition83%10/12
$w or $d or $H or $M or $S
l!l&&r!l&&!r
3070209
$w or $d or $H or $M
l!l&&r!l&&!r
23671209
$w or $d or $H
l!l&&r!l&&!r
23213280
$w or $d
l!l&&r!l&&!r
023493
MC/DC60%3/5
$w or $d or $H or $M or $S
$w $d $H $M $S
Truth table66%4/6
A or B or C or D or E
A= $wB= $dC= $HD= $ME= $S
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
918  
919 307 my @bits = ('P');
920 307 ▶ push @bits, ($w, 'W') if $w;
Branch: 1 branch
BranchTrueFalseTotal
if $w 0 307 307
921 307 ▶ push @bits, ($d, 'D') if $d;
Branch: 1 branch
BranchTrueFalseTotal
if $d 23 284 307
922 307 ▶ if (not $IsAllDay and ($H || $M || $S)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $H || $M || $S) 287 20 307
Condition88%8/9
not $IsAllDay and $H || $M || $S
!ll&&!rl&&r
191287
$H or $M or $S
l!l&&r!l&&!r
28701
$H or $M
l!l&&r!l&&!r
216711
MC/DC75%3/4
not $IsAllDay and $H || $M || $S
not $IsAllDay $H $M $S
Truth table80%4/5
not(A) and B or C or D
A= not $IsAllDayB= $HC= $MD= $S
ABCDresult
0XXX0
10000
11XX1
101X1
10011
923 287 push @bits, 'T';
924 287 ▶ push @bits, ($H, 'H') if $H;
Branch: 1 branch
BranchTrueFalseTotal
if $H 216 71 287
925 287 ▶ push @bits, ($M, 'M') if $M;
Branch: 1 branch
BranchTrueFalseTotal
if $M 77 210 287
926 287 ▶ push @bits, ($S, 'S') if $S;
Branch: 1 branch
BranchTrueFalseTotal
if $S 0 287 287
927 }
928  
929 307 return join ('', @bits);
930 }
931  
932 =head2 $NewEvent = Text::JSCalendar->NormaliseEvent($Event);
933  
934 Returns a copy of the event (the original is not changed) in a canonical
935 form for comparison: every property whose value is its default
936 (jscalendarbis-22, or RFC 8984 for the properties -22 reserved) is
937 removed, and so is an C<@type> that only repeats the type its position
938 already implies. Empty maps and arrays are removed. Everything else is
939 kept as it is: a property this module does not know, the contents of a
940 C<recurrenceOverrides> patch, and the C<@type> of the Event or Task and of
941 any trigger that is not an OffsetTrigger.
942  
943 Inside a recurrence override, a patch whose path names a known object
944 (C<participants/p1>, C<alerts/a1/trigger>, C<locations>) has that object
945 normalised the same way. A patched value is never removed for being the
946 default: in a patch it overrides the master, so C<"status": "confirmed">
947 says something that C<{}> does not.
948  
949 =cut
950  
951 # The @type an object may leave out because its position implies it
952 # (jscalendarbis-22 1.4.4). The Event or Task itself is absent here: there
953 # @type says which of the two it is. For a trigger this is the defaultType
954 # (3.5.1); an AbsoluteTrigger or unknown trigger keeps its @type.
955 19 my %ImpliedType = (
956 links => 'Link',
957 locations => 'Location',
958 virtualLocations => 'VirtualLocation',
959 recurrenceRule => 'RecurrenceRule',
960 byDay => 'NDay',
961 relatedTo => 'Relation',
962 participants => 'Participant',
963 alerts => 'Alert',
964 trigger => 'OffsetTrigger',
965 );
966  
967 213 ▶sub NormaliseEvent {
Subroutine NormaliseEvent: called CC=11 SCAR=24.0
Pod documented
968 213 my ($class, $Event, $Root) = @_;
969  
970 213 ▶ $Root ||= '';
Condition100%2/2
$Root ||= ""
l!l
13677
MC/DC100%1/1
$Root ||= ""
$Root
Truth table100%2/2
A
A= $Root
Aresult
11
00
971  
972 213 my %Copy = %$Event;
973  
974 213 ▶ if (exists $Copy{'@type'} and defined $ImpliedType{$Root}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})) 85 128 213
Condition100%6/6
exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
!ll&&!rl&&r
121785
exists $Copy{"\@type"} and defined $ImpliedType{$Root}
!ll&&!rl&&r
447792
MC/DC100%3/3
exists $Copy{"\@type"} and defined $ImpliedType{$Root} and _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
exists $Copy{"\@type"} defined $ImpliedType{$Root} _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
Truth table100%4/4
A and B and C
A= exists $Copy{"\@type"}B= defined $ImpliedType{$Root}C= _safeeq($Copy{"\@type"}, $ImpliedType{$Root})
ABCresult
0XX0
10X0
1100
1111
975 and _safeeq($Copy{'@type'}, $ImpliedType{$Root})) {
976 85 delete $Copy{'@type'};
977 }
978  
979 # An AbsoluteTrigger or an unknown trigger: nothing below applies to it
980 # (relativeTo's default is the OffsetTrigger's), so keep it as it is.
981 213 ▶ return \%Copy if $Root eq 'trigger' and exists $Copy{'@type'};
Branch: 1 branch
BranchTrueFalseTotal
if $Root eq "trigger" and exists $Copy{"\@type"} 7 206 213
Condition100%3/3
$Root eq "trigger" and exists $Copy{"\@type"}
!ll&&!rl&&r
191157
MC/DC100%2/2
$Root eq "trigger" and exists $Copy{"\@type"}
$Root eq "trigger" exists $Copy{"\@type"}
Truth table100%3/3
A and B
A= $Root eq "trigger"B= exists $Copy{"\@type"}
ABresult
0X0
100
111
982  
983 # Only the keys the table knows are normalised; any other key is kept.
984 # (This used to delete every key not in the table, which wiped the
985 # contents of override patches and triggers, and every @type.)
986 206 ▶ my $Spec = $EventKeys{$Root} || {};
Condition50%1/2
$EventKeys{$Root} || {}
l!l
2060
MC/DC0%0/1
$EventKeys{$Root} || {}
$EventKeys{$Root}
Truth table50%1/2
A
A= $EventKeys{$Root}
Aresult
11
00
987 206 foreach my $key (sort keys %$Spec) {
988 4084 ▶ next unless exists $Copy{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Copy{$key} 2987 1097 4084
989 1097 my ($keep, $value) = $class->_normaliseProp($Spec->{$key}, $key, $Copy{$key});
990 1097 ▶ if ($keep) { $Copy{$key} = $value }
Branch: 1 branch
BranchTrueFalseTotal
if ($keep) { } 990 107 1097
991 107 else { delete $Copy{$key} }
992 }
993  
994 206 return \%Copy;
995 }
996  
997 # Normalise one property value under its %EventKeys entry. Returns
998 # (1, $value) to keep it, or () to drop it as default or empty.
999 1097 ▶sub _normaliseProp {
Subroutine _normaliseProp: called CC=13 SCAR=26.2
1000 1097 my ($class, $entry, $key, $value) = @_;
1001 1097 my ($container, $type, undef, $default) = @$entry;
1002  
1003 1097 ▶ if ($container) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container) 99 998 1097
1004 # a map or array: null and empty are both "not set"
1005 99 ▶ return () unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 99 99
1006 99 my @new = $class->_normaliseContainer($entry, $key, $value);
1007 99 ▶ return @new ? (1, $new[0]) : ();
Branch: 1 branch
BranchTrueFalseTotal
@new ? : 99 0 99
1008 }
1009  
1010 998 ▶ if ($type eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 39 959 998
1011 39 ▶ return (1, $value) unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 39 39
1012 39 return (1, $class->NormaliseEvent($value, $key));
1013 }
1014 # not the shape we expect: keep it (a JSON boolean is a scalar here)
1015 959 ▶ return (1, $value) if ref($value) and not JSON::is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and not &JSON::is_bool($value) 10 949 959
Condition100%3/3
ref $value and not &JSON::is_bool($value)
!ll&&!rl&&r
9034610
MC/DC100%2/2
ref $value and not &JSON::is_bool($value)
ref $value not &JSON::is_bool($value)
Truth table100%3/3
A and not(B)
A= ref $valueB= not &JSON::is_bool($value)
ABresult
0X0
100
111
1016 949 ▶ if ($type eq 'bool') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "bool") 46 903 949
1017 46 ▶ return () if !!$default == !!$value;
Branch: 1 branch
BranchTrueFalseTotal
if !!$default == !!$value 44 2 46
1018 2 return (1, $value);
1019 }
1020 903 ▶ if ($type eq 'mailto') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "mailto") 0 903 903
1021 0 ▶ return (1, $value ? lc $value : $value);
Branch: 1 branch
BranchTrueFalseTotal
$value ? : 0 0 0
1022 }
1023 903 ▶ return () if _safeeq($default, $value);
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($default, $value) 63 840 903
1024 840 return (1, $value);
1025 }
1026  
1027 # The members of a map (container 2) or array (container 1). An empty
1028 # one is dropped (()), a malformed one kept as it is.
1029 105 ▶sub _normaliseContainer {
Subroutine _normaliseContainer: called CC=10 SCAR=24.3
1030 105 my ($class, $entry, $key, $value, $keepEmpty) = @_;
1031 105 my ($container) = @$entry;
1032  
1033 105 ▶ if ($container == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($container == 2) 98 7 105
1034 98 ▶ return $value unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 0 98 98
1035 98 ▶ return $value if !%$value and $keepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if not %$value and $keepEmpty 1 97 98
Condition66%2/3
not %$value and $keepEmpty
!ll&&!rl&&r
9701
MC/DC50%1/2
not %$value and $keepEmpty
not %$value $keepEmpty
Truth table66%2/3
not(A) and B
A= not %$valueB= $keepEmpty
ABresult
0X0
100
111
1036 97 ▶ return () unless %$value;
Branch: 1 branch
BranchTrueFalseTotal
unless %$value 0 97 97
1037 97 my %new = map { $_ => $class->_normaliseMember($entry, $key, $value->{$_}) } keys %$value;
1038 97 return \%new;
1039 }
1040  
1041 7 ▶ return $value unless ref($value) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 7 7
1042 7 ▶ return $value if !@$value and $keepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
if not @$value and $keepEmpty 0 7 7
Condition33%1/3
not @$value and $keepEmpty
!ll&&!rl&&r
700
MC/DC0%0/2
not @$value and $keepEmpty
not @$value $keepEmpty
Truth table33%1/3
not(A) and B
A= not @$valueB= $keepEmpty
ABresult
0X0
100
111
1043 7 ▶ return () unless @$value;
Branch: 1 branch
BranchTrueFalseTotal
unless @$value 0 7 7
1044 7 return [ map { $class->_normaliseMember($entry, $key, $_) } @$value ];
1045 }
1046  
1047 # One member of a map or array: an object or a patch is normalised, any
1048 # other value (a boolean in a set, a string) is kept.
1049 164 ▶sub _normaliseMember {
Subroutine _normaliseMember: called CC=4 SCAR=14.0
1050 164 my ($class, $entry, $key, $value) = @_;
1051 164 my $type = $entry->[1];
1052 164 ▶ return $value unless ref($value) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "HASH" 49 115 164
1053 115 ▶ return $class->NormaliseEvent($value, $key) if $type eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "object" 96 19 115
1054 19 ▶ return $class->_normalisePatch($value) if $type eq 'patch';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "patch" 19 0 19
1055 0 return $value;
1056 }
1057  
1058 # A PatchObject (jscalendarbis-22 1.4.9). Each path that resolves to a
1059 # known object position has its value normalised as that object; a value
1060 # is never dropped (a patch setting a default overrides the master), and
1061 # a path that does not resolve is kept untouched.
1062 19 ▶sub _normalisePatch {
Subroutine _normalisePatch: called CC=10 SCAR=23.7
1063 19 my ($class, $Patch) = @_;
1064  
1065 19 my %new;
1066 19 foreach my $path (keys %$Patch) {
1067 32 my $value = $Patch->{$path};
1068 32 my ($where, $entry, $key) = _patchTarget($path);
1069 32 ▶ if (!$where or ref($value) ne 'HASH' && ref($value) ne 'ARRAY') {
Branch: 4 branches
BranchTrueFalseTotal
if (not $where or ref $value ne 'HASH' and ref $value ne 'ARRAY') { } 24 8 32
elsif ($where eq 'member') { } 1 7 8
elsif ($entry->[0]) { } 6 1 7
elsif ($entry->[1] eq 'object' and ref $value eq 'HASH') { } 1 0 1
Condition83%5/6
not $where or ref $value ne "HASH" and ref $value ne "ARRAY"
l!l&&r!l&&!r
5198
ref $value ne "HASH" and ref $value ne "ARRAY"
!ll&&!rl&&r
8019
MC/DC66%2/3
not $where or ref $value ne "HASH" and ref $value ne "ARRAY"
not $where ref $value ne "HASH" ref $value ne "ARRAY"
Truth table75%3/4
not(A) or B and C
A= not $whereB= ref $value ne "HASH"C= ref $value ne "ARRAY"
ABCresult
1XX1
0111
00X0
0100
1070 24 $new{$path} = $value;
1071 }
1072 elsif ($where eq 'member') {
1073 # participants/p1, byDay/0: one object of the map or array
1074 1 ▶ $new{$path} = $entry->[1] eq 'object'
Branch: 1 branch
BranchTrueFalseTotal
$entry->[1] eq 'object' ? : 1 0 1
1075 ? $class->_normaliseMember($entry, $key, $value) : $value;
1076 }
1077 elsif ($entry->[0]) {
1078 # a whole map or array: an empty one is still a patch
1079 6 $new{$path} = $class->_normaliseContainer($entry, $key, $value, 1);
1080 }
1081 ▶ elsif ($entry->[1] eq 'object' and ref($value) eq 'HASH') {
Condition33%1/3
$entry->[1] eq "object" and ref $value eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
$entry->[1] eq "object" and ref $value eq "HASH"
$entry->[1] eq "object" ref $value eq "HASH"
Truth table33%1/3
A and B
A= $entry->[1] eq "object"B= ref $value eq "HASH"
ABresult
0X0
100
111
1082 1 $new{$path} = $class->NormaliseEvent($value, $key);
1083 }
1084 else {
1085 0 $new{$path} = $value;
1086 }
1087 }
1088  
1089 19 return \%new;
1090 }
1091  
1092 # Where a patch path points in %EventKeys: ('prop', $entry, $name) for a
1093 # property, ('member', $entry, $name) for one member of a map or array
1094 # property, or () when it is not a position the table describes.
1095 32 ▶sub _patchTarget {
Subroutine _patchTarget: called CC=9 SCAR=23.0
1096 32 my $path = shift;
1097 32 my @segs = map { _unquotekey($_) } split m{/}, $path, -1;
1098 32 my $table = '';
1099 32 ▶ while (@segs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@segs) 34 0 34
1100 34 my $name = shift @segs;
1101 34 ▶ my $entry = ($EventKeys{$table} || {})->{$name} or return ();
Branch: 1 branch
BranchTrueFalseTotal
my $entry = +($EventKeys{$table} || {})->{$name} or return () 29 5 34
Condition50%1/2
$EventKeys{$table} || {}
l!l
340
MC/DC0%0/1
$EventKeys{$table} || {}
$EventKeys{$table}
Truth table50%1/2
A
A= $EventKeys{$table}
Aresult
11
00
1102 29 ▶ return ('prop', $entry, $name) unless @segs;
Branch: 1 branch
BranchTrueFalseTotal
unless @segs 26 3 29
1103 3 ▶ if ($entry->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry->[0]) 3 0 3
1104 3 shift @segs; # the map key or array index
1105 3 ▶ return ('member', $entry, $name) unless @segs;
Branch: 1 branch
BranchTrueFalseTotal
unless @segs 1 2 3
1106 }
1107 # deeper in: only into an object with a table of its own
1108 2 ▶ return () unless $entry->[1] eq 'object' and $EventKeys{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $entry->[1] eq "object" and $EventKeys{$name} 0 2 2
Condition33%1/3
$entry->[1] eq "object" and $EventKeys{$name}
!ll&&!rl&&r
002
MC/DC0%0/2
$entry->[1] eq "object" and $EventKeys{$name}
$entry->[1] eq "object" $EventKeys{$name}
Truth table33%1/3
A and B
A= $entry->[1] eq "object"B= $EventKeys{$name}
ABresult
0X0
100
111
1109 2 $table = $name;
1110 }
1111 0 return ();
1112 }
1113  
1114 =head2 Text::JSCalendar->CompareEvents($Event1, $Event2);
1115  
1116 Returns true if the events are the same once normalised (see
1117 C<NormaliseEvent>).
1118  
1119 =cut
1120  
1121 7 ▶sub CompareEvents {
Subroutine CompareEvents: called CC=1 SCAR=0.0
Pod documented
1122 7 my ($class, $Event1, $Event2) = @_;
1123  
1124 7 my $E1 = $class->NormaliseEvent($Event1);
1125 7 my $E2 = $class->NormaliseEvent($Event2);
1126  
1127 7 return _safeeq($E1, $E2);
1128 }
1129  
1130 # Text::VCardFast recurses once per BEGIN, in C: nesting tens of thousands
1131 # deep overflows the stack and kills the process (no eval can catch that).
1132 # Real iCalendar nests four or so (VCALENDAR, VEVENT, VALARM); refuse
1133 # anything deeper than this before it gets there.
1134 19 our $MAX_NESTING = 16;
1135 395 ▶sub _nesting_ok {
Subroutine _nesting_ok: called CC=5 SCAR=16.1
1136 395 my ($text) = @_;
1137 395 my ($depth, $max) = (0, 0);
1138 395 ▶ while ($text =~ /^(BEGIN|END)[ \t]*:/mgi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text =~ /^(BEGIN|END)[ \t]*:/mig) 2559 394 2953
1139 2559 ▶ if (uc $1 eq 'BEGIN') { $depth++; return 0 if $depth > $MAX_NESTING }
Branch: 2 branches
BranchTrueFalseTotal
if (uc $1 eq 'BEGIN') { } 1288 1271 2559
if $depth > $Text::JSCalendar::MAX_NESTING 1 1287 1288
1140 1271 ▶ else { $depth-- if $depth > 0 }
Branch: 1 branch
BranchTrueFalseTotal
if $depth > 0 1271 0 1271
1141 }
1142 394 return 1;
1143 }
1144  
1145 395 ▶sub _getEventsFromVCalendar {
Subroutine _getEventsFromVCalendar: called CC=12 SCAR=25.0
1146 395 my ($Self, $VCalendar) = @_;
1147  
1148 395 ▶ confess "Error parsing VCalendar data: components nested more than $MAX_NESTING deep\n"
Branch: 1 branch
BranchTrueFalseTotal
unless _nesting_ok($VCalendar) 1 394 395
1149 unless _nesting_ok($VCalendar);
1150 394 ▶ my $CalendarData = eval { vcard2hash($VCalendar, multival => ['rrule'], only_one => 1) }
Branch: 1 branch
BranchTrueFalseTotal
my $CalendarData = eval { do { vcard2hash($VCalendar, "multival", ["rrule"], "only_one", 1) } } or confess("Error parsing VCalendar data: $@\n\n$VCalendar") 394 0 394
1151 or confess "Error parsing VCalendar data: $@\n\n$VCalendar";
1152  
1153 394 my @Events;
1154  
1155 394 ▶ foreach my $Calendar (@{$CalendarData->{objects} || []}) {
Condition50%1/2
$CalendarData->{'objects'} || []
l!l
3940
MC/DC0%0/1
$CalendarData->{'objects'} || []
$CalendarData->{'objects'}
Truth table50%1/2
A
A= $CalendarData->{'objects'}
Aresult
11
00
1156 394 ▶ next unless lc $Calendar->{type} eq 'vcalendar';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $Calendar->{"type"} eq "vcalendar" 0 394 394
1157  
1158 394 my $method = $Calendar->{properties}{method}[0]{value};
1159 394 my $prodid = $Calendar->{properties}{prodid}[0]{value};
1160  
1161 394 ▶ foreach my $VEvent (@{$Calendar->{objects} || []}) {
Condition100%2/2
$Calendar->{'objects'} || []
l!l
38410
MC/DC100%1/1
$Calendar->{'objects'} || []
$Calendar->{'objects'}
Truth table100%2/2
A
A= $Calendar->{'objects'}
Aresult
11
00
1162 548 ▶ my $type = lc($VEvent->{type} // '');
Condition50%1/2
$VEvent->{"type"} // ""
l!l
5480
MC/DC0%0/1
$VEvent->{"type"} // ""
$VEvent->{"type"}
Truth table50%1/2
A
A= $VEvent->{"type"}
Aresult
11
00
1163 548 ▶ next unless $type eq 'vevent' || $type eq 'vtodo';
Branch: 1 branch
BranchTrueFalseTotal
unless $type eq "vevent" or $type eq "vtodo" 109 439 548
Condition100%3/3
$type eq "vevent" or $type eq "vtodo"
l!l&&r!l&&!r
41722109
MC/DC100%2/2
$type eq "vevent" or $type eq "vtodo"
$type eq "vevent" $type eq "vtodo"
Truth table100%3/3
A or B
A= $type eq "vevent"B= $type eq "vtodo"
ABresult
1X1
011
000
1164 # each component on its own: one that cannot be converted is
1165 # dropped (and reported by errors()), not the whole calendar
1166 439 my $Event = eval { $Self->_vEventToEvent($Calendar, $VEvent, $method, $prodid) };
1167 439 ▶ if ($Event) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Event) { } 428 11 439
1168 428 push @Events, $Event;
1169 }
1170 else {
1171 11 $Self->_error($VEvent->{properties}{uid}[0]{value}, uc $type, $@);
1172 }
1173 }
1174 }
1175  
1176 394 return \@Events;
1177 }
1178  
1179 # One VEVENT or VTODO as an Event or Task. Dies if it cannot be
1180 # converted; a bad VALARM or RRULE in it is dropped and reported instead.
1181 439 ▶sub _vEventToEvent {
Subroutine _vEventToEvent: called CC=237 SCAR=59.6
1182 439 my ($Self, $Calendar, $VEvent, $method, $prodid) = @_;
1183  
1184 439 my $is_task = lc $VEvent->{type} eq 'vtodo';
1185  
1186 # parse simple component properties {{{
1187  
1188 my %Properties
1189 3144 = map { $_ => $VEvent->{properties}{$_}[0] }
1190 439 keys %{$VEvent->{properties}};
1191  
1192 439 my $uid = $Properties{uid}{value};
1193 # Case: UID is badly broken or missing -
1194 # let's just calculate a UID based on the incoming data. This
1195 # is the 'ICS sync url with no UIDs in it' case from BTS-3205,
1196 # http://mozorg.cdn.mozilla.net/media/caldata/DutchHolidays.ics
1197 439 ▶ $uid = _hexkey($VEvent) . '-syncauto' unless _saneuid($uid);
Branch: 1 branch
BranchTrueFalseTotal
unless _saneuid($uid) 0 439 439
1198  
1199 439 ▶ my $ShowAsFree = (lc($Properties{transp}{value} || '')) eq 'transparent';
Condition100%2/2
$Properties{'transp'}{'value'} || ''
l!l
288151
MC/DC100%1/1
$Properties{'transp'}{'value'} || ''
$Properties{'transp'}{'value'}
Truth table100%2/2
A
A= $Properties{'transp'}{'value'}
Aresult
11
00
1200  
1201 # clean up whitespace on text fields
1202 439 foreach my $Property (qw{description location summary}) {
1203 1317 ▶ next unless defined $Properties{$Property}{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Properties{$Property}{"value"} 960 357 1317
1204 357 $Properties{$Property}{value} =~ s/^\s+//gs;
1205 357 $Properties{$Property}{value} =~ s/\s+$//gs;
1206 }
1207  
1208 439 my @description;
1209 push @description, $Properties{description}{value}
1210 439 ▶ if defined $Properties{description}{value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Properties{"description"}{"value"} 88 351 439
1211  
1212 # }}}
1213  
1214 # parse time component properties {{{
1215  
1216 439 my ($IsAllDay, $Start, $StartTimeZone, $End, $EndTimeZone) = ('') x 5;
1217  
1218 439 ▶ confess "$uid: DTSTART not specified" unless defined $Properties{dtstart}{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Properties{"dtstart"}{"value"} 10 429 439
1219  
1220 429 ($Start, $StartTimeZone, $IsAllDay) = $Self->_getDateObj($Calendar, $Properties{dtstart});
1221  
1222 428 ▶ if (defined $Properties{dtend}{value}) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $Properties{'dtend'}{'value'}) { } 284 144 428
elsif (defined $Properties{'duration'}{'value'}) { } 20 124 144
1223 284 ▶ if (defined $Properties{duration}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Properties{"duration"}{"value"}) 1 283 284
1224 1 $Self->_warning($uid, uc $VEvent->{type}, "DTEND and DURATION cannot both be set; DURATION ignored");
1225 }
1226  
1227 284 ($End, $EndTimeZone) = $Self->_getDateObj($Calendar, $Properties{dtend});
1228 }
1229 elsif (defined $Properties{duration}{value}) {
1230 20 my $Duration = DateTime::Format::ICal->parse_duration(uc $Properties{duration}{value});
1231 20 $End = $Start->clone()->add($Duration);
1232 20 $EndTimeZone = $StartTimeZone;
1233 }
1234 else {
1235 124 $End = $Start->clone();
1236 124 $EndTimeZone = $StartTimeZone;
1237 }
1238  
1239 428 ▶ if (DateTime->compare($Start, $End) > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ("DateTime"->compare($Start, $End) > 0) 0 428 428
1240 # swap em!
1241 0 ($Start, $End) = ($End, $Start);
1242 0 ($StartTimeZone, $EndTimeZone) = ($EndTimeZone, $StartTimeZone);
1243 }
1244  
1245 428 ▶ if ($IsAllDay and $StartTimeZone) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay and $StartTimeZone) 0 428 428
Condition66%2/3
$IsAllDay and $StartTimeZone
!ll&&!rl&&r
404240
MC/DC0%0/2
$IsAllDay and $StartTimeZone
$IsAllDay $StartTimeZone
Truth table66%2/3
A and B
A= $IsAllDayB= $StartTimeZone
ABresult
0X0
100
111
1246 0 $Self->_warning($uid, uc $VEvent->{type}, "all-day DTSTART with time zone $StartTimeZone");
1247 }
1248  
1249 # if one is set, make sure they are both set
1250 428 ▶ $StartTimeZone ||= $EndTimeZone;
Condition66%2/3
$StartTimeZone ||= $EndTimeZone
l!l&&r!l&&!r
396032
MC/DC50%1/2
$StartTimeZone ||= $EndTimeZone
$StartTimeZone $EndTimeZone
Truth table66%2/3
A ||= B
A= $StartTimeZoneB= $EndTimeZone
ABresult
1X1
011
000
1251 428 ▶ $EndTimeZone ||= $StartTimeZone;
Condition66%2/3
$EndTimeZone ||= $StartTimeZone
l!l&&r!l&&!r
396032
MC/DC50%1/2
$EndTimeZone ||= $StartTimeZone
$EndTimeZone $StartTimeZone
Truth table66%2/3
A ||= B
A= $EndTimeZoneB= $StartTimeZone
ABresult
1X1
011
000
1252  
1253 # }}}
1254  
1255 428 my %Recurrence;
1256  
1257 428 ▶ if (exists $Properties{rrule}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $Properties{"rrule"}) 60 368 428
1258 # a rule that cannot be read drops only itself (see errors())
1259 60 my $ok = eval {
1260 60 my %RRULE;
1261  
1262 60 foreach my $RRULE (@{$Properties{rrule}{values}}) {
1263 157 my ($Key,$Value) = split '=', $RRULE;
1264 157 ▶ next unless defined $Value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Value 0 157 157
1265  
1266 157 $RRULE{lc $Key} = $Value;
1267 }
1268  
1269 # parse simple recurrence properties {{{
1270  
1271 60 ▶ if (exists $RRULE{freq}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{'freq'}) { } 60 0 60
1272 60 my $freq = lc $RRULE{freq};
1273 60 ▶ unless ($ValidFrequency{$freq}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidFrequency{$freq}) 2 58 60
1274 2 confess "$uid: Invalid recurrence FREQ ($freq)";
1275 }
1276  
1277 58 $Recurrence{frequency} = $freq;
1278 }
1279 else {
1280 0 confess "$uid: Recurrence FREQ not specified";
1281 }
1282  
1283 58 ▶ if (exists $RRULE{interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"interval"}) 8 50 58
1284 8 ▶ unless ($RRULE{interval} =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RRULE{"interval"} =~ /^\d+$/) 0 8 8
1285 0 confess "$uid: Invalid recurrence INTERVAL ($RRULE{interval})";
1286 }
1287 8 my $interval = int $RRULE{interval};
1288  
1289 8 ▶ if ($interval == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval == 0) 0 8 8
1290 0 confess "$uid: Recurrence INTERVAL is out of range ($RRULE{interval})";
1291 }
1292  
1293 # default == 1, so don't set a key for it
1294 8 ▶ if ($interval > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval > 1) 8 0 8
1295 8 $Recurrence{interval} = $interval;
1296 }
1297 }
1298  
1299 58 ▶ if (exists $RRULE{rscale}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"rscale"}) 14 44 58
1300 14 $Recurrence{rscale} = lc $RRULE{rscale};
1301 14 ▶ $Recurrence{skip} = lc $RRULE{skip} if $RRULE{skip};
Branch: 1 branch
BranchTrueFalseTotal
if $RRULE{"skip"} 14 0 14
1302 }
1303  
1304 58 ▶ if (exists $RRULE{wkst}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"wkst"}) 1 57 58
1305 1 my $wkst = lc $RRULE{wkst};
1306 1 ▶ unless ($ValidDay{$wkst}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{$wkst}) 0 1 1
1307 0 confess "$uid: Invalid recurrence WKST ($wkst)";
1308 }
1309  
1310 # default is Monday, so don't set a key for it
1311 1 ▶ if ($wkst ne 'mo') {
Branch: 1 branch
BranchTrueFalseTotal
if ($wkst ne "mo") 1 0 1
1312 1 $Recurrence{firstDayOfWeek} = $wkst;
1313 }
1314 }
1315  
1316 58 ▶ if (exists $RRULE{byday}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"byday"}) 15 43 58
1317 15 my @byDays;
1318  
1319 15 foreach my $BYDAY (split ',', $RRULE{byday}) {
1320 43 push @byDays, _BYDAY2byDay(lc $BYDAY);
1321 }
1322  
1323 15 ▶ $Recurrence{byDay} = \@byDays if @byDays;
Branch: 1 branch
BranchTrueFalseTotal
if @byDays 15 0 15
1324 }
1325  
1326 58 ▶ if (exists $RRULE{bymonth}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"bymonth"}) 8 50 58
1327 8 foreach my $BYMONTH (split ',', $RRULE{bymonth}) {
1328 9 ▶ unless ($BYMONTH =~ /^\d+L?$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($BYMONTH =~ /^\d+L?$/) 0 9 9
1329 0 confess "$uid: Invalid recurrence BYMONTH ($BYMONTH, $RRULE{bymonth})";
1330 }
1331  
1332 9 push @{$Recurrence{byMonth}}, "$BYMONTH";
1333 }
1334 }
1335  
1336 58 ▶ if (exists $RRULE{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"count"}) 16 42 58
1337 16 ▶ if (exists $RRULE{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"until"}) 0 16 16
1338 #confess "$uid: Recurrence COUNT and UNTIL cannot both be set";
1339 # seen in the wild: PRODID:-//dmfs.org//mimedir.icalendar//EN
1340 0 delete $RRULE{until};
1341 }
1342  
1343 16 ▶ unless ($RRULE{count} =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($RRULE{"count"} =~ /^\d+$/) 0 16 16
1344 0 confess "$uid: Invalid recurrence COUNT ($RRULE{count})";
1345 }
1346  
1347 16 $Recurrence{count} = int $RRULE{count};
1348 }
1349  
1350 58 ▶ if (exists $RRULE{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $RRULE{"until"}) 6 52 58
1351 # rfc5545 3.3.10 - UNTIL must be in DTSTART timezone, but both
1352 # google and iCloud store it in Z, so we will too as per rfc2445.
1353 6 my ($Until, $IsAllDay) = $Self->_makeDateObj($RRULE{until}, $StartTimeZone, $StartTimeZone);
1354 6 $Recurrence{until} = $Until->iso8601();
1355 }
1356  
1357 # }}}
1358  
1359 # parse generic recurrence properties {{{
1360  
1361 58 foreach my $Property (keys %RecurrenceProperties) {
1362 406 ▶ if (defined $RRULE{$Property}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $RRULE{$Property}) 15 391 406
1363 15 foreach my $Value (split ',', $RRULE{$Property}) {
1364 my ($Valid, $Min) = $RecurrenceProperties{$Property}{signed}
1365 28 ▶ ? ('[-+]?[1-9]\d*', ($RecurrenceProperties{$Property}{max} * -1))
Branch: 1 branch
BranchTrueFalseTotal
$RecurrenceProperties{$Property}{'signed'} ? : 16 12 28
1366 : ('\d+', 0);
1367  
1368 28 ▶ unless ($Value =~ /^$Valid$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value =~ /^$Valid$/) 0 28 28
1369 0 confess "$uid: Invalid recurrence $Property ($Value)";
1370 }
1371  
1372 28 ▶ unless (($Value >= $Min) and ($Value <= $RecurrenceProperties{$Property}{max})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}) 0 28 28
Condition33%1/3
$Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}
!ll&&!rl&&r
0028
MC/DC0%0/2
$Value >= $Min and $Value <= $RecurrenceProperties{$Property}{"max"}
$Value >= $Min $Value <= $RecurrenceProperties{$Property}{"max"}
Truth table33%1/3
A and B
A= $Value >= $MinB= $Value <= $RecurrenceProperties{$Property}{"max"}
ABresult
0X0
100
111
1373 0 confess "$uid: Recurrence $Property is out of range ($Value)";
1374 }
1375  
1376 28 push @{$Recurrence{$RecurrenceProperties{$Property}{name}}}, int $Value;
1377 }
1378 }
1379 }
1380  
1381 # }}}
1382 58 1;
1383 };
1384 60 ▶ unless ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 58 60
1385 2 %Recurrence = ();
1386 2 $Self->_error($uid, 'RRULE', $@);
1387 }
1388 }
1389  
1390 428 my %Overrides;
1391 428 ▶ if (exists $VEvent->{properties}{exdate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VEvent->{"properties"}{"exdate"}) 16 412 428
1392 16 foreach my $Item (@{$VEvent->{properties}{exdate}}) {
1393 17 foreach my $Date ($Self->_getDateObjMulti($Calendar, $Item, $StartTimeZone)) {
1394 18 $Overrides{$Date->iso8601()} = { excluded => $JSON::true }; # 4.3.3
1395 }
1396 }
1397 }
1398  
1399 428 ▶ if ($VEvent->{properties}{rdate}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($VEvent->{"properties"}{"rdate"}) 16 412 428
1400 # rdate = "RDATE" rdtparam ":" rdtval *("," rdtval) CRLF
1401 16 foreach my $Item (@{$VEvent->{properties}{rdate}}) {
1402 # a PERIOD's start is the key and its length the patch's
1403 # duration (jscalendar-icalendar-29 2.3.33)
1404 18 ▶ if (lc($Item->{params}{value}[0] || '') eq 'period') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc($Item->{"params"}{"value"}[0] || "") eq "period") 6 12 18
Condition100%2/2
$Item->{'params'}{'value'}[0] || ''
l!l
810
MC/DC100%1/1
$Item->{'params'}{'value'}[0] || ''
$Item->{'params'}{'value'}[0]
Truth table100%2/2
A
A= $Item->{'params'}{'value'}[0]
Aresult
11
00
1405 6 my $TimeZone = $Self->_getTimeZone($Calendar, $Item);
1406 6 foreach my $Period (split /,/, $Item->{value}) {
1407 7 my ($From, $To) = split m{/}, $Period, 2;
1408 7 ▶ my ($Date) = eval { $Self->_makeDateObj($From, $TimeZone, $StartTimeZone) } or next;
Branch: 1 branch
BranchTrueFalseTotal
my($Date) = eval { do { $Self->_makeDateObj($From, $TimeZone, $StartTimeZone) } } or next 7 0 7
1409 7 my $Length;
1410 7 ▶ if (defined $To and $To =~ /^[+-]?P/i) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $To and $To =~ /^[+-]?P/i) { } 2 5 7
elsif (defined $To) { } 5 0 5
Condition66%2/3
defined $To and $To =~ /^[+-]?P/i
!ll&&!rl&&r
052
MC/DC50%1/2
defined $To and $To =~ /^[+-]?P/i
defined $To $To =~ /^[+-]?P/i
Truth table66%2/3
A and B
A= defined $ToB= $To =~ /^[+-]?P/i
ABresult
0X0
100
111
1411 2 $Length = eval { DateTime::Format::ICal->parse_duration(uc $To) };
1412 }
1413 elsif (defined $To) {
1414 5 my ($Until) = eval { $Self->_makeDateObj($To, $TimeZone, $StartTimeZone) };
1415 5 ▶ $Length = $Until->subtract_datetime($Date) if $Until;
Branch: 1 branch
BranchTrueFalseTotal
if $Until 5 0 5
1416 }
1417 7 ▶ $Overrides{$Date->iso8601()} = ($Length && !$Length->is_negative)
Branch: 1 branch
BranchTrueFalseTotal
$Length && !$Length->is_negative ? : 7 0 7
Condition33%1/3
$Length and not $Length->is_negative
!ll&&!rl&&r
007
MC/DC0%0/2
$Length and not $Length->is_negative
$Length not $Length->is_negative
Truth table33%1/3
A and not(B)
A= $LengthB= not $Length->is_negative
ABresult
0X0
100
111
1418 ? { duration => $Self->_make_duration($Length) } : {};
1419 }
1420 6 next;
1421 }
1422 12 foreach my $Date ($Self->_getDateObjMulti($Calendar, $Item, $StartTimeZone)) {
1423 12 $Overrides{$Date->iso8601()} = {};
1424 }
1425 }
1426 }
1427  
1428 # parse alarms {{{
1429  
1430 428 my %Alerts;
1431 428 ▶ foreach my $VAlarm (@{$VEvent->{objects} || []}) {
Condition100%2/2
$VEvent->{'objects'} || []
l!l
72356
MC/DC100%1/1
$VEvent->{'objects'} || []
$VEvent->{'objects'}
Truth table100%2/2
A
A= $VEvent->{'objects'}
Aresult
11
00
1432 112 ▶ next unless lc $VAlarm->{type} eq 'valarm';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $VAlarm->{"type"} eq "valarm" 12 100 112
1433 # a bad alarm drops only itself (see errors())
1434 100 my $alarmuid;
1435 100 my $ok = eval {
1436  
1437 my %AlarmProperties
1438 423 = map { $_ => $VAlarm->{properties}{$_}[0] }
1439 100 keys %{$VAlarm->{properties}};
1440  
1441 $alarmuid = $AlarmProperties{uid}{value}
1442 || $AlarmProperties{'x-wr-alarmuid'}{value}
1443 100 ▶ || _hexkey($VAlarm, $uid) . '-alarmauto';
Condition100%5/5
$AlarmProperties{'uid'}{'value'} || $AlarmProperties{'x-wr-alarmuid'}{'value'} || _hexkey($VAlarm, $uid) . '-alarmauto'
l!l
9010
$AlarmProperties{"uid"}{"value"} or $AlarmProperties{"x-wr-alarmuid"}{"value"}
l!l&&r!l&&!r
88210
MC/DC100%2/2
$AlarmProperties{'uid'}{'value'} || $AlarmProperties{'x-wr-alarmuid'}{'value'} || _hexkey($VAlarm, $uid) . '-alarmauto'
$AlarmProperties{"uid"}{"value"} $AlarmProperties{"x-wr-alarmuid"}{"value"}
Truth table100%3/3
A or B
A= $AlarmProperties{"uid"}{"value"}B= $AlarmProperties{"x-wr-alarmuid"}{"value"}
ABresult
1X1
011
000
1444  
1445 100 my %Alert;
1446 100 $Alert{'@type'} = 'Alert';
1447  
1448 # ACTION is required (RFC 5545 3.6.6)
1449 100 ▶ my $AlarmAction = lc($AlarmProperties{action}{value} // die "VALARM without ACTION\n");
Condition100%2/2
$AlarmProperties{"action"}{"value"} // die("VALARM without ACTION\n")
l!l
991
MC/DC100%1/1
$AlarmProperties{"action"}{"value"} // die("VALARM without ACTION\n")
$AlarmProperties{"action"}{"value"}
Truth table100%2/2
A
A= $AlarmProperties{"action"}{"value"}
Aresult
11
00
1450 99 ▶ return 1 unless $AlarmAction;
Branch: 1 branch
BranchTrueFalseTotal
unless $AlarmAction 0 99 99
1451  
1452 99 ▶ if ($AlarmAction eq 'display' || $AlarmAction eq 'audio') {
Branch: 3 branches
BranchTrueFalseTotal
if ($AlarmAction eq 'display' or $AlarmAction eq 'audio') { } 89 10 99
elsif ($AlarmAction eq 'email') { } 8 2 10
elsif ($AlarmAction eq 'none') { } 2 0 2
Condition100%3/3
$AlarmAction eq "display" or $AlarmAction eq "audio"
l!l&&r!l&&!r
86310
MC/DC100%2/2
$AlarmAction eq "display" or $AlarmAction eq "audio"
$AlarmAction eq "display" $AlarmAction eq "audio"
Truth table100%3/3
A or B
A= $AlarmAction eq "display"B= $AlarmAction eq "audio"
ABresult
1X1
011
000
1453 89 $Alert{action} = 'display';
1454 }
1455 elsif ($AlarmAction eq 'email') {
1456 8 $Alert{action} = 'email';
1457 }
1458 elsif ($AlarmAction eq 'none') {
1459 2 return 1;
1460 }
1461 else {
1462 0 die "unknown VALARM ACTION $AlarmAction\n";
1463 }
1464  
1465 97 ▶ if ($AlarmProperties{acknowledged}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AlarmProperties{"acknowledged"}) 16 81 97
1466 16 my $date = $Self->_getDateObj($Calendar, $AlarmProperties{acknowledged}, 'UTC');
1467 16 $Alert{acknowledged} = $date->iso8601() . 'Z';
1468 }
1469  
1470 my $Trigger = $AlarmProperties{trigger}{value}
1471 97 ▶ || return 1;
Condition50%1/2
$AlarmProperties{'trigger'}{'value'} || (return 1)
l!l
970
MC/DC0%0/1
$AlarmProperties{'trigger'}{'value'} || (return 1)
$AlarmProperties{'trigger'}{'value'}
Truth table50%1/2
A
A= $AlarmProperties{'trigger'}{'value'}
Aresult
11
00
1472  
1473 97 ▶ my $Related = (lc ($AlarmProperties{trigger}{params}{related}[0] || '') eq 'end')
Branch: 1 branch
BranchTrueFalseTotal
lc($AlarmProperties{'trigger'}{'params'}{'related'}[0] || '') eq 'end' ? : 18 79 97
Condition100%2/2
$AlarmProperties{'trigger'}{'params'}{'related'}[0] || ''
l!l
2077
MC/DC100%1/1
$AlarmProperties{'trigger'}{'params'}{'related'}[0] || ''
$AlarmProperties{'trigger'}{'params'}{'related'}[0]
Truth table100%2/2
A
A= $AlarmProperties{'trigger'}{'params'}{'related'}[0]
Aresult
11
00
1474 ? 'end'
1475 : 'start';
1476  
1477 97 ▶ if ($Trigger =~ m/^[+-]?P/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Trigger =~ /^[+-]?P/i) { } 81 16 97
1478 81 ▶ my $Duration = eval { DateTime::Format::ICal->parse_duration(uc $Trigger) }
Condition50%1/2
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } } || (return 1)
l!l
810
MC/DC0%0/1
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } } || (return 1)
eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } }
Truth table50%1/2
A
A= eval { do { 'DateTime::Format::ICal'->parse_duration(uc $Trigger) } }
Aresult
11
00
1479 || return 1;
1480  
1481 81 my ($IsNeg, $OffsetStr);
1482 81 ▶ if ($Duration->is_negative()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Duration->is_negative) 67 14 81
1483 67 $Duration = $Duration->inverse();
1484 67 $IsNeg = 1;
1485 }
1486 # jscalendarbis-22 3.5.1: on a Task, "end" MUST NOT be used
1487 # without a due. RFC 5545 3.8.6.3 puts such a VTODO's end at
1488 # DTSTART + DURATION, so say the same instant relative to start.
1489 81 ▶ if ($is_task and $Related eq 'end' and not $Properties{due}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task and $Related eq "end" and not $Properties{"due"}{"value"}) 2 79 81
Condition83%5/6
$is_task and $Related eq "end" and not $Properties{"due"}{"value"}
!ll&&!rl&&r
7452
$is_task and $Related eq "end"
!ll&&!rl&&r
7407
MC/DC66%2/3
$is_task and $Related eq "end" and not $Properties{"due"}{"value"}
$is_task $Related eq "end" not $Properties{"due"}{"value"}
Truth table75%3/4
A and B and not(C)
A= $is_taskB= $Related eq "end"C= not $Properties{"due"}{"value"}
ABCresult
0XX0
10X0
1100
1111
1490 2 my $Span = $End->subtract_datetime($Start);
1491 2 ▶ $Duration = $IsNeg ? $Span->clone->subtract_duration($Duration)
Branch: 1 branch
BranchTrueFalseTotal
$IsNeg ? : 2 0 2
1492 : $Span->clone->add_duration($Duration);
1493 2 $IsNeg = 0;
1494 2 ▶ if ($Duration->is_negative()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Duration->is_negative) 1 1 2
1495 1 $Duration = $Duration->inverse();
1496 1 $IsNeg = 1;
1497 }
1498 2 $Related = 'start';
1499 }
1500 81 ▶ $OffsetStr = ($IsNeg ? '-' : '') . $Self->_make_duration($Duration);
Branch: 1 branch
BranchTrueFalseTotal
$IsNeg ? : 66 15 81
1501 $Alert{trigger} = {
1502 81 '@type' => 'OffsetTrigger',
1503 'offset' => $OffsetStr,
1504 'relativeTo' => $Related,
1505 };
1506 }
1507 else {
1508 # Absolute trigger (VALUE=DATE-TIME)
1509 16 my $AlertDate = $Self->_getDateObj($Calendar, $AlarmProperties{trigger}, 'UTC');
1510 $Alert{trigger} = {
1511 16 '@type' => 'AbsoluteTrigger',
1512 'when' => $AlertDate->iso8601() . 'Z',
1513 };
1514 }
1515  
1516 97 $Alerts{$alarmuid} = \%Alert;
1517 97 1;
1518 };
1519 100 ▶ $Self->_error($uid, 'VALARM', $@, $alarmuid) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 99 100
1520 }
1521  
1522 # }}}
1523  
1524 # parse attendees {{{
1525  
1526 428 my %Participants;
1527 my %AddrKeys;
1528 428 ▶ for my $VProp (@{$VEvent->{properties}{organizer} || []},
Condition100%2/2
$VEvent->{'properties'}{'organizer'} || []
l!l
67361
MC/DC100%1/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1529 428 ▶ @{$VEvent->{properties}{attendee} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attendee'} || []
l!l
70358
MC/DC100%1/1
$VEvent->{'properties'}{'attendee'} || []
$VEvent->{'properties'}{'attendee'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attendee'}
Aresult
11
00
1530 195 ▶ my $jsid = _propJSID($VProp) // next;
Condition100%2/2
_propJSID($VProp) // (next)
l!l
40155
MC/DC100%1/1
_propJSID($VProp) // (next)
_propJSID($VProp)
Truth table100%2/2
A
A= _propJSID($VProp)
Aresult
11
00
1531 40 ▶ my $addr = $VProp->{value} // next;
Condition50%1/2
$VProp->{"value"} // (next)
l!l
400
MC/DC0%0/1
$VProp->{"value"} // (next)
$VProp->{"value"}
Truth table50%1/2
A
A= $VProp->{"value"}
Aresult
11
00
1532 40 $addr =~ s/^mailto://i;
1533 40 ▶ $AddrKeys{lc $addr} //= $jsid;
Condition66%2/3
$AddrKeys{lc $addr} //= $jsid
l!l&&r!l&&!r
7330
MC/DC0%0/2
$AddrKeys{lc $addr} //= $jsid
$AddrKeys{lc $addr} $jsid
Truth table66%2/3
A //= B
A= $AddrKeys{lc $addr}B= $jsid
ABresult
1X1
011
000
1534 }
1535 428 ▶ for my $VOrganizer (@{$VEvent->{properties}{organizer} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'organizer'} || []
l!l
67361
MC/DC100%1/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1536 67 $Self->_makeParticipant($Calendar, \%Participants, $VOrganizer, 'owner', \%AddrKeys);
1537 }
1538 428 ▶ for my $VAttendee (@{$VEvent->{properties}{attendee} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attendee'} || []
l!l
70358
MC/DC100%1/1
$VEvent->{'properties'}{'attendee'} || []
$VEvent->{'properties'}{'attendee'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attendee'}
Aresult
11
00
1539 128 $Self->_makeParticipant($Calendar, \%Participants, $VAttendee, 'attendee', \%AddrKeys);
1540 }
1541  
1542 # }}}
1543  
1544 # parse attachments {{{
1545  
1546 428 my %Links;
1547 428 ▶ foreach my $Attach (@{$VEvent->{properties}{attach} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'attach'} || []
l!l
17411
MC/DC100%1/1
$VEvent->{'properties'}{'attach'} || []
$VEvent->{'properties'}{'attach'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'attach'}
Aresult
11
00
1548 26 ▶ next unless $Attach->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $Attach->{"value"} 0 26 26
1549  
1550 26 my $uri;
1551 26 ▶ my $encoding = lc($Attach->{params}{encoding}[0] || '');
Condition100%2/2
$Attach->{'params'}{'encoding'}[0] || ''
l!l
125
MC/DC100%1/1
$Attach->{'params'}{'encoding'}[0] || ''
$Attach->{'params'}{'encoding'}[0]
Truth table100%2/2
A
A= $Attach->{'params'}{'encoding'}[0]
Aresult
11
00
1552 26 ▶ if ($encoding eq 'base64' || $encoding eq 'b') {
Branch: 2 branches
BranchTrueFalseTotal
if ($encoding eq 'base64' or $encoding eq 'b') { } 1 25 26
elsif (grep {$Attach->{'value'} =~ m[^$_://];} 'http', 'https', 'ftp', 'data') { } 23 2 25
Condition66%2/3
$encoding eq "base64" or $encoding eq "b"
l!l&&r!l&&!r
1025
MC/DC50%1/2
$encoding eq "base64" or $encoding eq "b"
$encoding eq "base64" $encoding eq "b"
Truth table66%2/3
A or B
A= $encoding eq "base64"B= $encoding eq "b"
ABresult
1X1
011
000
1553 # Binary ATTACH - convert to data: URI
1554 1 ▶ my $mime = $Attach->{params}{fmttype}[0] || 'application/octet-stream';
Condition50%1/2
$Attach->{'params'}{'fmttype'}[0] || 'application/octet-stream'
l!l
10
MC/DC0%0/1
$Attach->{'params'}{'fmttype'}[0] || 'application/octet-stream'
$Attach->{'params'}{'fmttype'}[0]
Truth table50%1/2
A
A= $Attach->{'params'}{'fmttype'}[0]
Aresult
11
00
1555 1 $uri = "data:$mime;base64," . $Attach->{value};
1556 }
1557 100 elsif (grep { $Attach->{value} =~ m{^$_://} } qw{http https ftp data}) {
1558 23 $uri = $Attach->{value};
1559 }
1560 else {
1561 2 next;
1562 }
1563  
1564 24 my $filename = $Attach->{params}{filename}[0];
1565 24 my $mime = $Attach->{params}{fmttype}[0];
1566 24 ▶ if (not defined $mime and $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $mime and $filename) 1 23 24
Condition100%3/3
not defined $mime and $filename
!ll&&!rl&&r
8151
MC/DC100%2/2
not defined $mime and $filename
not defined $mime $filename
Truth table100%3/3
not(A) and B
A= not defined $mimeB= $filename
ABresult
0X0
100
111
1567 1 ▶ $MimeTypes ||= MIME::Types->new;
Condition33%1/3
$MimeTypes ||= "MIME::Types"->new
l!l&&r!l&&!r
010
MC/DC0%0/2
$MimeTypes ||= "MIME::Types"->new
$MimeTypes "MIME::Types"->new
Truth table33%1/3
A ||= B
A= $MimeTypesB= "MIME::Types"->new
ABresult
1X1
011
000
1568 1 my $MimeTypeObj = $MimeTypes->mimeTypeOf($filename);
1569 1 ▶ $mime = $MimeTypeObj->type() if $MimeTypeObj;
Branch: 1 branch
BranchTrueFalseTotal
if $MimeTypeObj 1 0 1
1570 }
1571  
1572 24 my $size = $Attach->{params}{size}[0];
1573  
1574 24 ▶ $Links{_propJSID($Attach) // sha1_hex(lc $uri)} = {
Branch: 3 branches
BranchTrueFalseTotal
defined $filename ? : 3 21 24
defined $mime ? : 9 15 24
defined $size && $size =~ /^\d+$/ ? : 6 18 24
Condition66%4/6
defined $size and $size =~ /^\d+$/
!ll&&!rl&&r
1806
_propJSID($Attach) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
12120
MC/DC50%1/2
defined $size and $size =~ /^\d+$/
defined $size $size =~ /^\d+$/
MC/DC0%0/2
_propJSID($Attach) // &sha1_hex(lc $uri)
_propJSID($Attach) &sha1_hex(lc $uri)
Truth table66%2/3
A and B
A= defined $sizeB= $size =~ /^\d+$/
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Attach)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1575 href => $uri,
1576 rel => 'enclosure',
1577 defined $filename ? (title => $filename) : (),
1578 defined $mime ? (contentType => $mime) : (),
1579 (defined $size && $size =~ /^\d+$/) ? (size => 0+$size) : (),
1580 };
1581 }
1582 # URL -> a link with rel "describedby", its title in LABEL
1583 # (jscalendar-icalendar 2.3.46)
1584 428 ▶ foreach my $URL (@{$VEvent->{properties}{url} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'url'} || []
l!l
9419
MC/DC100%1/1
$VEvent->{'properties'}{'url'} || []
$VEvent->{'properties'}{'url'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'url'}
Aresult
11
00
1585 9 my $uri = $URL->{value};
1586 9 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 9 9
1587 9 ▶ $Links{_propJSID($URL) // sha1_hex(lc $uri)} = {
Condition66%2/3
_propJSID($URL) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
630
MC/DC0%0/2
_propJSID($URL) // &sha1_hex(lc $uri)
_propJSID($URL) &sha1_hex(lc $uri)
Truth table66%2/3
A // B
A= _propJSID($URL)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1588 href => $uri,
1589 rel => 'describedby',
1590 _linkTitle($URL, 'label'),
1591 };
1592 }
1593 # IMAGE -> a link with rel "icon", its title in FILENAME
1594 # (jscalendar-icalendar 2.3.22; LABEL, which this module used to
1595 # write, is still read)
1596 428 ▶ foreach my $Image (@{$VEvent->{properties}{image} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'image'} || []
l!l
4424
MC/DC100%1/1
$VEvent->{'properties'}{'image'} || []
$VEvent->{'properties'}{'image'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'image'}
Aresult
11
00
1597 4 my $uri = $Image->{value};
1598 4 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 4 4
1599 4 my $size = $Image->{params}{size}[0];
1600 4 ▶ my @display = map { lc } grep { length } map { split /,/ } @{$Image->{params}{display} || []};
Condition50%1/2
$Image->{'params'}{'display'} || []
l!l
40
MC/DC0%0/1
$Image->{'params'}{'display'} || []
$Image->{'params'}{'display'}
Truth table50%1/2
A
A= $Image->{'params'}{'display'}
Aresult
11
00
1601 $Links{_propJSID($Image) // sha1_hex(lc $uri)} = {
1602 href => $uri,
1603 rel => 'icon',
1604 defined $Image->{params}{fmttype}[0] ? (contentType => $Image->{params}{fmttype}[0]) : (),
1605 (defined $size && $size =~ /^\d+$/) ? (size => 0+$size) : (),
1606 4 ▶ @display ? (display => { map { $_ => $JSON::true } @display }) : (),
Branch: 3 branches
BranchTrueFalseTotal
defined $Image->{'params'}{'fmttype'}[0] ? : 4 0 4
defined $size && $size =~ /^\d+$/ ? : 0 4 4
@display ? : 4 0 4
Condition50%3/6
defined $size and $size =~ /^\d+$/
!ll&&!rl&&r
400
_propJSID($Image) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
220
MC/DC0%0/2
defined $size and $size =~ /^\d+$/
defined $size $size =~ /^\d+$/
MC/DC0%0/2
_propJSID($Image) // &sha1_hex(lc $uri)
_propJSID($Image) &sha1_hex(lc $uri)
Truth table33%1/3
A and B
A= defined $sizeB= $size =~ /^\d+$/
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Image)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1607 _linkTitle($Image, 'filename', 'label'),
1608 };
1609 }
1610 # LINK with value type URI (jscalendar-icalendar 2.3.24): LINKREL is
1611 # the rel, LABEL the title; any other value type does not convert
1612 428 ▶ foreach my $Link (@{$VEvent->{properties}{link} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'link'} || []
l!l
5423
MC/DC100%1/1
$VEvent->{'properties'}{'link'} || []
$VEvent->{'properties'}{'link'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'link'}
Aresult
11
00
1613 8 my $uri = $Link->{value};
1614 8 ▶ next unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 8 8
1615 8 ▶ next unless lc($Link->{params}{value}[0] // 'uri') eq 'uri';
Branch: 1 branch
BranchTrueFalseTotal
unless lc($Link->{"params"}{"value"}[0] // "uri") eq "uri" 1 7 8
Condition50%1/2
$Link->{"params"}{"value"}[0] // "uri"
l!l
80
MC/DC0%0/1
$Link->{"params"}{"value"}[0] // "uri"
$Link->{"params"}{"value"}[0]
Truth table50%1/2
A
A= $Link->{"params"}{"value"}[0]
Aresult
11
00
1616 7 my $rel = $Link->{params}{linkrel}[0];
1617 $Links{_propJSID($Link) // sha1_hex(lc $uri)} = {
1618 href => $uri,
1619 defined $rel && length $rel ? (rel => $rel) : (),
1620 7 ▶ defined $Link->{params}{fmttype}[0] ? (contentType => $Link->{params}{fmttype}[0]) : (),
Branch: 2 branches
BranchTrueFalseTotal
defined $rel && length $rel ? : 7 0 7
defined $Link->{'params'}{'fmttype'}[0] ? : 1 6 7
Condition50%3/6
defined $rel and length $rel
!ll&&!rl&&r
007
_propJSID($Link) // &sha1_hex(lc $uri)
l!l&&r!l&&!r
430
MC/DC0%0/2
defined $rel and length $rel
defined $rel length $rel
MC/DC0%0/2
_propJSID($Link) // &sha1_hex(lc $uri)
_propJSID($Link) &sha1_hex(lc $uri)
Truth table33%1/3
A and B
A= defined $relB= length $rel
ABresult
0X0
100
111
Truth table66%2/3
A // B
A= _propJSID($Link)B= &sha1_hex(lc $uri)
ABresult
1X1
011
000
1621 _linkTitle($Link, 'label'),
1622 };
1623 }
1624  
1625 # }}}
1626  
1627 # parse CONFERENCE -> virtualLocations {{{
1628  
1629 428 my %VirtualLocations;
1630 428 ▶ foreach my $Conference (@{$VEvent->{properties}{conference} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'conference'} || []
l!l
9419
MC/DC100%1/1
$VEvent->{'properties'}{'conference'} || []
$VEvent->{'properties'}{'conference'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'conference'}
Aresult
11
00
1631 14 ▶ next unless $Conference->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $Conference->{"value"} 0 14 14
1632 14 ▶ my $id = $Conference->{params}{'x-jmap-id'}[0] || sha1_hex($Conference->{value});
Condition66%2/3
$Conference->{'params'}{'x-jmap-id'}[0] || &sha1_hex($Conference->{'value'})
l!l&&r!l&&!r
1220
MC/DC0%0/2
$Conference->{'params'}{'x-jmap-id'}[0] || &sha1_hex($Conference->{'value'})
$Conference->{'params'}{'x-jmap-id'}[0] &sha1_hex($Conference->{'value'})
Truth table66%2/3
A || B
A= $Conference->{'params'}{'x-jmap-id'}[0]B= &sha1_hex($Conference->{'value'})
ABresult
1X1
011
000
1633 14 my %vloc = ('@type' => 'VirtualLocation', uri => $Conference->{value});
1634 14 ▶ if ($Conference->{params}{label}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Conference->{"params"}{"label"}) 12 2 14
1635 12 $vloc{name} = $Conference->{params}{label}[0];
1636 }
1637 14 ▶ if ($Conference->{params}{feature}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Conference->{"params"}{"feature"}) 12 2 14
1638 12 my @features = map { lc $_ } map { split /,/ } @{$Conference->{params}{feature}};
1639 12 $vloc{features} = { map { $_ => $JSON::true } @features };
1640 }
1641 14 $VirtualLocations{$id} = \%vloc;
1642 }
1643  
1644 # }}}
1645  
1646 # Parse keywords {{{
1647  
1648 428 my %keywords;
1649 428 ▶ foreach my $Categories (@{$VEvent->{properties}{categories} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'categories'} || []
l!l
7421
MC/DC100%1/1
$VEvent->{'properties'}{'categories'} || []
$VEvent->{'properties'}{'categories'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'categories'}
Aresult
11
00
1650 10 my $val = $Categories->{value};
1651 10 $keywords{$_} = $JSON::true for split ',', $val;
1652 }
1653 428 delete $keywords{''}; # just in case it was created by leading or trailing ,
1654  
1655 # }}}
1656  
1657 # Parse relations {{{
1658  
1659 428 my %relations;
1660 428 ▶ foreach my $Relation (@{$VEvent->{properties}{'related-to'} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'related-to'} || []
l!l
21407
MC/DC100%1/1
$VEvent->{'properties'}{'related-to'} || []
$VEvent->{'properties'}{'related-to'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'related-to'}
Aresult
11
00
1661 38 ▶ my $reltype = $Relation->{params}{reltype}[0] || 'parent';
Condition100%2/2
$Relation->{'params'}{'reltype'}[0] || 'parent'
l!l
1721
MC/DC100%1/1
$Relation->{'params'}{'reltype'}[0] || 'parent'
$Relation->{'params'}{'reltype'}[0]
Truth table100%2/2
A
A= $Relation->{'params'}{'reltype'}[0]
Aresult
11
00
1662 38 ▶ $reltype = lc $reltype if grep { $_ eq lc $reltype } qw(first next parent child);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq lc $reltype;} "first", "next", "parent", "child" 34 4 38
1663 38 $relations{$Relation->{value}}{'@type'} = 'Relation';
1664 38 $relations{$Relation->{value}}{relation}{$reltype} = $JSON::true;
1665 }
1666  
1667 # }}}
1668  
1669 428 my %Event = ();
1670  
1671 # ==============================================================
1672 # 4.1 Metadata
1673  
1674 # 4.1.1 @type (JSCalendar bis uses capitalized names)
1675 428 ▶ $Event{'@type'} = $is_task ? 'Task' : 'Event';
Branch: 1 branch
BranchTrueFalseTotal
$is_task ? : 12 416 428
1676  
1677 # 4.1.2 uid
1678 428 $Event{uid} = "$uid";
1679  
1680 # 4.1.3 relatedTo
1681 428 ▶ $Event{relatedTo} = \%relations if %relations;
Branch: 1 branch
BranchTrueFalseTotal
if %relations 21 407 428
1682  
1683 # 4.1.4 prodId
1684 428 ▶ $Event{prodId} = $prodid if defined $prodid;
Branch: 1 branch
BranchTrueFalseTotal
if defined $prodid 427 1 428
1685  
1686 # 4.1.5 created
1687 428 ▶ if ($Properties{created}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"created"}{"value"}) 111 317 428
1688 # UTC item
1689 111 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{created}, 'UTC') };
1690 111 ▶ $Event{created} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 111 0 111
1691 }
1692  
1693 # 4.1.6 updated
1694 428 ▶ if ($Properties{dtstamp}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"dtstamp"}{"value"}) 427 1 428
1695 # UTC item
1696 427 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{dtstamp}, 'UTC') };
1697 427 ▶ $Event{updated} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 427 0 427
1698 }
1699 428 ▶ if (not $Event{updated} and $Properties{'last-modified'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $Event{"updated"} and $Properties{"last-modified"}{"value"}) 0 428 428
Condition66%2/3
not $Event{"updated"} and $Properties{"last-modified"}{"value"}
!ll&&!rl&&r
42710
MC/DC0%0/2
not $Event{"updated"} and $Properties{"last-modified"}{"value"}
not $Event{"updated"} $Properties{"last-modified"}{"value"}
Truth table66%2/3
not(A) and B
A= not $Event{"updated"}B= $Properties{"last-modified"}{"value"}
ABresult
0X0
100
111
1700 # UTC item
1701 0 my $Date = eval { $Self->_getDateObj($Calendar, $Properties{'last-modified'}, 'UTC') };
1702 0 ▶ $Event{updated} = $Date->iso8601() . 'Z' if $Date;
Branch: 1 branch
BranchTrueFalseTotal
if $Date 0 0 0
1703 }
1704 428 ▶ $Event{updated} ||= DateTime->now->iso8601();
Condition66%2/3
$Event{"updated"} ||= "DateTime"->now->iso8601
l!l&&r!l&&!r
42710
MC/DC0%0/2
$Event{"updated"} ||= "DateTime"->now->iso8601
$Event{"updated"} "DateTime"->now->iso8601
Truth table66%2/3
A ||= B
A= $Event{"updated"}B= "DateTime"->now->iso8601
ABresult
1X1
011
000
1705  
1706 # 4.1.7 sequence
1707 # (a value that is not an integer is ignored; it used to die, when
1708 # the module made every warning fatal)
1709 428 my $sequence = _intValue($Properties{sequence}{value});
1710 428 ▶ $Event{sequence} = $sequence if defined $sequence;
Branch: 1 branch
BranchTrueFalseTotal
if defined $sequence 273 155 428
1711  
1712 # 4.1.8 method
1713 428 ▶ $Event{method} = $method if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 2 426 428
1714  
1715 # ==============================================================
1716 # 4.2 What and where
1717  
1718 # 4.2.1 title
1719 $Event{title} = $Properties{summary}{value}
1720 428 ▶ if ($Properties{summary} and defined $Properties{summary}{value});
Branch: 1 branch
BranchTrueFalseTotal
if $Properties{"summary"} and defined $Properties{"summary"}{"value"} 234 194 428
Condition66%2/3
$Properties{"summary"} and defined $Properties{"summary"}{"value"}
!ll&&!rl&&r
0194234
MC/DC50%1/2
$Properties{"summary"} and defined $Properties{"summary"}{"value"}
$Properties{"summary"} defined $Properties{"summary"}{"value"}
Truth table66%2/3
A and B
A= $Properties{"summary"}B= defined $Properties{"summary"}{"value"}
ABresult
0X0
100
111
1721  
1722 # 4.2.2 description
1723 # STYLED-DESCRIPTION overrides DESCRIPTION if present
1724 428 ▶ if ($Properties{'styled-description'}{value}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Properties{'styled-description'}{'value'}) { } 3 425 428
elsif (@description) { } 88 337 425
1725 3 $Event{description} = $Properties{'styled-description'}{value};
1726 3 ▶ $Event{descriptionContentType} = $Properties{'styled-description'}{params}{fmttype}[0] // 'text/html';
Condition50%1/2
$Properties{"styled-description"}{"params"}{"fmttype"}[0] // "text/html"
l!l
30
MC/DC0%0/1
$Properties{"styled-description"}{"params"}{"fmttype"}[0] // "text/html"
$Properties{"styled-description"}{"params"}{"fmttype"}[0]
Truth table50%1/2
A
A= $Properties{"styled-description"}{"params"}{"fmttype"}[0]
Aresult
11
00
1727 }
1728 elsif (@description) {
1729 88 $Event{description} = join("\n", @description);
1730 }
1731  
1732 # 4.2.4 locations
1733 428 ▶ if ($Properties{location}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"location"}{"value"}) 34 394 428
1734 34 $Event{locations}{location} = { '@type' => 'Location', name => $Properties{location}{value} };
1735 }
1736 # X-APPLE-STRUCTURED-LOCATION -> location with coordinates, name, description
1737 # Check for Apple structured locations first; if present, skip plain GEO
1738 428 ▶ my $has_apple_location = scalar @{$VEvent->{properties}{'x-apple-structured-location'} || []};
Condition100%2/2
$VEvent->{'properties'}{'x-apple-structured-location'} || []
l!l
5423
MC/DC100%1/1
$VEvent->{'properties'}{'x-apple-structured-location'} || []
$VEvent->{'properties'}{'x-apple-structured-location'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'x-apple-structured-location'}
Aresult
11
00
1739  
1740 # GEO -> separate location with coordinates (only if no Apple structured location)
1741 428 ▶ if (!$has_apple_location && $Properties{geo}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $has_apple_location and $Properties{"geo"}{"value"}) 9 419 428
Condition100%3/3
not $has_apple_location and $Properties{"geo"}{"value"}
!ll&&!rl&&r
54149
MC/DC100%2/2
not $has_apple_location and $Properties{"geo"}{"value"}
not $has_apple_location $Properties{"geo"}{"value"}
Truth table100%3/3
not(A) and B
A= not $has_apple_locationB= $Properties{"geo"}{"value"}
ABresult
0X0
100
111
1742 9 my ($lat, $lon) = split /;/, $Properties{geo}{value};
1743 9 ▶ if (defined $lat && defined $lon) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $lat and defined $lon) 9 0 9
Condition33%1/3
defined $lat and defined $lon
!ll&&!rl&&r
009
MC/DC0%0/2
defined $lat and defined $lon
defined $lat defined $lon
Truth table33%1/3
A and B
A= defined $latB= defined $lon
ABresult
0X0
100
111
1744 9 my $coords = "geo:$lat,$lon";
1745 9 ▶ my $locid = $Event{locations} ? 'geo' : 'location';
Branch: 1 branch
BranchTrueFalseTotal
$Event{'locations'} ? : 2 7 9
1746 9 $Event{locations}{$locid} = { '@type' => 'Location', coordinates => $coords };
1747 }
1748 }
1749  
1750 428 ▶ for my $ASL (@{$VEvent->{properties}{'x-apple-structured-location'} || []}) {
Condition100%2/2
$VEvent->{'properties'}{'x-apple-structured-location'} || []
l!l
5423
MC/DC100%1/1
$VEvent->{'properties'}{'x-apple-structured-location'} || []
$VEvent->{'properties'}{'x-apple-structured-location'}
Truth table100%2/2
A
A= $VEvent->{'properties'}{'x-apple-structured-location'}
Aresult
11
00
1751 5 ▶ next unless $ASL->{value};
Branch: 1 branch
BranchTrueFalseTotal
unless $ASL->{"value"} 0 5 5
1752 5 my %loc = ('@type' => 'Location');
1753 5 ▶ if ($ASL->{value} =~ m{^geo:([-\d.]+),([-\d.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ASL->{"value"} =~ /^geo:([-\d.]+),([-\d.]+)/) 5 0 5
1754 5 $loc{coordinates} = $ASL->{value};
1755 }
1756 5 my $title = $ASL->{params}{'x-title'}[0];
1757 5 ▶ $loc{name} = $title if defined $title && $title ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $title and $title ne "" 5 0 5
Condition33%1/3
defined $title and $title ne ""
!ll&&!rl&&r
005
MC/DC0%0/2
defined $title and $title ne ""
defined $title $title ne ""
Truth table33%1/3
A and B
A= defined $titleB= $title ne ""
ABresult
0X0
100
111
1758 5 my $address = $ASL->{params}{'x-address'}[0];
1759 5 ▶ $loc{description} = $address if defined $address && $address ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $address and $address ne "" 0 5 5
Condition33%1/3
defined $address and $address ne ""
!ll&&!rl&&r
500
MC/DC0%0/2
defined $address and $address ne ""
defined $address $address ne ""
Truth table33%1/3
A and B
A= defined $addressB= $address ne ""
ABresult
0X0
100
111
1760 5 ▶ if (keys %loc > 1) { # more than just @type
Branch: 1 branch
BranchTrueFalseTotal
if (keys %loc > 1) 5 0 5
1761 5 ▶ my $locid = sha1_hex($ASL->{value} || 'apple-location');
Condition50%1/2
$ASL->{'value'} || 'apple-location'
l!l
50
MC/DC0%0/1
$ASL->{'value'} || 'apple-location'
$ASL->{'value'}
Truth table50%1/2
A
A= $ASL->{'value'}
Aresult
11
00
1762 5 $Event{locations}{$locid} = \%loc;
1763 }
1764 }
1765  
1766 # 4.2.5 virtualLocations
1767 428 ▶ $Event{virtualLocations} = \%VirtualLocations if %VirtualLocations;
Branch: 1 branch
BranchTrueFalseTotal
if %VirtualLocations 9 419 428
1768  
1769 # 4.2.6 links
1770 428 ▶ $Event{links} = \%Links if %Links;
Branch: 1 branch
BranchTrueFalseTotal
if %Links 22 406 428
1771  
1772 # 4.2.7 locale
1773 428 my $language;
1774 428 ▶ if ($Properties{description} and $Properties{description}{params}{language}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"description"} and $Properties{"description"}{"params"}{"language"}) 23 405 428
Condition66%2/3
$Properties{"description"} and $Properties{"description"}{"params"}{"language"}
!ll&&!rl&&r
040523
MC/DC50%1/2
$Properties{"description"} and $Properties{"description"}{"params"}{"language"}
$Properties{"description"} $Properties{"description"}{"params"}{"language"}
Truth table66%2/3
A and B
A= $Properties{"description"}B= $Properties{"description"}{"params"}{"language"}
ABresult
0X0
100
111
1775 23 $language = $Properties{description}{params}{language}[0];
1776 }
1777 428 ▶ if ($Properties{summary} and $Properties{summary}{params}{language}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}) 47 381 428
Condition66%2/3
$Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}
!ll&&!rl&&r
038147
MC/DC50%1/2
$Properties{"summary"} and $Properties{"summary"}{"params"}{"language"}
$Properties{"summary"} $Properties{"summary"}{"params"}{"language"}
Truth table66%2/3
A and B
A= $Properties{"summary"}B= $Properties{"summary"}{"params"}{"language"}
ABresult
0X0
100
111
1778 47 $language = $Properties{summary}{params}{language}[0];
1779 }
1780 428 ▶ $Event{locale} = $language if $language;
Branch: 1 branch
BranchTrueFalseTotal
if $language 47 381 428
1781  
1782 # 4.2.8 keywords
1783 428 ▶ $Event{keywords} = \%keywords if %keywords;
Branch: 1 branch
BranchTrueFalseTotal
if %keywords 7 421 428
1784  
1785 # 4.2.9 categories is not supported
1786  
1787 # 4.2.10 color
1788 # (one the module cannot read is dropped: it used to die, taking the
1789 # whole calendar with it)
1790 428 ▶ if ($Properties{color}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"color"}) 14 414 428
1791 14 my $color = eval { _fixColor($Properties{color}{value}) };
1792 14 ▶ $Event{color} = $color if defined $color;
Branch: 1 branch
BranchTrueFalseTotal
if defined $color 12 2 14
1793 }
1794  
1795 # ==============================================================
1796 # 4.3 Recurrence properties
1797  
1798 # 4.3.1 recurrenceRule (a singular object since jscalendarbis-15)
1799 428 ▶ if (%Recurrence) {
Branch: 1 branch
BranchTrueFalseTotal
if (%Recurrence) 58 370 428
1800 58 $Recurrence{'@type'} = 'RecurrenceRule';
1801 58 $Event{recurrenceRule} = \%Recurrence;
1802 }
1803  
1804 # 4.3.2 recurrenceOverrides
1805 428 ▶ $Event{recurrenceOverrides} = \%Overrides if %Overrides;
Branch: 1 branch
BranchTrueFalseTotal
if %Overrides 23 405 428
1806  
1807 # ... special case for recurrence overrides when processing the child ...
1808 428 ▶ if ($Properties{'recurrence-id'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"recurrence-id"}{"value"}) 55 373 428
1809 # in our system it's always in the timezone of the event, but iCloud
1810 # returns it in UTC despite the event having a timezone. Super weird.
1811 # Anyway, we need to format it to the StartTimeZone of the parent
1812 # event if there is one, and we don't have that yet!
1813 55 $Event{_recurrenceObj} = $Self->_getDateObj($Calendar, $Properties{'recurrence-id'});
1814 }
1815  
1816 # ==============================================================
1817 # 4.4 Sharing and scheduling properties
1818  
1819 # 4.4.1 priority
1820 # default is 0, so a truth test is sufficient
1821 428 ▶ if (my $priority = _intValue($Properties{priority}{value})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $priority = _intValue($Properties{"priority"}{"value"})) 9 419 428
1822 9 $Event{priority} = $priority;
1823 }
1824  
1825 # 4.4.2 freeBusyStatus
1826 428 ▶ if ($Properties{transp}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"transp"}{"value"}) 288 140 428
1827 288 ▶ $Event{freeBusyStatus} = 'free' if lc($Properties{transp}{value}) eq 'transparent';
Branch: 1 branch
BranchTrueFalseTotal
if lc $Properties{"transp"}{"value"} eq "transparent" 103 185 288
1828 }
1829  
1830 # 4.4.3 privacy (from CLASS property)
1831 428 ▶ if ($Properties{class}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"class"}{"value"}) 12 416 428
1832 12 my $cls = lc($Properties{class}{value});
1833 12 ▶ if ($cls eq 'confidential') { $Event{privacy} = 'secret' }
Branch: 2 branches
BranchTrueFalseTotal
if ($cls eq 'confidential') { } 2 10 12
elsif ($cls ne 'public') { } 9 1 10
1834 # jscalendar-icalendar-29 2.3.7: any other value MUST be private
1835 9 elsif ($cls ne 'public') { $Event{privacy} = 'private' }
1836 }
1837  
1838 # 4.4.4 organizerCalendarAddress
1839 428 foreach my $partid (sort keys %Participants) { # later wins
1840 160 ▶ next unless $Participants{$partid}{roles}{owner};
Branch: 1 branch
BranchTrueFalseTotal
unless $Participants{$partid}{"roles"}{"owner"} 87 73 160
1841 73 $Event{organizerCalendarAddress} = $Participants{$partid}{calendarAddress};
1842 }
1843  
1844 # sentBy (jscalendarbis-22 3.4.5): the ORGANIZER's SENT-BY
1845 # (jscalendar-icalendar-29 2.3.29), which needs an organizer
1846 428 ▶ if ($Event{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Event{"organizerCalendarAddress"}) 67 361 428
1847 67 ▶ for my $VOrganizer (@{$VEvent->{properties}{organizer} || []}) {
Condition50%1/2
$VEvent->{'properties'}{'organizer'} || []
l!l
670
MC/DC0%0/1
$VEvent->{'properties'}{'organizer'} || []
$VEvent->{'properties'}{'organizer'}
Truth table50%1/2
A
A= $VEvent->{'properties'}{'organizer'}
Aresult
11
00
1848 67 ▶ my $SentBy = _sentByAddress($VOrganizer) // next;
Condition100%2/2
_sentByAddress($VOrganizer) // (next)
l!l
265
MC/DC100%1/1
_sentByAddress($VOrganizer) // (next)
_sentByAddress($VOrganizer)
Truth table100%2/2
A
A= _sentByAddress($VOrganizer)
Aresult
11
00
1849 2 $Event{sentBy} = $SentBy;
1850 2 last;
1851 }
1852 }
1853  
1854 # 4.4.5 participants
1855 428 ▶ $Event{participants} = \%Participants if %Participants;
Branch: 1 branch
BranchTrueFalseTotal
if %Participants 78 350 428
1856  
1857 # ==============================================================
1858 # 4.5 Alerts
1859  
1860 # 4.5.1 alerts
1861 428 ▶ $Event{alerts} = \%Alerts if %Alerts;
Branch: 1 branch
BranchTrueFalseTotal
if %Alerts 61 367 428
1862  
1863 # version (jscalendarbis)
1864 428 $Event{version} = '2.0';
1865  
1866 # 4.6.1 localisations is not supported
1867  
1868 # ==============================================================
1869 # 5.1 JSEvent specific properties
1870  
1871 # 5.1.1 start
1872 428 ▶ $Event{start} = $Start->iso8601() if ref($Start);
Branch: 1 branch
BranchTrueFalseTotal
if ref $Start 428 0 428
1873  
1874 # 5.1.2 timeZone: not set for a DATE or a floating time (it can no
1875 # longer be null, jscalendarbis-22 3.6.1, jscalendar-icalendar-29 2.1.5)
1876 428 ▶ $Event{timeZone} = $StartTimeZone if not $IsAllDay and defined $StartTimeZone and length $StartTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
if not $IsAllDay and defined $StartTimeZone and length $StartTimeZone 396 32 428
Condition83%5/6
not $IsAllDay and defined $StartTimeZone and length $StartTimeZone
!ll&&!rl&&r
320396
not $IsAllDay and defined $StartTimeZone
!ll&&!rl&&r
248396
MC/DC66%2/3
not $IsAllDay and defined $StartTimeZone and length $StartTimeZone
not $IsAllDay defined $StartTimeZone length $StartTimeZone
Truth table75%3/4
not(A) and B and C
A= not $IsAllDayB= defined $StartTimeZoneC= length $StartTimeZone
ABCresult
0XX0
10X0
1100
1111
1877  
1878 # endTimeZone (jscalendarbis): set if end timezone differs from start
1879 428 ▶ if (!$IsAllDay && $EndTimeZone && $StartTimeZone && $EndTimeZone ne $StartTimeZone) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone) 7 421 428
Condition88%8/9
not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone
!ll&&!rl&&r
323897
not $IsAllDay and $EndTimeZone and $StartTimeZone
!ll&&!rl&&r
320396
not $IsAllDay and $EndTimeZone
!ll&&!rl&&r
248396
MC/DC75%3/4
not $IsAllDay and $EndTimeZone and $StartTimeZone and $EndTimeZone ne $StartTimeZone
not $IsAllDay $EndTimeZone $StartTimeZone $EndTimeZone ne $StartTimeZone
Truth table80%4/5
not(A) and B and C and D
A= not $IsAllDayB= $EndTimeZoneC= $StartTimeZoneD= $EndTimeZone ne $StartTimeZone
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1880 7 $Event{endTimeZone} = $EndTimeZone;
1881 }
1882  
1883 # 5.1.3 duration
1884 428 my $duration = $Self->_make_duration($End->subtract_datetime($Start), $IsAllDay);
1885 428 ▶ $Event{duration} = $duration if $duration;
Branch: 1 branch
BranchTrueFalseTotal
if $duration 428 0 428
1886  
1887 # 5.1.4 showWithoutTime (RFC 8984)
1888 428 ▶ $Event{showWithoutTime} = $IsAllDay ? $JSON::true : $JSON::false;
Branch: 1 branch
BranchTrueFalseTotal
$IsAllDay ? : 24 404 428
1889 # SHOW-WITHOUT-TIME property (for DATE-TIME events shown as all-day)
1890 428 ▶ if (!$IsAllDay && $Properties{'show-without-time'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $IsAllDay and $Properties{"show-without-time"}{"value"}) 5 423 428
Condition100%3/3
not $IsAllDay and $Properties{"show-without-time"}{"value"}
!ll&&!rl&&r
243995
MC/DC100%2/2
not $IsAllDay and $Properties{"show-without-time"}{"value"}
not $IsAllDay $Properties{"show-without-time"}{"value"}
Truth table100%3/3
not(A) and B
A= not $IsAllDayB= $Properties{"show-without-time"}{"value"}
ABresult
0X0
100
111
1891 5 my $swt = lc($Properties{'show-without-time'}{value});
1892 5 ▶ $Event{showWithoutTime} = $JSON::true if $swt eq 'true' || $swt eq 'yes';
Branch: 1 branch
BranchTrueFalseTotal
if $swt eq "true" or $swt eq "yes" 5 0 5
Condition33%1/3
$swt eq "true" or $swt eq "yes"
l!l&&r!l&&!r
500
MC/DC0%0/2
$swt eq "true" or $swt eq "yes"
$swt eq "true" $swt eq "yes"
Truth table33%1/3
A or B
A= $swt eq "true"B= $swt eq "yes"
ABresult
1X1
011
000
1893 }
1894  
1895 # 5.1.5 status
1896 428 ▶ if ($Properties{status}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"status"}{"value"}) 12 416 428
1897 12 ▶ $Event{status} = lc($Properties{status}{value}) if lc($Properties{status}{value}) ne 'confirmed';
Branch: 1 branch
BranchTrueFalseTotal
if lc $Properties{"status"}{"value"} ne "confirmed" 12 0 12
1898 }
1899  
1900 # Task-specific properties (VTODO)
1901 428 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) 12 416 428
1902 12 ▶ if ($Properties{due}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"due"}{"value"}) 8 4 12
1903 8 my ($Due, $DueTz) = $Self->_getDateObj($Calendar, $Properties{due});
1904 8 $Event{due} = $Due->iso8601();
1905 }
1906 12 my $percent = _intValue($Properties{'percent-complete'}{value});
1907 12 ▶ $Event{percentComplete} = $percent if defined $percent;
Branch: 1 branch
BranchTrueFalseTotal
if defined $percent 5 7 12
1908 12 ▶ if ($Properties{'estimated-duration'}{value}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Properties{"estimated-duration"}{"value"}) 1 11 12
1909 1 $Event{estimatedDuration} = uc $Properties{'estimated-duration'}{value};
1910 }
1911 12 ▶ if ($Properties{completed}{value}) {
Branch: 3 branches
BranchTrueFalseTotal
if ($Properties{'completed'}{'value'}) { } 1 11 12
elsif (lc($Properties{'status'}{'value'} || '') eq 'in-process') { } 4 7 11
elsif (lc($Properties{'status'}{'value'} || '') eq 'cancelled') { } 0 7 7
1912 1 $Event{progress} = 'completed';
1913 }
1914 ▶ elsif (lc($Properties{status}{value} || '') eq 'in-process') {
Condition100%2/2
$Properties{'status'}{'value'} || ''
l!l
47
MC/DC100%1/1
$Properties{'status'}{'value'} || ''
$Properties{'status'}{'value'}
Truth table100%2/2
A
A= $Properties{'status'}{'value'}
Aresult
11
00
1915 4 $Event{progress} = 'in-process';
1916 }
1917 ▶ elsif (lc($Properties{status}{value} || '') eq 'cancelled') {
Condition50%1/2
$Properties{'status'}{'value'} || ''
l!l
07
MC/DC0%0/1
$Properties{'status'}{'value'} || ''
$Properties{'status'}{'value'}
Truth table50%1/2
A
A= $Properties{'status'}{'value'}
Aresult
11
00
1918 0 $Event{progress} = 'cancelled';
1919 }
1920 }
1921  
1922 428 return \%Event;
1923 }
1924  
1925 # jscalendar-icalendar-29 3.2: DTSTART, DUE and RECURRENCE-ID are DATE
1926 # only if showWithoutTime is true, there is no timeZone, and no time of
1927 # day appears anywhere: start, due, the durations, until and the override
1928 # keys. Otherwise an event shown without time keeps its time and zone and
1929 # says so with SHOW-WITHOUT-TIME.
1930 310 ▶sub _writesAsDate {
Subroutine _writesAsDate: called CC=16 SCAR=28.3
1931 310 my $Args = shift;
1932 310 ▶ return 0 unless $Args->{showWithoutTime};
Branch: 1 branch
BranchTrueFalseTotal
unless $Args->{"showWithoutTime"} 282 28 310
1933 28 ▶ return 0 if defined $Args->{timeZone} && length $Args->{timeZone};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Args->{"timeZone"} and length $Args->{"timeZone"} 7 21 28
Condition66%2/3
defined $Args->{"timeZone"} and length $Args->{"timeZone"}
!ll&&!rl&&r
2107
MC/DC50%1/2
defined $Args->{"timeZone"} and length $Args->{"timeZone"}
defined $Args->{"timeZone"} length $Args->{"timeZone"}
Truth table66%2/3
A and B
A= defined $Args->{"timeZone"}B= length $Args->{"timeZone"}
ABresult
0X0
100
111
1934 21 ▶ my $midnight = sub { !defined $_[0] || $_[0] !~ /T/ || $_[0] =~ /T00:00(?::00(?:\.0+)?)?\z/ };
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] && $_[0] =~ /T/ or $_[0] =~ /T00:00(?::00(?:\.0+)?)?\z/ 56 39 95
Condition66%2/3
defined $_[0] && $_[0] =~ /T/
!ll&&!rl&&r
56039
MC/DC50%1/2
defined $_[0] && $_[0] =~ /T/
defined $_[0] $_[0] =~ /T/
Truth table66%2/3
A && B
A= defined $_[0]B= $_[0] =~ /T/
ABresult
0X0
100
111
1935 21 ▶ my $whole_days = sub { !defined $_[0] || $_[0] !~ /T/ || $_[0] =~ /T(?:0+[HMS])*\z/ };
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
not defined $_[0] && $_[0] =~ /T/ or $_[0] =~ /T(?:0+[HMS])*\z/ 38 2 40
Condition100%3/3
defined $_[0] && $_[0] =~ /T/
!ll&&!rl&&r
20182
MC/DC100%2/2
defined $_[0] && $_[0] =~ /T/
defined $_[0] $_[0] =~ /T/
Truth table100%3/3
A && B
A= defined $_[0]B= $_[0] =~ /T/
ABresult
0X0
100
111
1936 my $rule = ref $Args->{recurrenceRule} eq 'HASH' ? $Args->{recurrenceRule}
1937 21 ▶ : ref $Args->{recurrenceRules} eq 'ARRAY' ? $Args->{recurrenceRules}[0] : undef;
Branch: 2 branches
BranchTrueFalseTotal
ref $Args->{'recurrenceRule'} eq 'HASH' ? : 10 11 21
ref $Args->{'recurrenceRules'} eq 'ARRAY' ? : 0 11 11
1938 return 0 unless $midnight->($Args->{start}) && $midnight->($Args->{due})
1939 && $midnight->($Args->{recurrenceId}) && $midnight->($rule ? $rule->{until} : undef)
1940 21 ▶ && $whole_days->($Args->{duration}) && $whole_days->($Args->{estimatedDuration});
Branch: 2 branches
BranchTrueFalseTotal
unless &$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"}) 1 20 21
$rule ? : 10 10 20
Condition66%10/15
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef)
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"})
!ll&&!rl&&r
1020
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"})
!ll&&!rl&&r
1020
MC/DC16%1/6
&$midnight($Args->{"start"}) and &$midnight($Args->{"due"}) and &$midnight($Args->{"recurrenceId"}) and &$midnight($rule ? $rule->{"until"} : undef) and &$whole_days($Args->{"duration"}) and &$whole_days($Args->{"estimatedDuration"})
&$midnight($Args->{"start"}) &$midnight($Args->{"due"}) &$midnight($Args->{"recurrenceId"}) &$midnight($rule ? $rule->{"until"} : undef) &$whole_days($Args->{"duration"}) &$whole_days($Args->{"estimatedDuration"})
Truth table28%2/7
A and B and C and D and E and F
A= &$midnight($Args->{"start"})B= &$midnight($Args->{"due"})C= &$midnight($Args->{"recurrenceId"})D= &$midnight($rule ? $rule->{"until"} : undef)E= &$whole_days($Args->{"duration"})F= &$whole_days($Args->{"estimatedDuration"})
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
1941 20 ▶ for my $key (keys %{ ref $Args->{recurrenceOverrides} eq 'HASH' ? $Args->{recurrenceOverrides} : {} }) {
Branch: 1 branch
BranchTrueFalseTotal
ref $Args->{'recurrenceOverrides'} eq 'HASH' ? : 6 14 20
1942 14 ▶ return 0 unless $midnight->($key);
Branch: 1 branch
BranchTrueFalseTotal
unless &$midnight($key) 0 14 14
1943 }
1944 20 return 1;
1945 }
1946  
1947 1381 ▶sub _getTimeZone {
Subroutine _getTimeZone: called CC=17 SCAR=28.8
1948 1381 my $Self = shift;
1949 1381 my ($Calendar, $Element) = @_;
1950  
1951 1381 ▶ if ($Element->{value} =~ m/Z$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Element->{"value"} =~ /Z$/) 914 467 1381
1952 914 return 'Etc/UTC';
1953 }
1954  
1955 467 my $TZID = $Element->{params}{tzid}[0];
1956  
1957 467 ▶ return undef unless $TZID;
Branch: 1 branch
BranchTrueFalseTotal
unless $TZID 67 400 467
1958  
1959 400 ▶ return $Self->{_tznamemap}{$TZID} if exists $Self->{_tznamemap}{$TZID};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Self->{"_tznamemap"}{$TZID} 247 153 400
1960  
1961 153 my %TzOffsets;
1962  
1963 153 ▶ foreach my $VTimeZone (@{$Calendar->{objects} || []}) {
Condition50%1/2
$Calendar->{'objects'} || []
l!l
1530
MC/DC0%0/1
$Calendar->{'objects'} || []
$Calendar->{'objects'}
Truth table50%1/2
A
A= $Calendar->{'objects'}
Aresult
11
00
1964 307 ▶ next unless lc $VTimeZone->{type} eq 'vtimezone';
Branch: 1 branch
BranchTrueFalseTotal
unless lc $VTimeZone->{"type"} eq "vtimezone" 190 117 307
1965 117 ▶ next unless ($VTimeZone->{properties}{tzid}[0]{value} || '') eq $TZID;
Branch: 1 branch
BranchTrueFalseTotal
unless ($VTimeZone->{"properties"}{"tzid"}[0]{"value"} || "") eq $TZID 8 109 117
Condition50%1/2
$VTimeZone->{'properties'}{'tzid'}[0]{'value'} || ''
l!l
1170
MC/DC0%0/1
$VTimeZone->{'properties'}{'tzid'}[0]{'value'} || ''
$VTimeZone->{'properties'}{'tzid'}[0]{'value'}
Truth table50%1/2
A
A= $VTimeZone->{'properties'}{'tzid'}[0]{'value'}
Aresult
11
00
1966  
1967 109 ▶ foreach my $Observance (@{$VTimeZone->{objects} || []}) {
Condition50%1/2
$VTimeZone->{'objects'} || []
l!l
1090
MC/DC0%0/1
$VTimeZone->{'objects'} || []
$VTimeZone->{'objects'}
Truth table50%1/2
A
A= $VTimeZone->{'objects'}
Aresult
11
00
1968 217 ▶ next unless grep { (lc $Observance->{type} || '') eq $_ } qw{standard daylight};
Branch: 1 branch
BranchTrueFalseTotal
unless grep {(lc $Observance->{"type"} || "") eq $_;} "standard", "daylight" 0 217 217
Condition50%1/2
lc $Observance->{'type'} || ''
l!l
4340
MC/DC0%0/1
lc $Observance->{'type'} || ''
lc $Observance->{'type'}
Truth table50%1/2
A
A= lc $Observance->{'type'}
Aresult
11
00
1969 217 ▶ next unless defined $Observance->{properties}{tzoffsetto}[0]{value};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Observance->{"properties"}{"tzoffsetto"}[0]{"value"} 0 217 217
1970  
1971 $TzOffsets{lc $Observance->{type}}
1972 217 = $Observance->{properties}{tzoffsetto}[0]{value};
1973 }
1974 }
1975  
1976 my $TimeZone = Text::JSCalendar::TimeZones->GetTimeZone(
1977 TZID => $TZID,
1978 Time => $Element->{value},
1979 (exists $TzOffsets{standard}
1980 ? (StandardTzOffsetTo => $TzOffsets{standard})
1981 : ()),
1982 (exists $TzOffsets{daylight}
1983 ? (DaylightTzOffsetTo => $TzOffsets{daylight})
1984 153 ▶ : ()),
Branch: 2 branches
BranchTrueFalseTotal
exists $TzOffsets{'standard'} ? : 109 44 153
exists $TzOffsets{'daylight'} ? : 108 45 153
Condition50%1/2
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ()) || undef
l!l
1530
MC/DC0%0/1
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ()) || undef
'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ())
Truth table50%1/2
A
A= 'Text::JSCalendar::TimeZones'->GetTimeZone('TZID', $TZID, 'Time', $Element->{'value'}, exists $TzOffsets{'standard'} ? ('StandardTzOffsetTo', $TzOffsets{'standard'}) : (), exists $TzOffsets{'daylight'} ? ('DaylightTzOffsetTo', $TzOffsets{'daylight'}) : ())
Aresult
11
00
1985 ) || undef;
1986  
1987 153 $Self->{_tznamemap}{$TZID} = $TimeZone;
1988 153 return $TimeZone;
1989 }
1990  
1991 692 ▶sub _wireDate {
Subroutine _wireDate: called CC=6 SCAR=18.2
1992 # format: YYYY-MM-DDTHH:MM:SS Z?
1993 692 my $isoDate = shift;
1994 692 ▶ my $timeZone = shift || $FLOATING;
Condition66%2/3
shift() || $Text::JSCalendar::FLOATING
l!l&&r!l&&!r
656360
MC/DC0%0/2
shift() || $Text::JSCalendar::FLOATING
shift() $Text::JSCalendar::FLOATING
Truth table66%2/3
A || B
A= shift()B= $Text::JSCalendar::FLOATING
ABresult
1X1
011
000
1995 692 ▶ confess "Invalid value (undefined) was not ISO8601" unless defined $isoDate;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $isoDate 1 691 692
1996 691 ▶ confess "Invalid value '$isoDate' was not ISO8601" unless $isoDate =~ m/^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(Z?)$/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $isoDate =~ /^(\d{4,})-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)(Z?)$/i 0 691 691
1997 691 ▶ $timeZone = 'Etc/UTC' if $7;
Branch: 1 branch
BranchTrueFalseTotal
if $7 326 365 691
1998  
1999 691 ▶ my $Date = DateTime->_new(
Branch: 1 branch
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "hour", $4, "minute", $5, "second", $6, "time_zone", $timeZone, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${isoDate}'") 691 0 691
2000 year => $1,
2001 month => $2,
2002 day => $3,
2003 hour => $4,
2004 minute => $5,
2005 second => $6,
2006 time_zone => $timeZone,
2007 locale => $LOCALE,
2008 ) or confess "Invalid value '$isoDate'";
2009  
2010 691 return $Date;
2011 }
2012  
2013 1411 ▶sub _vDate {
Subroutine _vDate: called CC=6 SCAR=18.0
2014 # format: :YYYYMMDDTHHMMSS (floating)
2015 # format: :YYYYMMDDTHHMMSSZ (UTC)
2016 # format: ;TZID=X/Y:YYMMDDTHHMMSS (zoned)
2017 # format: ;TYPE=DATE:YYYYMMDD (but we don't know about that)
2018 1411 my $vDate = shift;
2019  
2020 1411 ▶ if ($vDate =~ m/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(\.\d+)?(Z?)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vDate =~ /^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)(\.\d+)?(Z?)$/i) 1352 59 1411
2021 1352 ▶ my $Date = DateTime->_new(
Branch: 2 branches
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "hour", $4, "minute", $5, "second", $6, "time_zone", $8 eq "Z" ? $Text::JSCalendar::UTC : $Text::JSCalendar::FLOATING, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${vDate}' for DATETIME") 1352 0 1352
$8 eq 'Z' ? : 939 413 1352
2022 year => $1,
2023 month => $2,
2024 day => $3,
2025 hour => $4,
2026 minute => $5,
2027 second => $6,
2028 # ignore milliseconds in $7
2029 time_zone => ($8 eq 'Z' ? $UTC : $FLOATING),
2030 locale => $LOCALE,
2031 ) or confess "Invalid value '$vDate' for DATETIME";
2032  
2033 1352 return ($Date, 1);
2034 }
2035  
2036 59 ▶ if ($vDate =~ m/^(\d\d\d\d)(\d\d)(\d\d)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($vDate =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) 58 1 59
2037 # all day
2038 58 ▶ my $Date = DateTime->_new(
Branch: 1 branch
BranchTrueFalseTotal
my $Date = "DateTime"->_new("year", $1, "month", $2, "day", $3, "time_zone", $Text::JSCalendar::FLOATING, "locale", $Text::JSCalendar::LOCALE) or confess("Invalid value '${vDate}' for DATE") 58 0 58
2039 year => $1,
2040 month => $2,
2041 day => $3,
2042 time_zone => $FLOATING,
2043 locale => $LOCALE,
2044 ) or confess "Invalid value '$vDate' for DATE";
2045  
2046 58 return ($Date, 0);
2047 }
2048  
2049 # we only support those two patterns
2050 1 confess "Date '$vDate' was neither a DATE or DATETIME value";
2051 }
2052  
2053 354 ▶sub _makeVTime {
Subroutine _makeVTime: called CC=1 SCAR=0.0
2054 354 my $Self = shift;
2055 354 my ($TimeZones, $wire, $tz, $IsAllDay) = @_;
2056  
2057 354 my $date = _wireDate($wire, $tz);
2058  
2059 354 return $Self->_makeVTimeObj($TimeZones, $date, $tz, $IsAllDay);
2060 }
2061  
2062 866 ▶sub _makeVTimeObj {
Subroutine _makeVTimeObj: called CC=4 SCAR=13.9
2063 866 my $Self = shift;
2064 866 my ($TimeZones, $date, $tz, $IsAllDay) = @_;
2065  
2066 # all day?
2067 866 ▶ if ($IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay) 34 832 866
2068 34 return [$date->strftime('%Y%m%d'), { VALUE => 'DATE' }];
2069 }
2070  
2071 # floating?
2072 832 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 25 807 832
2073 25 return [$date->strftime('%Y%m%dT%H%M%S')];
2074 }
2075  
2076 # UTC?
2077 807 ▶ if ($UTCLinks{$tz}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($UTCLinks{$tz}) 559 248 807
2078 559 return [$date->strftime('%Y%m%dT%H%M%SZ')];
2079 }
2080  
2081 248 my $zone = $Self->tz($tz);
2082  
2083 248 $TimeZones->{$zone->name()} = 1;
2084  
2085 248 return [$date->strftime('%Y%m%dT%H%M%S'), { TZID => $zone->name() }];
2086 }
2087  
2088 354 ▶sub _makeZTime {
Subroutine _makeZTime: called CC=1 SCAR=0.0
2089 354 my ($Self, $date) = @_;
2090 354 return $Self->_makeVTime({}, $date, 'UTC');
2091 }
2092  
2093 64 ▶sub _makeLTime {
Subroutine _makeLTime: called CC=4 SCAR=13.9
2094 64 my $Self = shift;
2095 64 my ($TimeZones, $ltime, $tz, $IsAllDay) = @_;
2096  
2097 64 my $date = _wireDate($ltime, $Self->tz($tz));
2098  
2099 64 ▶ return [$date->strftime('%Y%m%d'), { VALUE => 'DATE' }] if $IsAllDay;
Branch: 1 branch
BranchTrueFalseTotal
if $IsAllDay 8 56 64
2100  
2101 56 ▶ unless ($tz) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tz) 3 53 56
2102 # floating
2103 3 return [$date->strftime('%Y%m%dT%H%M%S')];
2104 }
2105  
2106 53 ▶ if ($tz =~ m/UTC/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tz =~ /UTC/i) 8 45 53
2107 8 return [$date->strftime('%Y%m%dT%H%M%SZ')];
2108 }
2109  
2110 # XXX - factor this crap out
2111 45 $TimeZones->{$tz} = 1;
2112  
2113 # XXX - use our cache
2114 45 my $zone = $Self->tz($tz);
2115  
2116 45 return [$date->strftime('%Y%m%dT%H%M%S'), { TZID => $zone->name() }];
2117 }
2118  
2119 270 ▶sub _argsToVEvents {
Subroutine _argsToVEvents: called CC=158 SCAR=51.2
2120 270 my $Self = shift;
2121 270 my ($TimeZones, $Args, $recurrenceData) = @_;
2122 270 my @VEvents;
2123  
2124 270 ▶ my $type = $Args->{'@type'} || '';
Condition50%1/2
$Args->{'@type'} || ''
l!l
2700
MC/DC0%0/1
$Args->{'@type'} || ''
$Args->{'@type'}
Truth table50%1/2
A
A= $Args->{'@type'}
Aresult
11
00
2125 270 my $is_task = $type eq 'Task';
2126 270 my $VEvent;
2127 270 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) { } 9 261 270
2128 9 eval { require Data::ICal::Entry::Todo };
2129 9 $VEvent = Data::ICal::Entry::Todo->new();
2130 } else {
2131 261 $VEvent = Data::ICal::Entry::Event->new();
2132 }
2133  
2134 # required properties
2135 270 my $transp = 'OPAQUE';
2136 270 ▶ if (defined $Args->{freeBusyStatus}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"freeBusyStatus"}) 54 216 270
2137 54 ▶ $transp = 'TRANSPARENT' if $Args->{freeBusyStatus} eq 'free';
Branch: 1 branch
BranchTrueFalseTotal
if $Args->{"freeBusyStatus"} eq "free" 54 0 54
2138 }
2139 $VEvent->add_properties(
2140 uid => $Args->{uid},
2141 270 ▶ sequence => ($Args->{sequence} || 0),
Branch: 1 branch
BranchTrueFalseTotal
$is_task ? : 9 261 270
Condition100%2/2
$Args->{'sequence'} || 0
l!l
38232
MC/DC100%1/1
$Args->{'sequence'} || 0
$Args->{'sequence'}
Truth table100%2/2
A
A= $Args->{'sequence'}
Aresult
11
00
2142 ($is_task ? () : (transp => $transp)),
2143 );
2144  
2145 270 ▶ if ($recurrenceData) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurrenceData) 40 230 270
2146 40 my ($recurrenceId, $TopLevel) = @$recurrenceData;
2147 40 $VEvent->add_property('recurrence-id' => $Self->_makeLTime($TimeZones, $recurrenceId, $TopLevel->{timeZone}, _writesAsDate($TopLevel)));
2148 # (the same DATE-or-not decision as the master's DTSTART, -29 3.2)
2149 }
2150  
2151 # direct copy if properties exist
2152 270 ▶ if (defined $Args->{title} && $Args->{title} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"title"} and $Args->{"title"} ne "") 175 95 270
Condition100%3/3
defined $Args->{"title"} and $Args->{"title"} ne ""
!ll&&!rl&&r
941175
MC/DC100%2/2
defined $Args->{"title"} and $Args->{"title"} ne ""
defined $Args->{"title"} $Args->{"title"} ne ""
Truth table100%3/3
A and B
A= defined $Args->{"title"}B= $Args->{"title"} ne ""
ABresult
0X0
100
111
2153 175 my %lang;
2154 175 ▶ $lang{language} = $Args->{locale} if exists $Args->{locale};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"locale"} 25 150 175
2155 175 $VEvent->add_property(summary => [$Args->{title}, \%lang]);
2156 }
2157 270 ▶ if (defined $Args->{description} && $Args->{description} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"description"} and $Args->{"description"} ne "") 43 227 270
Condition100%3/3
defined $Args->{"description"} and $Args->{"description"} ne ""
!ll&&!rl&&r
220743
MC/DC100%2/2
defined $Args->{"description"} and $Args->{"description"} ne ""
defined $Args->{"description"} $Args->{"description"} ne ""
Truth table100%3/3
A and B
A= defined $Args->{"description"}B= $Args->{"description"} ne ""
ABresult
0X0
100
111
2158 43 my %lang;
2159 43 ▶ $lang{language} = $Args->{locale} if exists $Args->{locale};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"locale"} 24 19 43
2160 43 ▶ if ($Args->{descriptionContentType} && $Args->{descriptionContentType} ne 'text/plain') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{'descriptionContentType'} and $Args->{'descriptionContentType'} ne 'text/plain') { } 3 40 43
Condition66%2/3
$Args->{"descriptionContentType"} and $Args->{"descriptionContentType"} ne "text/plain"
!ll&&!rl&&r
4003
MC/DC50%1/2
$Args->{"descriptionContentType"} and $Args->{"descriptionContentType"} ne "text/plain"
$Args->{"descriptionContentType"} $Args->{"descriptionContentType"} ne "text/plain"
Truth table66%2/3
A and B
A= $Args->{"descriptionContentType"}B= $Args->{"descriptionContentType"} ne "text/plain"
ABresult
0X0
100
111
2161 # STYLED-DESCRIPTION for non-plain content types
2162 3 $VEvent->add_property('styled-description' => [$Args->{description}, { FMTTYPE => $Args->{descriptionContentType}, %lang }]);
2163 }
2164 else {
2165 40 $VEvent->add_property(description => [$Args->{description}, \%lang]);
2166 }
2167 }
2168  
2169 270 ▶ if ($Args->{status} and $Args->{status} ne 'confirmed') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"status"} and $Args->{"status"} ne "confirmed") 6 264 270
Condition66%2/3
$Args->{"status"} and $Args->{"status"} ne "confirmed"
!ll&&!rl&&r
26406
MC/DC50%1/2
$Args->{"status"} and $Args->{"status"} ne "confirmed"
$Args->{"status"} $Args->{"status"} ne "confirmed"
Truth table66%2/3
A and B
A= $Args->{"status"}B= $Args->{"status"} ne "confirmed"
ABresult
0X0
100
111
2170 6 $VEvent->add_property('status', uc($Args->{status}));
2171 }
2172  
2173 # privacy -> CLASS
2174 270 ▶ if ($Args->{privacy} && $Args->{privacy} ne 'public') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"privacy"} and $Args->{"privacy"} ne "public") 5 265 270
Condition66%2/3
$Args->{"privacy"} and $Args->{"privacy"} ne "public"
!ll&&!rl&&r
26505
MC/DC50%1/2
$Args->{"privacy"} and $Args->{"privacy"} ne "public"
$Args->{"privacy"} $Args->{"privacy"} ne "public"
Truth table66%2/3
A and B
A= $Args->{"privacy"}B= $Args->{"privacy"} ne "public"
ABresult
0X0
100
111
2175 5 ▶ my $cls = $Args->{privacy} eq 'secret' ? 'CONFIDENTIAL' : uc($Args->{privacy});
Branch: 1 branch
BranchTrueFalseTotal
$Args->{'privacy'} eq 'secret' ? : 1 4 5
2176 5 $VEvent->add_property('class' => $cls);
2177 }
2178  
2179 # priority
2180 270 ▶ if ($Args->{priority} && $Args->{priority} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"priority"} and $Args->{"priority"} > 0) 12 258 270
Condition66%2/3
$Args->{"priority"} and $Args->{"priority"} > 0
!ll&&!rl&&r
258012
MC/DC50%1/2
$Args->{"priority"} and $Args->{"priority"} > 0
$Args->{"priority"} $Args->{"priority"} > 0
Truth table66%2/3
A and B
A= $Args->{"priority"}B= $Args->{"priority"} > 0
ABresult
0X0
100
111
2181 12 $VEvent->add_property('priority' => $Args->{priority});
2182 }
2183  
2184 # color
2185 # COLOR is a CSS3 color name or a six-digit hex value (icalendar-
2186 # jscalendar-extensions-09 2.2); any other CSS color has no iCalendar form
2187 270 ▶ my $Color = $Args->{color} ? eval { _fixColor($Args->{color}) } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$Args->{'color'} ? : 9 261 270
2188 270 ▶ if (defined $Color) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Color) 8 262 270
2189 8 $VEvent->add_property('color' => $Color);
2190 }
2191  
2192 # dates in UTC - stored in UTC
2193 270 ▶ $VEvent->add_property(created => $Self->_makeZTime($Args->{created})) if $Args->{created};
Branch: 1 branch
BranchTrueFalseTotal
if $Args->{"created"} 58 212 270
2194 270 ▶ $VEvent->add_property(dtstamp => $Self->_makeZTime($Args->{updated} || DateTime->now->iso8601()));
Condition66%2/3
$Args->{'updated'} || 'DateTime'->now->iso8601
l!l&&r!l&&!r
242280
MC/DC0%0/2
$Args->{'updated'} || 'DateTime'->now->iso8601
$Args->{'updated'} 'DateTime'->now->iso8601
Truth table66%2/3
A || B
A= $Args->{'updated'}B= 'DateTime'->now->iso8601
ABresult
1X1
011
000
2195  
2196 # dates in localtime - zones based on location
2197 270 my $EndTimeZone = $Args->{endTimeZone};
2198 270 ▶ my $locations = $Args->{locations} || {};
Condition100%2/2
$Args->{'locations'} || {}
l!l
24246
MC/DC100%1/1
$Args->{'locations'} || {}
$Args->{'locations'}
Truth table100%2/2
A
A= $Args->{'locations'}
Aresult
11
00
2199 270 foreach my $id (sort keys %$locations) {
2200 27 ▶ if ($locations->{$id}{name} && !$locations->{$id}{coordinates}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}) 19 8 27
Condition100%3/3
$locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}
!ll&&!rl&&r
5319
MC/DC100%2/2
$locations->{$id}{"name"} and not $locations->{$id}{"coordinates"}
$locations->{$id}{"name"} not $locations->{$id}{"coordinates"}
Truth table100%3/3
A and not(B)
A= $locations->{$id}{"name"}B= not $locations->{$id}{"coordinates"}
ABresult
0X0
100
111
2201 # Only emit LOCATION if this entry doesn't also have coordinates
2202 # (coordinates with name go into X-APPLE-STRUCTURED-LOCATION with X-TITLE)
2203 19 $VEvent->add_property(location => $locations->{$id}{name});
2204 }
2205 # GEO from coordinates
2206 27 ▶ if ($locations->{$id}{coordinates} && $locations->{$id}{coordinates} =~ m{^geo:([-\d.]+),([-\d.]+)}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/) 8 19 27
Condition66%2/3
$locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
!ll&&!rl&&r
1908
MC/DC50%1/2
$locations->{$id}{"coordinates"} and $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
$locations->{$id}{"coordinates"} $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
Truth table66%2/3
A and B
A= $locations->{$id}{"coordinates"}B= $locations->{$id}{"coordinates"} =~ /^geo:([-\d.]+),([-\d.]+)/
ABresult
0X0
100
111
2207 8 my ($lat, $lon) = ($1, $2);
2208 8 my $has_apple_meta = $locations->{$id}{name};
2209 8 ▶ if ($has_apple_meta) {
Branch: 1 branch
BranchTrueFalseTotal
if ($has_apple_meta) { } 3 5 8
2210 # Emit X-APPLE-STRUCTURED-LOCATION (which implies GEO)
2211 3 my %asl_params = (VALUE => 'URI');
2212 3 ▶ $asl_params{'X-TITLE'} = $locations->{$id}{name} if $locations->{$id}{name};
Branch: 1 branch
BranchTrueFalseTotal
if $locations->{$id}{"name"} 3 0 3
2213 3 $VEvent->add_property('x-apple-structured-location' => [$locations->{$id}{coordinates}, \%asl_params]);
2214 }
2215 else {
2216 # Plain GEO without Apple metadata
2217 5 $VEvent->add_property('geo' => "$lat;$lon");
2218 }
2219 }
2220 }
2221  
2222 270 my $StartTimeZone = $Args->{timeZone};
2223 270 my $IsAllDay = _writesAsDate($Args);
2224 270 my $Start = _wireDate($Args->{start}, $StartTimeZone);
2225 269 $VEvent->add_property(dtstart => $Self->_makeVTimeObj($TimeZones, $Start, $StartTimeZone, $IsAllDay));
2226  
2227 # SHOW-WITHOUT-TIME for DATE-TIME events displayed as all-day
2228 # (jscalendar-icalendar-29 2.3.38, 3.2)
2229 269 ▶ if ($Args->{showWithoutTime} && !$IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"showWithoutTime"} and not $IsAllDay) 7 262 269
Condition100%3/3
$Args->{"showWithoutTime"} and not $IsAllDay
!ll&&!rl&&r
245177
MC/DC100%2/2
$Args->{"showWithoutTime"} and not $IsAllDay
$Args->{"showWithoutTime"} not $IsAllDay
Truth table100%3/3
A and not(B)
A= $Args->{"showWithoutTime"}B= not $IsAllDay
ABresult
0X0
100
111
2230 7 $VEvent->add_property('show-without-time' => ['TRUE', { VALUE => 'BOOLEAN' }]);
2231 }
2232  
2233 269 ▶ if ($Args->{duration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"duration"}) 243 26 269
2234 243 ▶ $EndTimeZone //= $StartTimeZone;
Condition100%3/3
$EndTimeZone //= $StartTimeZone
l!l&&r!l&&!r
421623
MC/DC100%2/2
$EndTimeZone //= $StartTimeZone
$EndTimeZone $StartTimeZone
Truth table100%3/3
A //= B
A= $EndTimeZoneB= $StartTimeZone
ABresult
1X1
011
000
2235 243 my $Duration = eval { DateTime::Format::ICal->parse_duration($Args->{duration}) };
2236 243 ▶ my $End = $Start->clone()->add($Duration) if $Duration;
Branch: 1 branch
BranchTrueFalseTotal
if $Duration 243 0 243
2237 243 ▶ $End->set_time_zone($EndTimeZone) if $EndTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
if $EndTimeZone 220 23 243
2238 243 $VEvent->add_property(dtend => $Self->_makeVTimeObj($TimeZones, $End, $EndTimeZone, $IsAllDay));
2239 }
2240  
2241 269 ▶ if (my $rule_def = $Args->{recurrenceRule}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rule_def = $Args->{"recurrenceRule"}) 43 226 269
2242 43 my %Recurrence = $Self->_makeRecurrence($rule_def, $IsAllDay, $StartTimeZone);
2243  
2244 # RFC 2445 4.3.10 - FREQ is the first part of the RECUR value type.
2245 # RFC 5545 3.3.10 - FREQ should be first to ensure backward compatibility.
2246 my $rule = join(';',
2247 ('FREQ=' . delete($Recurrence{FREQ})),
2248 41 (map { "$_=$Recurrence{$_}" } keys %Recurrence),
2249 );
2250 41 $VEvent->add_property(rrule => $rule);
2251 }
2252  
2253 267 my $Synthetic = isSyntheticMaster($Args);
2254 267 ▶ if ($Args->{recurrenceOverrides}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"recurrenceOverrides"}) 32 235 267
2255 32 foreach my $recurrenceId (sort keys %{$Args->{recurrenceOverrides}}) {
2256 59 my $val = $Args->{recurrenceOverrides}{$recurrenceId};
2257 59 ▶ if ($val->{excluded}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($val->{'excluded'}) { } 13 46 59
elsif (keys %$val or $Synthetic) { } 40 6 46
2258 # (no master to carry an EXDATE: the instance is simply not written)
2259 13 ▶ next if $Synthetic;
Branch: 1 branch
BranchTrueFalseTotal
if $Synthetic 1 12 13
2260 12 $VEvent->add_property(exdate => $Self->_makeLTime($TimeZones, $recurrenceId, $StartTimeZone, $IsAllDay));
2261 }
2262 ▶ elsif (keys %$val or $Synthetic) {
Condition100%3/3
keys %$val or $Synthetic
l!l&&r!l&&!r
3916
MC/DC100%2/2
keys %$val or $Synthetic
keys %$val $Synthetic
Truth table100%3/3
A or B
A= keys %$valB= $Synthetic
ABresult
1X1
011
000
2263 40 my $SubEvent = $Self->_maximise($Args, $val, $recurrenceId);
2264 40 push @VEvents, $Self->_argsToVEvents($TimeZones, $SubEvent, [$recurrenceId, $Args]);
2265 }
2266 else {
2267 6 $VEvent->add_property(rdate => $Self->_makeLTime($TimeZones, $recurrenceId, $StartTimeZone, $IsAllDay));
2268 }
2269 }
2270 }
2271  
2272 267 ▶ if ($Args->{alerts}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"alerts"}) 36 231 267
2273 # (an untitled event still gets a readable DESCRIPTION; the title was
2274 # interpolated undefined, which died under FATAL warnings)
2275 36 ▶ my $Title = $Args->{title} // '';
Condition100%2/2
$Args->{"title"} // ""
l!l
2511
MC/DC100%1/1
$Args->{"title"} // ""
$Args->{"title"}
Truth table100%2/2
A
A= $Args->{"title"}
Aresult
11
00
2276 36 for my $id (sort keys %{$Args->{alerts}}) {
2277 # a bad alert drops only itself (see errors())
2278 56 my $ok = eval {
2279 56 my $Alert = $Args->{alerts}{$id};
2280  
2281 56 ▶ my $trigger = $Alert->{trigger} // {};
Condition50%1/2
$Alert->{"trigger"} // {}
l!l
560
MC/DC0%0/1
$Alert->{"trigger"} // {}
$Alert->{"trigger"}
Truth table50%1/2
A
A= $Alert->{"trigger"}
Aresult
11
00
2282 56 ▶ my $triggerType = $trigger->{'@type'} // 'OffsetTrigger';
Condition100%2/2
$trigger->{"\@type"} // "OffsetTrigger"
l!l
515
MC/DC100%1/1
$trigger->{"\@type"} // "OffsetTrigger"
$trigger->{"\@type"}
Truth table100%2/2
A
A= $trigger->{"\@type"}
Aresult
11
00
2283 56 ▶ my $action = $Alert->{action} // 'display';
Condition100%2/2
$Alert->{"action"} // "display"
l!l
4511
MC/DC100%1/1
$Alert->{"action"} // "display"
$Alert->{"action"}
Truth table100%2/2
A
A= $Alert->{"action"}
Aresult
11
00
2284  
2285 56 my $VAlarm;
2286 56 ▶ if ($action eq 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action eq 'email') { } 5 51 56
2287 5 $VAlarm = Data::ICal::Entry::Alarm::Email->new();
2288 5 $VAlarm->add_property(summary => "Event alert: '$Title'");
2289 5 $VAlarm->add_property(description => "Event alert: '$Title'");
2290 5 ▶ if ($Args->{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"organizerCalendarAddress"}) 2 3 5
2291 2 $VAlarm->add_property(attendee => $Args->{organizerCalendarAddress});
2292 }
2293 }
2294 else {
2295 51 $VAlarm = Data::ICal::Entry::Alarm::Display->new();
2296 }
2297  
2298 56 ▶ if ($triggerType eq 'OffsetTrigger') {
Branch: 2 branches
BranchTrueFalseTotal
if ($triggerType eq 'OffsetTrigger') { } 47 9 56
elsif ($triggerType eq 'AbsoluteTrigger') { } 8 1 9
2299 47 ▶ my $Offset = $trigger->{offset} // 'PT0S';
Condition50%1/2
$trigger->{"offset"} // "PT0S"
l!l
470
MC/DC0%0/1
$trigger->{"offset"} // "PT0S"
$trigger->{"offset"}
Truth table50%1/2
A
A= $trigger->{"offset"}
Aresult
11
00
2300 47 ▶ my $RelTo = $trigger->{relativeTo} // 'start';
Condition100%2/2
$trigger->{"relativeTo"} // "start"
l!l
3710
MC/DC100%1/1
$trigger->{"relativeTo"} // "start"
$trigger->{"relativeTo"}
Truth table100%2/2
A
A= $trigger->{"relativeTo"}
Aresult
11
00
2301 # Offset may have a leading '-' sign (already encoded in the duration string)
2302 47 ▶ my $Sign = ($Offset =~ s/^-//) ? '-' : '';
Branch: 1 branch
BranchTrueFalseTotal
$Offset =~ s/^-// ? : 40 7 47
2303 47 ▶ my $Loc1 = $RelTo eq 'end' ? "ends" : "starts";
Branch: 1 branch
BranchTrueFalseTotal
$RelTo eq 'end' ? : 8 39 47
2304 47 ▶ my $Loc2 = $RelTo eq 'end' ? "ended" : "started";
Branch: 1 branch
BranchTrueFalseTotal
$RelTo eq 'end' ? : 8 39 47
2305 47 ▶ my $Minutes = eval { DateTime::Format::ICal->parse_duration(uc $Offset)->in_units('minutes') } // 0;
Condition50%1/2
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } } // 0
l!l
470
MC/DC0%0/1
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } } // 0
eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } }
Truth table50%1/2
A
A= eval { do { "DateTime::Format::ICal"->parse_duration(uc $Offset)->in_units("minutes") } }
Aresult
11
00
2306 47 ▶ if ($action ne 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "email") 42 5 47
2307 42 ▶ $VAlarm->add_properties(
Branch: 1 branch
BranchTrueFalseTotal
$Sign eq '-' ? : 35 7 42
2308 description => (($Sign eq '-')
2309 ? "'$Title' $Loc1 in $Minutes minutes"
2310 : "'$Title' $Loc2 $Minutes minutes ago"),
2311 );
2312 }
2313 47 $VAlarm->add_property(uid => $id);
2314 47 ▶ if ($RelTo eq 'end') {
Branch: 1 branch
BranchTrueFalseTotal
if ($RelTo eq 'end') { } 8 39 47
2315 8 $VAlarm->add_property(trigger => ["${Sign}$Offset", { RELATED => 'END' }]);
2316 }
2317 else {
2318 39 $VAlarm->add_property(trigger => "${Sign}$Offset");
2319 }
2320 }
2321 elsif ($triggerType eq 'AbsoluteTrigger') {
2322 8 ▶ my $When = $trigger->{when} // '';
Condition50%1/2
$trigger->{"when"} // ""
l!l
80
MC/DC0%0/1
$trigger->{"when"} // ""
$trigger->{"when"}
Truth table50%1/2
A
A= $trigger->{"when"}
Aresult
11
00
2323 8 ▶ if ($action ne 'email') {
Branch: 1 branch
BranchTrueFalseTotal
if ($action ne "email") 8 0 8
2324 8 $VAlarm->add_properties(
2325 description => "Event alert: '$Title'",
2326 );
2327 }
2328 8 $VAlarm->add_property(uid => $id);
2329 8 $VAlarm->add_property(trigger => [
2330 $Self->_makeZTime($When)->[0],
2331 { 'VALUE' => 'DATE-TIME' }
2332 ]);
2333 }
2334 else {
2335 1 confess "Unknown trigger type $triggerType";
2336 }
2337  
2338 55 ▶ if ($Alert->{acknowledged}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Alert->{"acknowledged"}) 8 47 55
2339 8 $VAlarm->add_property(acknowledged => $Self->_makeZTime($Alert->{acknowledged}));
2340 }
2341  
2342 55 $VEvent->add_entry($VAlarm);
2343 55 1;
2344 };
2345 56 ▶ $Self->_error($Args->{uid}, 'Alert', $@, $id) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 55 56
2346 }
2347 }
2348  
2349 267 my %namemap;
2350 my %keymap;
2351 267 my %sentbymap;
2352 267 ▶ if ($Args->{participants}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"participants"}) 57 210 267
2353 57 foreach my $partid (sort keys %{$Args->{participants}}) {
2354 108 my $Attendee = $Args->{participants}{$partid};
2355 # jscalendarbis: a Participant's address is its calendarAddress URI;
2356 # "email" is the JSCalendar 1.0 form, still accepted.
2357 my $Uri = $Attendee->{calendarAddress}
2358 108 ▶ // (defined $Attendee->{email} ? "mailto:$Attendee->{email}" : undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $Attendee->{'email'} ? : 1 0 1
Condition100%2/2
$Attendee->{"calendarAddress"} // (defined $Attendee->{"email"} ? qq[mailto:$Attendee->{"email"}] : undef)
l!l
1071
MC/DC100%1/1
$Attendee->{"calendarAddress"} // (defined $Attendee->{"email"} ? qq[mailto:$Attendee->{"email"}] : undef)
$Attendee->{"calendarAddress"}
Truth table100%2/2
A
A= $Attendee->{"calendarAddress"}
Aresult
11
00
2359 108 ▶ next unless defined $Uri;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Uri 0 108 108
2360  
2361 # jscalendar-icalendar 2.3.4: JSID carries the participant's key,
2362 # and may be left out only when the reader would arrive at the same
2363 # key anyway. Without it, an override patching
2364 # participants/<key>/... no longer finds its participant.
2365 108 my $DefaultKey = _defaultParticipantKey($Uri);
2366 108 ▶ my $NeedJSID = !(defined $DefaultKey and $DefaultKey eq $partid);
Condition66%2/3
defined $DefaultKey && $DefaultKey eq $partid
!ll&&!rl&&r
04464
MC/DC50%1/2
defined $DefaultKey && $DefaultKey eq $partid
defined $DefaultKey $DefaultKey eq $partid
Truth table66%2/3
A && B
A= defined $DefaultKeyB= $DefaultKey eq $partid
ABresult
0X0
100
111
2367 108 ▶ $keymap{lc $Uri} //= $partid if $NeedJSID;
Branch: 1 branch
BranchTrueFalseTotal
if $NeedJSID 44 64 108
Condition66%2/3
$keymap{lc $Uri} //= $partid
l!l&&r!l&&!r
1430
MC/DC0%0/2
$keymap{lc $Uri} //= $partid
$keymap{lc $Uri} $partid
Truth table66%2/3
A //= B
A= $keymap{lc $Uri}B= $partid
ABresult
1X1
011
000
2368  
2369 108 my %AttendeeProps;
2370 108 ▶ $AttendeeProps{JSID} = $partid if $NeedJSID;
Branch: 1 branch
BranchTrueFalseTotal
if $NeedJSID 44 64 108
2371 108 ▶ if ($Attendee->{"name"}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"name"}) 68 40 108
2372 68 $AttendeeProps{"CN"} = $Attendee->{"name"};
2373 68 $namemap{lc $Uri} = $Attendee->{"name"};
2374 }
2375  
2376 my $roles = ref($Attendee->{roles}) eq 'HASH'
2377 ? $Attendee->{roles}
2378 0 ▶ : { map { $_ => 1 } @{$Attendee->{roles} || []} };
Branch: 1 branch
BranchTrueFalseTotal
ref $Attendee->{'roles'} eq 'HASH' ? : 105 3 108
Condition50%1/2
$Attendee->{'roles'} || []
l!l
03
MC/DC0%0/1
$Attendee->{'roles'} || []
$Attendee->{'roles'}
Truth table50%1/2
A
A= $Attendee->{'roles'}
Aresult
11
00
2379  
2380 # jscalendarbis: every participant is an ATTENDEE unless the
2381 # ORGANIZER fully represents it (jscalendar-icalendar 3.6)
2382 108 ▶ unless ($roles->{attendee}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($roles->{"attendee"}) 30 78 108
2383 30 my $OrgUri = $Args->{organizerCalendarAddress};
2384 next if defined $OrgUri and lc $OrgUri eq lc $Uri
2385 23 and not grep { $_ ne 'owner' } keys %$roles
2386 30 ▶ and not grep { !$OrganizerOnly{$_} } keys %$Attendee;
Branch: 1 branch
BranchTrueFalseTotal
if defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee) 22 8 30
Condition88%8/9
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee)
!ll&&!rl&&r
7122
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles)
!ll&&!rl&&r
7023
defined $OrgUri and lc $OrgUri eq lc $Uri
!ll&&!rl&&r
2523
MC/DC75%3/4
defined $OrgUri and lc $OrgUri eq lc $Uri and not grep({$_ ne "owner";} keys %$roles) and not grep({not $OrganizerOnly{$_};} keys %$Attendee)
defined $OrgUri lc $OrgUri eq lc $Uri not grep({$_ ne "owner";} keys %$roles) not grep({not $OrganizerOnly{$_};} keys %$Attendee)
Truth table80%4/5
A and B and not(C) and not(D)
A= defined $OrgUriB= lc $OrgUri eq lc $UriC= not grep({$_ ne "owner";} keys %$roles)D= not grep({not $OrganizerOnly{$_};} keys %$Attendee)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
2387 }
2388  
2389 86 ▶ $AttendeeProps{"CUTYPE"} = uc $Attendee->{"kind"} if defined $Attendee->{"kind"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"kind"} 7 79 86
2390 86 ▶ $AttendeeProps{"RSVP"} = "TRUE" if $Attendee->{"expectReply"};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"expectReply"} 5 81 86
2391 86 ▶ $AttendeeProps{"X-SEQUENCE"} = $Attendee->{"scheduleSequence"} if defined $Attendee->{"scheduleSequence"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"scheduleSequence"} 8 78 86
2392 86 ▶ $AttendeeProps{"X-DTSTAMP"} = $Self->_makeZTime($Attendee->{"scheduleUpdated"}) if defined $Attendee->{"scheduleUpdated"};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Attendee->{"scheduleUpdated"} 9 77 86
2393 86 foreach my $prop (keys %AttendeeProps) {
2394 121 ▶ delete $AttendeeProps{$prop} if $AttendeeProps{$prop} eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $AttendeeProps{$prop} eq "" 0 121 121
2395 }
2396 86 ▶ if ($roles->{owner}) {
Branch: 4 branches
BranchTrueFalseTotal
if ($roles->{'owner'}) { } 26 60 86
elsif ($roles->{'chair'}) { } 1 59 60
elsif ($roles->{'optional'}) { } 7 52 59
elsif ($roles->{'informational'}) { } 1 51 52
2397 26 $AttendeeProps{ROLE} = 'OWNER';
2398 }
2399 elsif ($roles->{chair}) {
2400 1 $AttendeeProps{ROLE} = 'CHAIR';
2401 }
2402 elsif ($roles->{optional}) {
2403 7 $AttendeeProps{ROLE} = 'OPT-PARTICIPANT';
2404 }
2405 elsif ($roles->{informational}) {
2406 1 $AttendeeProps{ROLE} = 'NON-PARTICIPANT';
2407 }
2408 # default is REQ-PARTICIPANT
2409 86 ▶ $AttendeeProps{"SCHEDULE-AGENT"} = uc($Attendee->{scheduleAgent}) if $Attendee->{scheduleAgent};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"scheduleAgent"} 2 84 86
2410 86 ▶ if ($Attendee->{delegatedFrom} && ref($Attendee->{delegatedFrom}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH") 4 82 86
Condition66%2/3
$Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH"
!ll&&!rl&&r
8204
MC/DC50%1/2
$Attendee->{"delegatedFrom"} and ref $Attendee->{"delegatedFrom"} eq "HASH"
$Attendee->{"delegatedFrom"} ref $Attendee->{"delegatedFrom"} eq "HASH"
Truth table66%2/3
A and B
A= $Attendee->{"delegatedFrom"}B= ref $Attendee->{"delegatedFrom"} eq "HASH"
ABresult
0X0
100
111
2411 4 $AttendeeProps{"DELEGATED-FROM"} = [ sort keys %{$Attendee->{delegatedFrom}} ];
2412 }
2413 86 ▶ if ($Attendee->{delegatedTo} && ref($Attendee->{delegatedTo}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH") 4 82 86
Condition66%2/3
$Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH"
!ll&&!rl&&r
8204
MC/DC50%1/2
$Attendee->{"delegatedTo"} and ref $Attendee->{"delegatedTo"} eq "HASH"
$Attendee->{"delegatedTo"} ref $Attendee->{"delegatedTo"} eq "HASH"
Truth table66%2/3
A and B
A= $Attendee->{"delegatedTo"}B= ref $Attendee->{"delegatedTo"} eq "HASH"
ABresult
0X0
100
111
2414 4 $AttendeeProps{"DELEGATED-TO"} = [ sort keys %{$Attendee->{delegatedTo}} ];
2415 }
2416  
2417 86 ▶ $AttendeeProps{PARTSTAT} = uc $Attendee->{"participationStatus"} if $Attendee->{"participationStatus"};
Branch: 1 branch
BranchTrueFalseTotal
if $Attendee->{"participationStatus"} 49 37 86
2418 86 ▶ if (defined $Attendee->{sentBy} and length $Attendee->{sentBy}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}) 2 84 86
Condition66%2/3
defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}
!ll&&!rl&&r
8402
MC/DC50%1/2
defined $Attendee->{"sentBy"} and length $Attendee->{"sentBy"}
defined $Attendee->{"sentBy"} length $Attendee->{"sentBy"}
Truth table66%2/3
A and B
A= defined $Attendee->{"sentBy"}B= length $Attendee->{"sentBy"}
ABresult
0X0
100
111
2419 2 $AttendeeProps{"SENT-BY"} = _mailto($Attendee->{sentBy});
2420 2 $sentbymap{lc $Uri} = $Attendee->{sentBy};
2421 }
2422  
2423 86 $VEvent->add_property(attendee => [ $Uri, \%AttendeeProps ]);
2424 }
2425 }
2426 267 ▶ if ($Args->{organizerCalendarAddress}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"organizerCalendarAddress"}) 51 216 267
2427 51 my $OrgUri = $Args->{organizerCalendarAddress};
2428 51 my %OrgProps;
2429 51 my $CN = $namemap{lc $OrgUri};
2430 51 ▶ $OrgProps{CN} = $CN if $CN;
Branch: 1 branch
BranchTrueFalseTotal
if $CN 30 21 51
2431 # the organizer's participant may not be written as an ATTENDEE, so
2432 # its key must ride on the ORGANIZER (jscalendar-icalendar 2.3.29)
2433 51 ▶ $OrgProps{JSID} = $keymap{lc $OrgUri} if defined $keymap{lc $OrgUri};
Branch: 1 branch
BranchTrueFalseTotal
if defined $keymap{lc $OrgUri} 16 35 51
2434 # the Event's sentBy, else the organizer participant's (-29 3.7)
2435 51 ▶ my $SentBy = $Args->{sentBy} // $sentbymap{lc $OrgUri};
Condition66%2/3
$Args->{"sentBy"} // $sentbymap{lc $OrgUri}
l!l&&r!l&&!r
2049
MC/DC50%1/2
$Args->{"sentBy"} // $sentbymap{lc $OrgUri}
$Args->{"sentBy"} $sentbymap{lc $OrgUri}
Truth table66%2/3
A // B
A= $Args->{"sentBy"}B= $sentbymap{lc $OrgUri}
ABresult
1X1
011
000
2436 51 ▶ $OrgProps{"SENT-BY"} = _mailto($SentBy) if defined $SentBy and length $SentBy;
Branch: 1 branch
BranchTrueFalseTotal
if defined $SentBy and length $SentBy 2 49 51
Condition66%2/3
defined $SentBy and length $SentBy
!ll&&!rl&&r
4902
MC/DC50%1/2
defined $SentBy and length $SentBy
defined $SentBy length $SentBy
Truth table66%2/3
A and B
A= defined $SentByB= length $SentBy
ABresult
0X0
100
111
2437 51 ▶ $VEvent->add_property(organizer => [ $OrgUri, %OrgProps ? \%OrgProps : () ]);
Branch: 1 branch
BranchTrueFalseTotal
%OrgProps ? : 35 16 51
2438 }
2439  
2440 267 ▶ if ($Args->{links}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"links"}) 19 248 267
2441 # jscalendar-icalendar 3.4: the property follows "rel" (whose default
2442 # is "enclosure", jscalendarbis 1.5.11): enclosure -> ATTACH, icon ->
2443 # IMAGE, the first describedby -> URL, anything else -> LINK. The
2444 # title is FILENAME on ATTACH and IMAGE, LABEL on URL and LINK; LINKREL
2445 # goes on LINK only. JSID carries the key unless the reader would
2446 # arrive at it anyway.
2447 19 my $HaveURL = 0;
2448 19 foreach my $key (sort keys %{$Args->{links}}) {
2449 34 my $Link = $Args->{links}{$key};
2450 34 ▶ next unless ref $Link eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Link eq "HASH" 0 34 34
2451 34 ▶ my $Url = $Link->{href} // next;
Condition50%1/2
$Link->{"href"} // (next)
l!l
340
MC/DC0%0/1
$Link->{"href"} // (next)
$Link->{"href"}
Truth table50%1/2
A
A= $Link->{"href"}
Aresult
11
00
2452 34 ▶ my $rel = $Link->{rel} // 'enclosure';
Condition100%2/2
$Link->{"rel"} // "enclosure"
l!l
259
MC/DC100%1/1
$Link->{"rel"} // "enclosure"
$Link->{"rel"}
Truth table100%2/2
A
A= $Link->{"rel"}
Aresult
11
00
2453 34 my %Props;
2454 34 ▶ $Props{JSID} = $key unless $key eq sha1_hex(lc $Url);
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq &sha1_hex(lc $Url) 24 10 34
2455 34 my $Name;
2456 34 ▶ if ($rel eq 'enclosure') {
Branch: 3 branches
BranchTrueFalseTotal
if ($rel eq 'enclosure') { } 20 14 34
elsif ($rel eq 'icon') { } 3 11 14
elsif ($rel eq 'describedby' and not $HaveURL++) { } 6 5 11
2457 20 $Name = 'attach';
2458 20 ▶ $Props{FILENAME} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 3 17 20
2459 20 ▶ $Props{SIZE} = $Link->{size} if defined $Link->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"size"} 8 12 20
2460 }
2461 elsif ($rel eq 'icon') {
2462 3 $Name = 'image';
2463 3 $Props{VALUE} = 'URI';
2464 3 ▶ $Props{FILENAME} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 3 0 3
2465 3 ▶ $Props{SIZE} = $Link->{size} if defined $Link->{size};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"size"} 0 3 3
2466 3 ▶ my @display = grep { $Link->{display}{$_} } sort keys %{ ref $Link->{display} eq 'HASH' ? $Link->{display} : {} };
Branch: 1 branch
BranchTrueFalseTotal
ref $Link->{'display'} eq 'HASH' ? : 3 0 3
2467 3 ▶ $Props{DISPLAY} = join(',', map { uc } @display) if @display;
Branch: 1 branch
BranchTrueFalseTotal
if @display 3 0 3
2468 }
2469 ▶ elsif ($rel eq 'describedby' && !$HaveURL++) {
Condition100%3/3
$rel eq "describedby" and not $HaveURL++
!ll&&!rl&&r
326
MC/DC100%2/2
$rel eq "describedby" and not $HaveURL++
$rel eq "describedby" not $HaveURL++
Truth table100%3/3
A and not(B)
A= $rel eq "describedby"B= not $HaveURL++
ABresult
0X0
100
111
2470 6 $Name = 'url';
2471 6 ▶ $Props{LABEL} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 2 4 6
2472 }
2473 else {
2474 5 $Name = 'link';
2475 5 $Props{VALUE} = 'URI';
2476 5 $Props{LINKREL} = $rel;
2477 5 ▶ $Props{LABEL} = $Link->{title} if defined $Link->{title};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"title"} 4 1 5
2478 }
2479 34 ▶ $Props{FMTTYPE} = $Link->{contentType} if defined $Link->{contentType} && $Name ne 'url';
Branch: 1 branch
BranchTrueFalseTotal
if defined $Link->{"contentType"} and $Name ne "url" 16 18 34
Condition66%2/3
defined $Link->{"contentType"} and $Name ne "url"
!ll&&!rl&&r
18016
MC/DC50%1/2
defined $Link->{"contentType"} and $Name ne "url"
defined $Link->{"contentType"} $Name ne "url"
Truth table66%2/3
A and B
A= defined $Link->{"contentType"}B= $Name ne "url"
ABresult
0X0
100
111
2480 34 ▶ $VEvent->add_property($Name => [ $Url, %Props ? \%Props : () ]);
Branch: 1 branch
BranchTrueFalseTotal
%Props ? : 29 5 34
2481 }
2482 }
2483  
2484 267 ▶ if ($Args->{relatedTo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"relatedTo"}) 12 255 267
2485 12 foreach my $uid (keys %{$Args->{relatedTo}}) {
2486 21 my $relation = $Args->{relatedTo}{$uid}{relation};
2487 21 foreach my $key (keys %$relation) {
2488 22 ▶ $key = uc($key) if grep { $_ eq $key } qw(first next parent child);
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $key;} "first", "next", "parent", "child" 19 3 22
2489 22 my %Props;
2490 22 ▶ $Props{RELTYPE} = $key unless $key eq 'PARENT';
Branch: 1 branch
BranchTrueFalseTotal
unless $key eq "PARENT" 11 11 22
2491 22 $VEvent->add_property('RELATED-TO' => [ $uid, \%Props ]);
2492 }
2493 }
2494 }
2495  
2496 267 ▶ if ($Args->{keywords}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"keywords"}) 4 263 267
2497 4 my @items = sort keys %{$Args->{keywords}};
2498 4 $VEvent->add_property('CATEGORIES', join(',', @items));
2499 }
2500  
2501 # virtualLocations -> CONFERENCE
2502 267 ▶ if ($Args->{virtualLocations}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"virtualLocations"}) 7 260 267
2503 7 foreach my $id (sort keys %{$Args->{virtualLocations}}) {
2504 10 my $vloc = $Args->{virtualLocations}{$id};
2505 10 ▶ next unless $vloc->{uri};
Branch: 1 branch
BranchTrueFalseTotal
unless $vloc->{"uri"} 0 10 10
2506 10 my %params = ('VALUE' => 'URI');
2507 10 $params{'X-JMAP-ID'} = $id;
2508 10 ▶ if ($vloc->{features} && ref($vloc->{features}) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($vloc->{"features"} and ref $vloc->{"features"} eq "HASH") 8 2 10
Condition66%2/3
$vloc->{"features"} and ref $vloc->{"features"} eq "HASH"
!ll&&!rl&&r
208
MC/DC50%1/2
$vloc->{"features"} and ref $vloc->{"features"} eq "HASH"
$vloc->{"features"} ref $vloc->{"features"} eq "HASH"
Truth table66%2/3
A and B
A= $vloc->{"features"}B= ref $vloc->{"features"} eq "HASH"
ABresult
0X0
100
111
2509 8 my @feats = sort keys %{$vloc->{features}};
2510 8 ▶ $params{FEATURE} = join(',', map { uc $_ } @feats) if @feats;
Branch: 1 branch
BranchTrueFalseTotal
if @feats 8 0 8
2511 }
2512 10 ▶ $params{LABEL} = $vloc->{name} if defined $vloc->{name} && $vloc->{name} ne '';
Branch: 1 branch
BranchTrueFalseTotal
if defined $vloc->{"name"} and $vloc->{"name"} ne "" 8 2 10
Condition66%2/3
defined $vloc->{"name"} and $vloc->{"name"} ne ""
!ll&&!rl&&r
208
MC/DC50%1/2
defined $vloc->{"name"} and $vloc->{"name"} ne ""
defined $vloc->{"name"} $vloc->{"name"} ne ""
Truth table66%2/3
A and B
A= defined $vloc->{"name"}B= $vloc->{"name"} ne ""
ABresult
0X0
100
111
2513 10 $VEvent->add_property(conference => [$vloc->{uri}, \%params]);
2514 }
2515 }
2516  
2517 # Task-specific properties (VTODO)
2518 267 ▶ if ($is_task) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_task) 8 259 267
2519 8 ▶ if ($Args->{due}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"due"}) 6 2 8
2520 6 $VEvent->add_property(due => $Self->_makeLTime($TimeZones, $Args->{due}, $StartTimeZone, $IsAllDay));
2521 }
2522 8 ▶ if (defined $Args->{percentComplete}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"percentComplete"}) 5 3 8
2523 5 $VEvent->add_property('percent-complete' => $Args->{percentComplete});
2524 }
2525 8 ▶ if ($Args->{estimatedDuration}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"estimatedDuration"}) 1 7 8
2526 1 $VEvent->add_property('estimated-duration' => $Args->{estimatedDuration});
2527 }
2528 8 ▶ if ($Args->{progress} && $Args->{progress} eq 'completed') {
Branch: 2 branches
BranchTrueFalseTotal
if ($Args->{'progress'} and $Args->{'progress'} eq 'completed') { } 1 7 8
elsif ($Args->{'progress'} and $Args->{'progress'} eq 'in-process') { } 2 9 11
Condition100%3/3
$Args->{"progress"} and $Args->{"progress"} eq "completed"
!ll&&!rl&&r
431
MC/DC100%2/2
$Args->{"progress"} and $Args->{"progress"} eq "completed"
$Args->{"progress"} $Args->{"progress"} eq "completed"
Truth table100%3/3
A and B
A= $Args->{"progress"}B= $Args->{"progress"} eq "completed"
ABresult
0X0
100
111
2529 1 ▶ $VEvent->add_property(completed => $Self->_makeZTime($Args->{updated} || DateTime->now->iso8601()));
Condition33%1/3
$Args->{'updated'} || 'DateTime'->now->iso8601
l!l&&r!l&&!r
100
MC/DC0%0/2
$Args->{'updated'} || 'DateTime'->now->iso8601
$Args->{'updated'} 'DateTime'->now->iso8601
Truth table33%1/3
A || B
A= $Args->{'updated'}B= 'DateTime'->now->iso8601
ABresult
1X1
011
000
2530 }
2531 ▶ elsif ($Args->{progress} && $Args->{progress} eq 'in-process') {
Condition100%3/3
$Args->{"progress"} and $Args->{"progress"} eq "in-process"
!ll&&!rl&&r
412
MC/DC100%2/2
$Args->{"progress"} and $Args->{"progress"} eq "in-process"
$Args->{"progress"} $Args->{"progress"} eq "in-process"
Truth table100%3/3
A and B
A= $Args->{"progress"}B= $Args->{"progress"} eq "in-process"
ABresult
0X0
100
111
2532 2 $VEvent->add_property(status => 'IN-PROCESS');
2533 }
2534 }
2535  
2536 # a synthetic master (see SYNTHETIC_MASTER) has no component of its
2537 # own: only its instances are written
2538 267 ▶ unshift @VEvents, $VEvent unless $Synthetic;
Branch: 1 branch
BranchTrueFalseTotal
unless $Synthetic 262 5 267
2539  
2540 267 return @VEvents;
2541 }
2542  
2543 =head2 $self->eventsToVCalendar(@Events)
2544  
2545 Convert a set of events (one or multiple) into an ical file)
2546  
2547 Returns a string
2548  
2549 e.g.
2550  
2551 print $jscal->eventsToVCalendar(@Events);
2552  
2553 =cut
2554  
2555 234 ▶sub eventsToVCalendar {
Subroutine eventsToVCalendar: called CC=1 SCAR=0.0
Pod documented
2556 234 my $Self = shift;
2557 234 $Self->_resetDiagnostics();
2558 234 my $VCalendar = $Self->_buildVCalendar(\@_);
2559 234 ▶ return $Self->_withICalWarnings(sub { $VCalendar->as_string() });
Subroutine __ANON__: called CC=1 SCAR=0.0
2560 }
2561  
2562 1 ▶sub _argsToVCalendar {
Subroutine _argsToVCalendar: called CC=1 SCAR=0.0
2563 1 my $Self = shift;
2564 1 $Self->_resetDiagnostics();
2565 1 return $Self->_buildVCalendar(@_);
2566 }
2567  
2568 235 ▶sub _buildVCalendar {
Subroutine _buildVCalendar: called CC=1 SCAR=0.0
2569 235 my $Self = shift;
2570 235 my $Item = shift;
2571 235 my %ExtraProp = @_;
2572 235 ▶ return $Self->_withICalWarnings(sub { $Self->_buildVCalendarInner($Item, %ExtraProp) });
Subroutine __ANON__: called CC=1 SCAR=0.0
2573 }
2574  
2575 235 ▶sub _buildVCalendarInner {
Subroutine _buildVCalendarInner: called CC=15 SCAR=27.1
2576 235 my $Self = shift;
2577 235 my $Item = shift;
2578 235 my %ExtraProp = @_;
2579  
2580 235 my $VCalendar = Data::ICal->new();
2581 235 my $havepid = 0;
2582  
2583 235 foreach my $extra (keys %ExtraProp) {
2584 0 $VCalendar->add_properties($extra => $ExtraProp{$extra});
2585 }
2586 235 $VCalendar->add_properties(calscale => 'GREGORIAN');
2587  
2588 235 my @VEvents;
2589 my %TimeZones;
2590 235 ▶ foreach my $Args (ref $Item eq 'ARRAY' ? @$Item : $Item) {
Branch: 1 branch
BranchTrueFalseTotal
ref $Item eq 'ARRAY' ? : 235 0 235
2591 # each object on its own: one that cannot be written is left out
2592 # (and reported by errors()), not the whole calendar
2593 231 my %Zones;
2594 231 my @Converted = eval {
2595 231 ▶ die "not a JSCalendar object\n" unless ref $Args eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Args eq "HASH" 1 230 231
2596 230 $Self->_argsToVEvents(\%Zones, $Args);
2597 };
2598 231 ▶ if (my $err = $@) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $@) 4 227 231
2599 4 ▶ my $type = ref $Args eq 'HASH' && ($Args->{'@type'} // '') eq 'Task' ? 'Task' : 'Event';
Branch: 1 branch
BranchTrueFalseTotal
ref $Args eq 'HASH' && ($Args->{'@type'} // '') eq 'Task' ? : 1 3 4
Condition80%4/5
ref $Args eq "HASH" and ($Args->{"\@type"} // "") eq "Task"
!ll&&!rl&&r
121
$Args->{"\@type"} // ""
l!l
30
MC/DC50%1/2
ref $Args eq "HASH" and ($Args->{"\@type"} // "") eq "Task"
ref $Args eq "HASH" $Args->{"\@type"}
Truth table66%2/3
A and B
A= ref $Args eq "HASH"B= $Args->{"\@type"}
ABresult
0X0
100
111
2600 4 ▶ $Self->_error(ref $Args eq 'HASH' ? $Args->{uid} : undef, $type, $err);
Branch: 1 branch
BranchTrueFalseTotal
ref $Args eq 'HASH' ? : 3 1 4
2601 4 next;
2602 }
2603 227 push @VEvents, @Converted;
2604 227 @TimeZones{keys %Zones} = values %Zones;
2605 227 ▶ if (not $havepid and $Args->{prodId}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $havepid and $Args->{"prodId"}) 146 81 227
Condition100%3/3
not $havepid and $Args->{"prodId"}
!ll&&!rl&&r
279146
MC/DC100%2/2
not $havepid and $Args->{"prodId"}
not $havepid $Args->{"prodId"}
Truth table100%3/3
not(A) and B
A= not $havepidB= $Args->{"prodId"}
ABresult
0X0
100
111
2606 146 $VCalendar->add_properties('prodid' => $Args->{prodId});
2607 146 $havepid = 1;
2608 }
2609 }
2610  
2611 # add timezone parts first
2612 235 foreach my $Zone (sort keys %TimeZones) {
2613 105 my $VTimeZone = Text::JSCalendar::TimeZones->GetVTimeZone($Zone);
2614 105 ▶ next unless $VTimeZone;
Branch: 1 branch
BranchTrueFalseTotal
unless $VTimeZone 0 105 105
2615 105 $VCalendar->add_entry($VTimeZone);
2616 }
2617  
2618 # then the events
2619 235 foreach my $VEvent (@VEvents) {
2620 262 $VCalendar->add_entry($VEvent);
2621 }
2622  
2623 235 _sanitizeEntry($VCalendar);
2624  
2625 235 return $VCalendar;
2626 }
2627  
2628 # Data::ICal escapes newlines in values, but not a lone CR, and puts
2629 # parameter values out verbatim, so a CR or LF from the event data
2630 # would start a new content line. RFC 5545 allows no control characters
2631 # other than HTAB in either, so strip them before serialising.
2632 866 ▶sub _sanitizeEntry {
Subroutine _sanitizeEntry: called CC=8 SCAR=20.9
2633 866 my $Entry = shift;
2634  
2635 866 foreach my $Props (values %{$Entry->properties}) {
2636 4337 foreach my $Prop (@$Props) {
2637 4391 my $value = $Prop->value;
2638 4391 ▶ if (defined $value and not ref $value) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and not ref $value) 4391 0 4391
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
004391
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
2639 4391 $value =~ s/\r\n?/\n/g;
2640 4391 $value =~ s/[\x00-\x08\x0b-\x1f\x7f]//g;
2641 4391 $Prop->value($value);
2642 }
2643  
2644 4391 my %params;
2645 4391 ▶ while (my ($name, $val) = each %{$Prop->parameters}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$Prop->parameters;}) 798 4391 5189
2646 $params{$name} = ref $val eq 'ARRAY'
2647 798 ▶ ? [ map { _sanitizeParam($_) } @$val ]
Branch: 1 branch
BranchTrueFalseTotal
ref $val eq 'ARRAY' ? : 17 781 798
2648 : _sanitizeParam($val);
2649 }
2650 4391 $Prop->parameters(\%params);
2651 }
2652 }
2653  
2654 866 _sanitizeEntry($_) for @{$Entry->entries};
2655 }
2656  
2657 799 ▶sub _sanitizeParam {
Subroutine _sanitizeParam: called CC=2 SCAR=7.0
2658 799 my $val = shift;
2659 799 ▶ return $val unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 799 799
2660 799 $val =~ s/[\r\n]+/ /g;
2661 # DQUOTE can't be escaped either; Data::ICal drops it with a warning
2662 799 $val =~ s/[\x00-\x08\x0a-\x1f\x7f"]//g;
2663 # nor a backslash: RFC 5545 gives it no meaning in a parameter, but
2664 # Text::VCardFast reads \; \: \" as escapes, so "Evil \" swallowed the
2665 # next parameter, or left the line unreadable
2666 799 $val =~ s/\\//g;
2667 799 return $val;
2668 }
2669  
2670 43 ▶sub _makeRecurrence {
Subroutine _makeRecurrence: called CC=41 SCAR=43.3
2671 43 my $Self = shift;
2672 43 my ($Args, $IsAllDay, $TZ) = @_;
2673  
2674 43 my %Recurrence;
2675  
2676 # validate simple recurrence properties {{{
2677  
2678 43 ▶ unless (ref($Args) eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args eq "HASH") 0 43 43
2679 0 confess 'Invalid recurrence';
2680 }
2681  
2682 43 ▶ if ($Args->{frequency}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{'frequency'}) { } 43 0 43
2683 43 ▶ unless ($ValidFrequency{$Args->{frequency}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidFrequency{$Args->{"frequency"}}) 1 42 43
2684 1 confess "Invalid recurrence frequency ($Args->{frequency})";
2685 }
2686  
2687 42 $Recurrence{FREQ} = uc($Args->{frequency});
2688 }
2689 else {
2690 0 confess 'Recurrence frequency not specified';
2691 }
2692  
2693 # (numbers are copied before they meet a pattern or a join: either
2694 # stringifies the value it is given, and that would turn the caller's
2695 # 2 into "2" when it next encodes the object as JSON)
2696 42 ▶ if (defined $Args->{interval}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"interval"}) 7 35 42
2697 7 my $interval = $Args->{interval};
2698 7 ▶ unless ($interval =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($interval =~ /^\d+$/) 0 7 7
2699 0 confess "Invalid recurrence interval ($interval)";
2700 }
2701  
2702 7 ▶ if ($interval == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval == 0) 0 7 7
2703 0 confess "Recurrence interval is out of range ($interval)";
2704 }
2705  
2706 7 ▶ if ($interval > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($interval > 1) 7 0 7
2707 7 $Recurrence{INTERVAL} = $interval;
2708 }
2709 }
2710  
2711 42 ▶ if (defined $Args->{firstDayOfWeek}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"firstDayOfWeek"}) 1 41 42
2712 1 ▶ unless ($ValidDay{$Args->{firstDayOfWeek}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ValidDay{$Args->{"firstDayOfWeek"}}) 0 1 1
2713 0 confess "Invalid recurrence firstDayOfWeek ($Args->{firstDayOfWeek})";
2714 }
2715  
2716 1 ▶ unless ($Args->{firstDayOfWeek} eq 'mo') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Args->{"firstDayOfWeek"} eq "mo") 1 0 1
2717 1 $Recurrence{WKST} = uc $Args->{firstDayOfWeek};
2718 }
2719 }
2720  
2721 42 ▶ if ($Args->{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"byDay"}) 11 31 42
2722 11 ▶ unless (ref($Args->{byDay}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{"byDay"} eq "ARRAY") 0 11 11
2723 0 confess 'Invalid recurrence byDay';
2724 }
2725  
2726 11 ▶ unless (@{$Args->{byDay}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{"byDay"};}) 0 11 11
2727 0 confess 'Recurrence byDay is empty';
2728 }
2729  
2730 11 $Recurrence{BYDAY} = join(',', map{ _byDay2BYDAY($_) } @{$Args->{byDay}});
2731 }
2732  
2733 42 ▶ if ($Args->{byMonth}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"byMonth"}) 7 35 42
2734 7 ▶ unless (ref($Args->{byMonth}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{"byMonth"} eq "ARRAY") 0 7 7
2735 0 confess 'Invalid recurrence byMonth';
2736 }
2737  
2738 7 ▶ unless (@{$Args->{byMonth}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{"byMonth"};}) 0 7 7
2739 0 confess 'Recurrence byMonth is empty';
2740 }
2741  
2742 7 my @BYMONTHS;
2743  
2744 7 foreach my $byMonthArg (@{$Args->{byMonth}}) {
2745 10 my $byMonth = $byMonthArg;
2746 10 ▶ unless ($byMonth =~ /^(\d+)L?$/i) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($byMonth =~ /^(\d+)L?$/i) 0 10 10
2747 0 confess "Recurrence byMonth is not a number with optional L ($byMonth)";
2748 }
2749 10 my $monthNum = $1;
2750 10 ▶ unless ($monthNum >= 1 and $monthNum <= 13) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($monthNum >= 1 and $monthNum <= 13) 0 10 10
Condition33%1/3
$monthNum >= 1 and $monthNum <= 13
!ll&&!rl&&r
0010
MC/DC0%0/2
$monthNum >= 1 and $monthNum <= 13
$monthNum >= 1 $monthNum <= 13
Truth table33%1/3
A and B
A= $monthNum >= 1B= $monthNum <= 13
ABresult
0X0
100
111
2751 # not sure if 13 is OK
2752 0 confess "Recurrence byMonth is too high ($monthNum)";
2753 }
2754  
2755 10 push @BYMONTHS, $byMonth;
2756 }
2757  
2758 7 $Recurrence{BYMONTH} = join ',', @BYMONTHS;
2759 }
2760  
2761 42 ▶ if (defined $Args->{count}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"count"}) 15 27 42
2762 15 ▶ if (defined $Args->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Args->{"until"}) 0 15 15
2763 0 confess 'Recurrence count and until cannot both be set';
2764 }
2765  
2766 15 my $count = $Args->{count};
2767 15 ▶ unless ($count =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($count =~ /^\d+$/) 0 15 15
2768 0 confess "Invalid recurrence count ($count)";
2769 }
2770  
2771 15 $Recurrence{COUNT} = $count;
2772 }
2773  
2774 42 ▶ if ($Args->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"until"}) 4 38 42
2775 4 my $Until = _wireDate($Args->{until}, $Self->tz($TZ));
2776  
2777 4 ▶ if ($IsAllDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($IsAllDay) { } 2 2 4
2778 2 $Recurrence{UNTIL} = $Until->strftime('%Y%m%d');
2779 }
2780 else {
2781 # API is in Localtime, but both iCloud and Google use 'Z' times as per
2782 # rfc2445, so we'll copy them for compatibility.
2783 2 $Until->set_time_zone($UTC);
2784 2 $Recurrence{UNTIL} = $Until->strftime('%Y%m%dT%H%M%SZ');
2785 }
2786 }
2787  
2788 42 ▶ if ($Args->{rscale}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{"rscale"}) 7 35 42
2789 # written into the RRULE as they are: an rscale like "gregorian;COUNT=1"
2790 # would add rule parts past the checks below (RFC 7529: an rscale is a
2791 # calendar name; skip is one of three values)
2792 7 ▶ confess "recurrence rscale ($Args->{rscale}) is not valid" unless $Args->{rscale} =~ /\A[A-Za-z0-9-]{1,64}\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $Args->{"rscale"} =~ /\A[A-Za-z0-9-]{1,64}\z/ 1 6 7
2793 confess "recurrence skip ($Args->{skip}) is not valid"
2794 6 ▶ if exists $Args->{skip} && ($Args->{skip} // '') !~ /\A(?:omit|backward|forward)\z/i;
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"skip"} and not +($Args->{"skip"} // "") =~ /\A(?:omit|backward|forward)\z/i 0 6 6
Condition40%2/5
exists $Args->{"skip"} and not +($Args->{"skip"} // "") =~ /\A(?:omit|backward|forward)\z/i
!ll&&!rl&&r
060
$Args->{"skip"} // ""
l!l
60
MC/DC0%0/2
exists $Args->{"skip"} and not +($Args->{"skip"} // "") =~ /\A(?:omit|backward|forward)\z/i
exists $Args->{"skip"} $Args->{"skip"}
Truth table33%1/3
A and not(B)
A= exists $Args->{"skip"}B= $Args->{"skip"}
ABresult
0X0
110
101
2795 6 $Recurrence{RSCALE} = uc $Args->{rscale};
2796 6 ▶ $Recurrence{SKIP} = uc $Args->{skip} if exists $Args->{skip};
Branch: 1 branch
BranchTrueFalseTotal
if exists $Args->{"skip"} 6 0 6
2797 }
2798  
2799 # }}}
2800  
2801 # validate generic recurrence properties {{{
2802  
2803 41 foreach my $Property (keys %RecurrenceProperties) {
2804 287 my $Name = $RecurrenceProperties{$Property}{name};
2805  
2806 287 ▶ if ($Args->{$Name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Args->{$Name}) 25 262 287
2807 25 ▶ unless (ref($Args->{$Name}) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $Args->{$Name} eq "ARRAY") 0 25 25
2808 0 confess "Invalid recurrence $Name";
2809 }
2810  
2811 25 ▶ unless (@{$Args->{$Name}}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$Args->{$Name};}) 0 25 25
2812 0 confess "Recurrence $Name is empty";
2813 }
2814  
2815 25 my @Values;
2816  
2817 25 foreach my $ValueArg (@{$Args->{$Name}}) {
2818 43 my $Value = $ValueArg;
2819 my ($Valid, $Min) = $RecurrenceProperties{$Property}{signed}
2820 43 ▶ ? ('[-+]?[1-9]\d*', ($RecurrenceProperties{$Property}{max} * -1))
Branch: 1 branch
BranchTrueFalseTotal
$RecurrenceProperties{$Property}{'signed'} ? : 26 17 43
2821 : ('\d+', 0);
2822  
2823 43 ▶ unless ($Value =~ /^$Valid$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Value =~ /^$Valid$/) 0 43 43
2824 0 confess "Invalid recurrence $Name ($Value)";
2825 }
2826  
2827 43 ▶ unless (($Min <= $Value) and ($Value <= $RecurrenceProperties{$Property}{max})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}) 0 43 43
Condition33%1/3
$Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}
!ll&&!rl&&r
0043
MC/DC0%0/2
$Min <= $Value and $Value <= $RecurrenceProperties{$Property}{"max"}
$Min <= $Value $Value <= $RecurrenceProperties{$Property}{"max"}
Truth table33%1/3
A and B
A= $Min <= $ValueB= $Value <= $RecurrenceProperties{$Property}{"max"}
ABresult
0X0
100
111
2828 0 confess "Recurrence $Name is out of range ($Value)";
2829 }
2830  
2831 43 push @Values, $Value;
2832 }
2833  
2834 25 $Recurrence{uc $Property} = join ',', @Values;
2835 }
2836 }
2837  
2838 # }}}
2839  
2840 41 return %Recurrence;
2841 }
2842  
2843 =head2 $self->vcalendarToEvents($Data)
2844  
2845 Convert a text vcalendar (either a single event or an entire ical file) into an array of events.
2846  
2847 Returns an array (not arrayref) of Events in UID order.
2848  
2849 e.g.
2850  
2851 foreach my $Event ($CalDAV->vcalendarToEvents($Data)) {
2852 # ...
2853 }
2854  
2855 =cut
2856  
2857 56 ▶sub _insert_override {
Subroutine _insert_override: called CC=10 SCAR=23.0
2858 56 my $Event = shift;
2859 56 my $recurrenceId = shift;
2860 56 my $Recurrence = shift;
2861 56 my $KeepEmpty = shift;
2862  
2863 56 my %override;
2864 56 my %oldkeys = map { $_ => 1 } keys %$Event;
2865 56 foreach my $Key (sort keys %$Recurrence) {
2866 672 delete $oldkeys{$Key};
2867 672 ▶ next if $MustBeTopLevel{$Key}; # XXX - check safeeq and die?
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$Key} 236 436 672
2868 436 ▶ if ($Key eq 'start') {
Branch: 1 branch
BranchTrueFalseTotal
if ($Key eq "start") 56 380 436
2869 # special case, it's the recurrence-id
2870 56 ▶ next if _safeeq($Recurrence->{start}, $recurrenceId);
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($Recurrence->{"start"}, $recurrenceId) 23 33 56
2871 33 $override{start} = $Recurrence->{start};
2872 33 next;
2873 }
2874 380 ▶ next if _safeeq($Recurrence->{$Key}, $Event->{$Key});
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($Recurrence->{$Key}, $Event->{$Key}) 288 92 380
2875 92 _add_override(\%override, _quotekey($Key), $Recurrence->{$Key}, $Event->{$Key});
2876 }
2877  
2878 56 foreach my $Key (sort keys %oldkeys) {
2879 99 ▶ next if $MustBeTopLevel{$Key};
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$Key} 87 12 99
2880 12 $override{$Key} = $JSON::null;
2881 }
2882  
2883 # in theory should never happen, but you could edit something back to be identical
2884 56 ▶ return unless %override or $KeepEmpty;
Branch: 1 branch
BranchTrueFalseTotal
unless %override or $KeepEmpty 4 52 56
Condition66%2/3
%override or $KeepEmpty
l!l&&r!l&&!r
5204
MC/DC50%1/2
%override or $KeepEmpty
%override $KeepEmpty
Truth table66%2/3
A or B
A= %overrideB= $KeepEmpty
ABresult
1X1
011
000
2885 52 $Event->{recurrenceOverrides}{$recurrenceId} = \%override;
2886 }
2887  
2888 395 ▶sub vcalendarToEvents {
Subroutine vcalendarToEvents: called CC=13 SCAR=25.7
Pod documented
2889 395 my $Self = shift;
2890 395 my $Data = shift;
2891  
2892 # Internal caches need to be invalidated on each item read! A bit evil really...
2893 395 delete $Self->{_tznamemap};
2894 395 $Self->_resetDiagnostics();
2895  
2896 395 my %map;
2897 my %exceptions;
2898 395 my $Events = $Self->_getEventsFromVCalendar($Data);
2899  
2900 394 foreach my $Event (@$Events) {
2901 428 my $uid = $Event->{uid};
2902 428 ▶ if ($Event->{_recurrenceObj}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Event->{'_recurrenceObj'}) { } 55 373 428
elsif ($map{$uid}) { } 1 372 373
2903 55 push @{$exceptions{$uid}}, $Event;
2904 }
2905 elsif ($map{$uid}) {
2906 # it looks like sometimes Google doesn't remember to put the Recurrence ID
2907 # on additional recurrences after the first one, which is going to screw up
2908 # pretty badly because if the date has changed, then we can't even notice
2909 # which recurrent it was SUPPOSED to be. *sigh*.
2910 1 ▶ $Self->_warning($uid, uc($Event->{'@type'} eq 'Task' ? 'VTODO' : 'VEVENT'),
Branch: 1 branch
BranchTrueFalseTotal
$Event->{'@type'} eq 'Task' ? : 0 1 1
2911 "a second component without RECURRENCE-ID; read as an instance at its DTSTART");
2912 1 push @{$exceptions{$uid}}, $Event;
2913 1 $map{$uid}{_dirty} = 1;
2914 }
2915 else {
2916 372 $map{$uid} = $Event;
2917 }
2918 }
2919  
2920 394 foreach my $uid (keys %exceptions) {
2921 38 ▶ unless ($map{$uid}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($map{$uid}) 9 29 38
2922 # create a synthetic top-level, and say so (see SYNTHETIC_MASTER),
2923 # from the earliest instance, so that it does not depend on the
2924 # order of the components (the writer sorts them)
2925 9 my ($First) = sort { _compareInstances($a, $b) } @{$exceptions{$uid}};
2926 $map{$uid} = {
2927 SYNTHETIC_MASTER() => $JSON::true,
2928 uid => $uid,
2929 # required at top level, but may be different in recurrences
2930 # so not in MustBeTopLevel
2931 start => $First->{start},
2932 updated => $First->{updated},
2933 version => $First->{version},
2934 9 };
2935 9 ▶ $map{$uid}{timeZone} = $First->{timeZone} unless $First->{showWithoutTime};
Branch: 1 branch
BranchTrueFalseTotal
unless $First->{"showWithoutTime"} 9 0 9
2936 9 foreach my $key (keys %MustBeTopLevel) {
2937 117 ▶ $map{$uid}{$key} = $First->{$key} if exists $First->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $First->{$key} 40 77 117
2938 }
2939 }
2940 38 foreach my $SubEvent (@{$exceptions{$uid}}) {
2941 56 my $recurrenceId = $SubEvent->{start};
2942 56 ▶ if ($SubEvent->{_recurrenceObj}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($SubEvent->{"_recurrenceObj"}) 55 1 56
2943 55 my $Date = delete $SubEvent->{_recurrenceObj};
2944 55 ▶ $Date->set_time_zone($map{$uid}{timeZone}) if $map{$uid}{timeZone};
Branch: 1 branch
BranchTrueFalseTotal
if $map{$uid}{"timeZone"} 52 3 55
2945 55 $recurrenceId = $Date->iso8601();
2946 }
2947 # every instance of a synthetic master is an override, even one
2948 # that patches nothing: there is no rule or RDATE to recur from
2949 56 _insert_override($map{$uid}, $recurrenceId, $SubEvent, isSyntheticMaster($map{$uid}));
2950 }
2951 }
2952  
2953 394 return map { $map{$_} } sort keys %map;
2954 }
2955  
2956 =head2 $self->instance($Event, $recurrenceId)
2957  
2958 The occurrence of C<$Event> with the given recurrence id (a LocalDateTime
2959 as used for C<recurrenceOverrides> keys, C<YYYY-MM-DDTHH:MM:SS>), as an
2960 object of its own: a copy of the master with the override patch for that
2961 id, if any, applied (PatchObject paths such as
2962 C<participants/p1/participationStatus> included, as the writer applies
2963 them), C<recurrenceId> set, C<recurrenceIdTimeZone> set to the master's
2964 C<timeZone> if it has one, C<start> the patch's if it moves the
2965 occurrence and the recurrence id otherwise, and C<recurrenceRule> and
2966 C<recurrenceOverrides> removed. A patch cannot change the properties an
2967 occurrence must share with its master (C<uid>, C<@type>,
2968 C<recurrenceRule>, ...; the same ones the writer ignores).
2969  
2970 Returns undef if the occurrence is excluded, or if C<$Event> is a
2971 synthetic master (see above) and the id is not one of its instances.
2972 It does not check that the id is an occurrence of the rule: that is
2973 what C<occurrences> is for. C<$Event> is not changed. May be called as
2974 a class method.
2975  
2976 =cut
2977  
2978 6 ▶sub instance {
Subroutine instance: called CC=11 SCAR=24.2
Pod documented
2979 6 my ($Self, $Event, $recurrenceId) = @_;
2980 6 ▶ croak 'instance: not an event' unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 6 6
2981 6 ▶ my $rid = _localDateTime($recurrenceId) // croak "instance: invalid recurrenceId";
Condition50%1/2
_localDateTime($recurrenceId) // croak("instance: invalid recurrenceId")
l!l
60
MC/DC0%0/1
_localDateTime($recurrenceId) // croak("instance: invalid recurrenceId")
_localDateTime($recurrenceId)
Truth table50%1/2
A
A= _localDateTime($recurrenceId)
Aresult
11
00
2982  
2983 6 ▶ my $Overrides = ref $Event->{recurrenceOverrides} eq 'HASH' ? $Event->{recurrenceOverrides} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $Event->{'recurrenceOverrides'} eq 'HASH' ? : 6 0 6
2984 6 my $Patch = $Overrides->{$rid};
2985 6 ▶ $Patch = undef unless ref $Patch eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Patch eq "HASH" 2 4 6
2986 6 ▶ return undef if $Patch and $Patch->{excluded};
Branch: 1 branch
BranchTrueFalseTotal
if $Patch and $Patch->{"excluded"} 1 5 6
Condition100%3/3
$Patch and $Patch->{"excluded"}
!ll&&!rl&&r
231
MC/DC100%2/2
$Patch and $Patch->{"excluded"}
$Patch $Patch->{"excluded"}
Truth table100%3/3
A and B
A= $PatchB= $Patch->{"excluded"}
ABresult
0X0
100
111
2987 5 ▶ return undef if !$Patch and isSyntheticMaster($Event);
Branch: 1 branch
BranchTrueFalseTotal
if not $Patch and isSyntheticMaster($Event) 1 4 5
Condition100%3/3
not $Patch and isSyntheticMaster($Event)
!ll&&!rl&&r
311
MC/DC100%2/2
not $Patch and isSyntheticMaster($Event)
not $Patch isSyntheticMaster($Event)
Truth table100%3/3
not(A) and B
A= not $PatchB= isSyntheticMaster($Event)
ABresult
0X0
100
111
2988  
2989 4 ▶ my $Instance = $Self->_maximise($Event, $Patch || {}, $rid);
Condition100%2/2
$Patch || {}
l!l
31
MC/DC100%1/1
$Patch || {}
$Patch
Truth table100%2/2
A
A= $Patch
Aresult
11
00
2990 4 delete $Instance->{excluded};
2991 4 $Instance->{recurrenceId} = $rid;
2992 4 ▶ if (defined $Event->{timeZone}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Event->{'timeZone'}) { } 4 0 4
2993 4 $Instance->{recurrenceIdTimeZone} = $Event->{timeZone};
2994 }
2995 else {
2996 0 delete $Instance->{recurrenceIdTimeZone};
2997 }
2998 4 return $Instance;
2999 }
3000  
3001 =head2 $self->occurrences($Event, after => $from, before => $to, max => $n)
3002  
3003 The recurrence ids of C<$Event> (LocalDateTimes, C<YYYY-MM-DDTHH:MM:SS>,
3004 the form of C<recurrenceOverrides> keys) that are at or after C<after>
3005 and before C<before>, in order. Both bounds are LocalDateTimes in the
3006 event's own time zone (a trailing C<Z> is ignored, a bare date means its
3007 midnight) and either may be left out. These are:
3008  
3009 =over
3010  
3011 =item * the event's C<start>, which is always the first occurrence
3012 (jscalendarbis-22 3.3.3.1), and for a C<recurrenceRule> every date-time
3013 the rule produces from it, with every rule property this module reads:
3014 C<frequency>, C<interval>, C<firstDayOfWeek>, C<byDay> (with
3015 C<nthOfPeriod>), C<byMonthDay>, C<byMonth>, C<byYearDay>, C<byWeekNo>,
3016 C<byHour>, C<byMinute>, C<bySecond>, C<bySetPosition>, C<count>,
3017 C<until>, and C<skip> (C<rscale> must be C<gregorian>, the default;
3018 another one dies),
3019  
3020 =item * plus every C<recurrenceOverrides> key that is not excluded and
3021 that the rule does not produce (an added occurrence, iCalendar's RDATE),
3022  
3023 =item * minus every key whose patch sets C<excluded>.
3024  
3025 =back
3026  
3027 For a synthetic master (see above) they are its instances: its override
3028 keys, minus the excluded ones.
3029  
3030 C<max> (default 5000) bounds the number returned, so an unbounded rule
3031 without C<before> still ends; a rule that stops matching (C<byMonthDay>
3032 30 in C<byMonth> 2) ends once 400 years pass without an occurrence.
3033 Returns an empty list for an event without C<start>. May be called as
3034 a class method.
3035  
3036 =cut
3037  
3038 19 our $MaxOccurrences = 5000;
3039 # Bounds on one rule's expansion (a rule is untrusted input): the periods
3040 # and candidate dates looked at, and the entries of any one BYxxx list.
3041 19 our $MaxExpandWork = 250_000;
3042 19 our $MaxRuleList = 400;
3043  
3044 39 ▶sub occurrences {
Subroutine occurrences: called CC=23 SCAR=32.5
Pod documented
3045 39 my ($Self, $Event, %Opts) = @_;
3046 39 ▶ croak 'occurrences: not an event' unless ref $Event eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Event eq "HASH" 0 39 39
3047 39 ▶ my $max = $Opts{max} // $MaxOccurrences;
Condition66%2/3
$Opts{"max"} // $Text::JSCalendar::MaxOccurrences
l!l&&r!l&&!r
4350
MC/DC0%0/2
$Opts{"max"} // $Text::JSCalendar::MaxOccurrences
$Opts{"max"} $Text::JSCalendar::MaxOccurrences
Truth table66%2/3
A // B
A= $Opts{"max"}B= $Text::JSCalendar::MaxOccurrences
ABresult
1X1
011
000
3048 39 ▶ croak 'occurrences: max must be a positive integer' unless $max =~ /^\d+$/ and $max > 0;
Branch: 1 branch
BranchTrueFalseTotal
unless $max =~ /^\d+$/ and $max > 0 0 39 39
Condition33%1/3
$max =~ /^\d+$/ and $max > 0
!ll&&!rl&&r
0039
MC/DC0%0/2
$max =~ /^\d+$/ and $max > 0
$max =~ /^\d+$/ $max > 0
Truth table33%1/3
A and B
A= $max =~ /^\d+$/B= $max > 0
ABresult
0X0
100
111
3049 39 my ($after, $before);
3050 39 ▶ if (defined $Opts{after}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Opts{"after"}) 5 34 39
3051 5 ▶ $after = _localDateTime($Opts{after}) // croak "occurrences: invalid after ($Opts{after})";
Condition50%1/2
_localDateTime($Opts{"after"}) // croak(qq[occurrences: invalid after ($Opts{"after"})])
l!l
50
MC/DC0%0/1
_localDateTime($Opts{"after"}) // croak(qq[occurrences: invalid after ($Opts{"after"})])
_localDateTime($Opts{"after"})
Truth table50%1/2
A
A= _localDateTime($Opts{"after"})
Aresult
11
00
3052 }
3053 39 ▶ if (defined $Opts{before}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Opts{"before"}) 3 36 39
3054 3 ▶ $before = _localDateTime($Opts{before}) // croak "occurrences: invalid before ($Opts{before})";
Condition50%1/2
_localDateTime($Opts{"before"}) // croak(qq[occurrences: invalid before ($Opts{"before"})])
l!l
30
MC/DC0%0/1
_localDateTime($Opts{"before"}) // croak(qq[occurrences: invalid before ($Opts{"before"})])
_localDateTime($Opts{"before"})
Truth table50%1/2
A
A= _localDateTime($Opts{"before"})
Aresult
11
00
3055 }
3056 10140 ▶ my $inRange = sub {
Subroutine __ANON__: called CC=5 SCAR=16.2
3057 10140 my $rid = shift;
3058 10140 ▶ return 0 if defined $after and $rid lt $after;
Branch: 1 branch
BranchTrueFalseTotal
if defined $after and $rid lt $after 6 10134 10140
Condition100%3/3
defined $after and $rid lt $after
!ll&&!rl&&r
512550096
MC/DC100%2/2
defined $after and $rid lt $after
defined $after $rid lt $after
Truth table100%3/3
A and B
A= defined $afterB= $rid lt $after
ABresult
0X0
100
111
3059 10134 ▶ return 0 if defined $before and $rid ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $rid ge $before 0 10134 10134
Condition66%2/3
defined $before and $rid ge $before
!ll&&!rl&&r
1012770
MC/DC0%0/2
defined $before and $rid ge $before
defined $before $rid ge $before
Truth table66%2/3
A and B
A= defined $beforeB= $rid ge $before
ABresult
0X0
100
111
3060 10134 return 1;
3061 39 };
3062  
3063 39 ▶ my $Overrides = ref $Event->{recurrenceOverrides} eq 'HASH' ? $Event->{recurrenceOverrides} : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $Event->{'recurrenceOverrides'} eq 'HASH' ? : 3 36 39
3064 39 my (%excluded, @added);
3065 39 foreach my $key (keys %$Overrides) {
3066 6 ▶ my $rid = _localDateTime($key) // next;
Condition50%1/2
_localDateTime($key) // (next)
l!l
60
MC/DC0%0/1
_localDateTime($key) // (next)
_localDateTime($key)
Truth table50%1/2
A
A= _localDateTime($key)
Aresult
11
00
3067 6 my $Patch = $Overrides->{$key};
3068 6 ▶ if (ref $Patch eq 'HASH' and $Patch->{excluded}) { $excluded{$rid} = 1 }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $Patch eq 'HASH' and $Patch->{'excluded'}) { } 1 5 6
Condition66%2/3
ref $Patch eq "HASH" and $Patch->{"excluded"}
!ll&&!rl&&r
051
MC/DC50%1/2
ref $Patch eq "HASH" and $Patch->{"excluded"}
ref $Patch eq "HASH" $Patch->{"excluded"}
Truth table66%2/3
A and B
A= ref $Patch eq "HASH"B= $Patch->{"excluded"}
ABresult
0X0
100
111
3069 5 else { push @added, $rid }
3070 }
3071  
3072 39 my @found;
3073 39 ▶ unless (isSyntheticMaster($Event)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (isSyntheticMaster($Event)) 38 1 39
3074 38 ▶ my $start = _localDateTime($Event->{start}) // return ();
Condition50%1/2
_localDateTime($Event->{"start"}) // (return ())
l!l
380
MC/DC0%0/1
_localDateTime($Event->{"start"}) // (return ())
_localDateTime($Event->{"start"})
Truth table50%1/2
A
A= _localDateTime($Event->{"start"})
Aresult
11
00
3075 38 my $Rule = $Event->{recurrenceRule};
3076 38 ▶ $Rule = undef unless ref $Rule eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Rule eq "HASH" 1 37 38
3077 38 ▶ my $limit = defined $before ? $before : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $before ? : 3 35 38
3078 10136 ▶ my $take = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
3079 10136 my $rid = shift;
3080 10136 ▶ return 1 if $excluded{$rid} or !$inRange->($rid);
Branch: 1 branch
BranchTrueFalseTotal
if $excluded{$rid} or not &$inRange($rid) 7 10129 10136
Condition100%3/3
$excluded{$rid} or not &$inRange($rid)
l!l&&r!l&&!r
1610129
MC/DC100%2/2
$excluded{$rid} or not &$inRange($rid)
$excluded{$rid} not &$inRange($rid)
Truth table100%3/3
A or not(B)
A= $excluded{$rid}B= not &$inRange($rid)
ABresult
1X1
011
000
3081 10129 push @found, $rid;
3082 10129 return @found < $max;
3083 38 };
3084 38 ▶ if ($Rule) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Rule) { } 37 1 38
elsif (not defined $before or $start lt $before) { } 1 0 1
3085 37 _expandRule($Rule, $start, $limit, $take, $after);
3086 }
3087 ▶ elsif (!defined $before or $start lt $before) {
Condition33%1/3
not defined $before or $start lt $before
l!l&&r!l&&!r
100
MC/DC0%0/2
not defined $before or $start lt $before
not defined $before $start lt $before
Truth table33%1/3
not(A) or B
A= not defined $beforeB= $start lt $before
ABresult
1X1
011
000
3088 1 $take->($start);
3089 }
3090 }
3091  
3092 35 my %seen;
3093 35 ▶ my @all = sort grep { !$seen{$_}++ } @found, grep { !$excluded{$_} and $inRange->($_) } @added;
Condition33%1/3
!$excluded{$_} && &$inRange($_)
!ll&&!rl&&r
005
MC/DC0%0/2
!$excluded{$_} && &$inRange($_)
!$excluded{$_} &$inRange($_)
Truth table33%1/3
not(A) && B
A= !$excluded{$_}B= &$inRange($_)
ABresult
0X0
100
111
3094 35 ▶ splice @all, $max if @all > $max;
Branch: 1 branch
BranchTrueFalseTotal
if @all > $max 0 35 35
3095 35 return @all;
3096 }
3097  
3098 # A LocalDateTime in the canonical form of override keys, or undef.
3099 # A trailing Z or fraction is dropped; a bare date is its midnight.
3100 60 ▶sub _localDateTime {
Subroutine _localDateTime: called CC=5 SCAR=18.1
3101 60 my $value = shift;
3102 60 ▶ return undef unless defined $value and not ref $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and not ref $value 0 60 60
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0060
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
3103 60 ▶ return "$1T00:00:00" if $value =~ /^(\d{4}-\d\d-\d\d)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(\d{4}-\d\d-\d\d)$/ 1 59 60
3104 59 ▶ return "$1T$2" if $value =~ /^(\d{4}-\d\d-\d\d)T(\d\d:\d\d:\d\d)(?:\.\d+)?Z?$/i;
Branch: 1 branch
BranchTrueFalseTotal
if $value =~ /^(\d{4}-\d\d-\d\d)T(\d\d:\d\d:\d\d)(?:\.\d+)?Z?$/i 59 0 59
3105 0 return undef;
3106 }
3107  
3108 # --- recurrence rule expansion (jscalendarbis-22 3.3.3.1) ---------------
3109 #
3110 # Days are counted from 1970-01-01 (day 0, a Thursday); weekdays are
3111 # 0 (mo) to 6 (su). Everything is local time: recurrence ids are.
3112  
3113 19 my %DayNum = (mo => 0, tu => 1, we => 2, th => 3, fr => 4, sa => 5, su => 6);
3114  
3115 2117 ▶sub _isLeap { my $y = shift; return ($y % 4 == 0 && $y % 100 != 0) || $y % 400 == 0 }
Subroutine _isLeap: called CC=3 SCAR=11.0
Condition100%6/6
$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0
l!l&&r!l&&!r
1064221589
$y % 4 == 0 and $y % 100 != 0
!ll&&!rl&&r
1586425106
MC/DC100%3/3
$y % 4 == 0 && $y % 100 != 0 || $y % 400 == 0
$y % 4 == 0 $y % 100 != 0 $y % 400 == 0
Truth table80%4/5
A and B || C
A= $y % 4 == 0B= $y % 100 != 0C= $y % 400 == 0
ABCresult
11X1
0X11
1011
0X00
1000
3116  
3117 718 ▶sub _daysInMonth {
Subroutine _daysInMonth: called CC=3 SCAR=11.0
3118 718 my ($y, $m) = @_;
3119 718 ▶ return 29 if $m == 2 and _isLeap($y);
Branch: 1 branch
BranchTrueFalseTotal
if $m == 2 and _isLeap($y) 110 608 718
Condition100%3/3
$m == 2 and _isLeap($y)
!ll&&!rl&&r
270338110
MC/DC100%2/2
$m == 2 and _isLeap($y)
$m == 2 _isLeap($y)
Truth table100%3/3
A and B
A= $m == 2B= _isLeap($y)
ABresult
0X0
100
111
3120 608 return (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$m - 1];
3121 }
3122  
3123 # days from civil and back (H. Hinnant's algorithms)
3124 9800 ▶sub _dayNumber {
Subroutine _dayNumber: called CC=4 SCAR=13.9
3125 9800 my ($y, $m, $d) = @_;
3126 9800 ▶ $y -= 1 if $m <= 2;
Branch: 1 branch
BranchTrueFalseTotal
if $m <= 2 6885 2915 9800
3127 9800 ▶ my $era = int(($y >= 0 ? $y : $y - 399) / 400);
Branch: 1 branch
BranchTrueFalseTotal
$y >= 0 ? : 9800 0 9800
3128 9800 my $yoe = $y - $era * 400;
3129 9800 ▶ my $doy = int((153 * ($m + ($m > 2 ? -3 : 9)) + 2) / 5) + $d - 1;
Branch: 1 branch
BranchTrueFalseTotal
$m > 2 ? : 2915 6885 9800
3130 9800 my $doe = $yoe * 365 + int($yoe / 4) - int($yoe / 100) + $doy;
3131 9800 return $era * 146097 + $doe - 719468;
3132 }
3133  
3134 1291566 ▶sub _civil {
Subroutine _civil: called CC=4 SCAR=13.9
3135 1291566 my $z = shift() + 719468;
3136 1291566 ▶ my $era = int(($z >= 0 ? $z : $z - 146096) / 146097);
Branch: 1 branch
BranchTrueFalseTotal
$z >= 0 ? : 1291566 0 1291566
3137 1291566 my $doe = $z - $era * 146097;
3138 1291566 my $yoe = int(($doe - int($doe / 1460) + int($doe / 36524) - int($doe / 146096)) / 365);
3139 1291566 my $y = $yoe + $era * 400;
3140 1291566 my $doy = $doe - (365 * $yoe + int($yoe / 4) - int($yoe / 100));
3141 1291566 my $mp = int((5 * $doy + 2) / 153);
3142 1291566 my $d = $doy - int((153 * $mp + 2) / 5) + 1;
3143 1291566 ▶ my $m = $mp + ($mp < 10 ? 3 : -9);
Branch: 1 branch
BranchTrueFalseTotal
$mp < 10 ? : 517686 773880 1291566
3144 1291566 ▶ return ($y + ($m <= 2 ? 1 : 0), $m, $d);
Branch: 1 branch
BranchTrueFalseTotal
$m <= 2 ? : 773880 517686 1291566
3145 }
3146  
3147 7232 ▶sub _weekday { return (shift() + 3) % 7 } # day 0 was a Thursday
Subroutine _weekday: called CC=1 SCAR=0.0
3148  
3149 # The week number (and its year) of a day, weeks starting on $wkst, week
3150 # 1 being the first with four days in the year; and how many weeks that
3151 # year has.
3152 5114 ▶sub _weekNo {
Subroutine _weekNo: called CC=1 SCAR=0.0
3153 5114 my ($day, $wkst) = @_;
3154 5114 my $weekStart = $day - ((_weekday($day) - $wkst) % 7);
3155 5114 my ($wy) = _civil($weekStart + 3);
3156 5114 my $ordinal = $weekStart + 3 - _dayNumber($wy, 1, 1);
3157 5114 return (int($ordinal / 7) + 1, $wy);
3158 }
3159  
3160 2557 ▶sub _weeksInYear {
Subroutine _weeksInYear: called CC=1 SCAR=0.0
3161 2557 my ($y, $wkst) = @_;
3162 2557 my ($n) = _weekNo(_dayNumber($y, 12, 28), $wkst);
3163 2557 return $n;
3164 }
3165  
3166 384 ▶sub _list {
Subroutine _list: called CC=3 SCAR=11.0
3167 384 my $v = shift;
3168 384 ▶ return undef unless ref $v eq 'ARRAY' and @$v;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $v eq "ARRAY" and @$v 349 35 384
Condition66%2/3
ref $v eq "ARRAY" and @$v
!ll&&!rl&&r
349035
MC/DC50%1/2
ref $v eq "ARRAY" and @$v
ref $v eq "ARRAY" @$v
Truth table66%2/3
A and B
A= ref $v eq "ARRAY"B= @$v
ABresult
0X0
100
111
3169 35 return $v;
3170 }
3171  
3172 # Calls $take->($recurrenceId) for each occurrence of $Rule from $start
3173 # (the start itself first, always), in order, until it returns false,
3174 # the rule ends, an occurrence reaches $before, or 400 years pass
3175 # without one.
3176 37 ▶sub _expandRule {
Subroutine _expandRule: called CC=102 SCAR=49.5
3177 37 my ($Rule, $start, $before, $take, $after) = @_;
3178  
3179 37 ▶ my $freq = lc($Rule->{frequency} // '');
Condition50%1/2
$Rule->{"frequency"} // ""
l!l
370
MC/DC0%0/1
$Rule->{"frequency"} // ""
$Rule->{"frequency"}
Truth table50%1/2
A
A= $Rule->{"frequency"}
Aresult
11
00
3180 37 ▶ croak "recurrence frequency ($freq) is not valid" unless $ValidFrequency{$freq};
Branch: 1 branch
BranchTrueFalseTotal
unless $ValidFrequency{$freq} 0 37 37
3181 37 ▶ my $rscale = lc($Rule->{rscale} // 'gregorian');
Condition100%2/2
$Rule->{"rscale"} // "gregorian"
l!l
433
MC/DC100%1/1
$Rule->{"rscale"} // "gregorian"
$Rule->{"rscale"}
Truth table100%2/2
A
A= $Rule->{"rscale"}
Aresult
11
00
3182 37 ▶ croak "recurrence rscale $rscale is not supported" unless $rscale eq 'gregorian';
Branch: 1 branch
BranchTrueFalseTotal
unless $rscale eq "gregorian" 1 36 37
3183 36 ▶ my $skip = lc($Rule->{skip} // 'omit');
Condition100%2/2
$Rule->{"skip"} // "omit"
l!l
333
MC/DC100%1/1
$Rule->{"skip"} // "omit"
$Rule->{"skip"}
Truth table100%2/2
A
A= $Rule->{"skip"}
Aresult
11
00
3184 36 ▶ my $interval = $Rule->{interval} // 1;
Condition100%2/2
$Rule->{"interval"} // 1
l!l
729
MC/DC100%1/1
$Rule->{"interval"} // 1
$Rule->{"interval"}
Truth table100%2/2
A
A= $Rule->{"interval"}
Aresult
11
00
3185 36 ▶ croak "recurrence interval ($interval) is not valid" unless $interval =~ /^\d+$/ and $interval >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $interval =~ /^\d+$/ and $interval >= 1 0 36 36
Condition33%1/3
$interval =~ /^\d+$/ and $interval >= 1
!ll&&!rl&&r
0036
MC/DC0%0/2
$interval =~ /^\d+$/ and $interval >= 1
$interval =~ /^\d+$/ $interval >= 1
Truth table33%1/3
A and B
A= $interval =~ /^\d+$/B= $interval >= 1
ABresult
0X0
100
111
3186 36 ▶ my $wkst = $DayNum{lc($Rule->{firstDayOfWeek} // 'mo')} // croak 'recurrence firstDayOfWeek is not valid';
Condition75%3/4
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")} // croak("recurrence firstDayOfWeek is not valid")
l!l
360
$Rule->{"firstDayOfWeek"} // "mo"
l!l
135
MC/DC0%0/1
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")} // croak("recurrence firstDayOfWeek is not valid")
$DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")}
MC/DC100%1/1
$Rule->{"firstDayOfWeek"} // "mo"
$Rule->{"firstDayOfWeek"}
Truth table50%1/2
A
A= $DayNum{lc($Rule->{"firstDayOfWeek"} // "mo")}
Aresult
11
00
Truth table100%2/2
A
A= $Rule->{"firstDayOfWeek"}
Aresult
11
00
3187 36 my $count = $Rule->{count};
3188 36 ▶ croak "recurrence count ($count) is not valid" if defined $count and $count !~ /^\d+$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $count and not $count =~ /^\d+$/ 0 36 36
Condition66%2/3
defined $count and not $count =~ /^\d+$/
!ll&&!rl&&r
12240
MC/DC0%0/2
defined $count and not $count =~ /^\d+$/
defined $count not $count =~ /^\d+$/
Truth table66%2/3
A and not(B)
A= defined $countB= not $count =~ /^\d+$/
ABresult
0X0
100
111
3189 36 my $until;
3190 36 ▶ if (defined $Rule->{until}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $Rule->{"until"}) 2 34 36
3191 2 ▶ $until = _localDateTime($Rule->{until}) // croak "recurrence until ($Rule->{until}) is not valid";
Condition50%1/2
_localDateTime($Rule->{"until"}) // croak(qq[recurrence until ($Rule->{"until"}) is not valid])
l!l
20
MC/DC0%0/1
_localDateTime($Rule->{"until"}) // croak(qq[recurrence until ($Rule->{"until"}) is not valid])
_localDateTime($Rule->{"until"})
Truth table50%1/2
A
A= _localDateTime($Rule->{"until"})
Aresult
11
00
3192 }
3193  
3194 36 my ($sy, $sm, $sd, $sH, $sM, $sS) = $start =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/;
3195 36 $_ += 0 for $sy, $sm, $sd, $sH, $sM, $sS;
3196 36 my $startDay = _dayNumber($sy, $sm, $sd);
3197  
3198 # the rule's parts, numbers checked, and those implied by the start
3199 36 my %by;
3200 36 foreach my $name (qw(byMonthDay byYearDay byWeekNo byHour byMinute bySecond bySetPosition)) {
3201 252 ▶ my $list = _list($Rule->{$name}) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $list = _list($Rule->{$name}) or next 15 237 252
3202 15 ▶ $by{$name} = [ map { croak "recurrence $name ($_) is not valid" unless defined $_ and /^[-+]?\d+$/; 0 + $_ } @$list ];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_ and /^[-+]?\d+$/ 0 2020 2020
Condition33%1/3
defined $_ and /^[-+]?\d+$/
!ll&&!rl&&r
002020
MC/DC0%0/2
defined $_ and /^[-+]?\d+$/
defined $_ /^[-+]?\d+$/
Truth table33%1/3
A and B
A= defined $_B= /^[-+]?\d+$/
ABresult
0X0
100
111
3203 }
3204 # RFC 5545 S3.3.10's ranges (a negative day counts from the end), and no
3205 # list longer than any calendar could need: a rule is untrusted input,
3206 # and every entry is work in every period
3207 36 my %range = (byHour => [0, 23], byMinute => [0, 59], bySecond => [0, 60],
3208 byMonthDay => [-31, 31], byYearDay => [-366, 366], byWeekNo => [-53, 53],
3209 bySetPosition => [-366, 366]);
3210 36 foreach my $name (keys %range) {
3211 247 ▶ next unless $by{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless $by{$name} 232 15 247
3212 15 ▶ croak "recurrence $name has too many entries" if @{$by{$name}} > $MaxRuleList;
Branch: 1 branch
BranchTrueFalseTotal
if @{$by{$name};} > $Text::JSCalendar::MaxRuleList 1 14 15
3213 croak "recurrence $name is out of range"
3214 14 ▶ if grep { $_ < $range{$name}[0] or $_ > $range{$name}[1] or $_ == 0 && $range{$name}[0] < 0 } @{$by{$name}};
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ < $range{$name}[0] or $_ > $range{$name}[1] or $_ == 0 and $range{$name}[0] < 0;} @{$by{$name};} 2 12 14
Condition66%6/9
$_ < $range{$name}[0] || $_ > $range{$name}[1] || $_ == 0 && $range{$name}[0] < 0
l!l&&r!l&&!r
3017
$_ < $range{$name}[0] or $_ > $range{$name}[1]
l!l&&r!l&&!r
0317
$_ == 0 and $range{$name}[0] < 0
!ll&&!rl&&r
1610
MC/DC25%1/4
$_ < $range{$name}[0] || $_ > $range{$name}[1] || $_ == 0 && $range{$name}[0] < 0
$_ < $range{$name}[0] $_ > $range{$name}[1] $_ == 0 $range{$name}[0] < 0
Truth table60%3/5
A or B || C and D
A= $_ < $range{$name}[0]B= $_ > $range{$name}[1]C= $_ == 0D= $range{$name}[0] < 0
ABCDresult
1XXX1
01XX1
00111
000X0
00100
3215 }
3216 33 foreach my $name (qw(byMonth byDay)) {
3217 66 ▶ my $list = _list($Rule->{$name}) or next;
Branch: 1 branch
BranchTrueFalseTotal
my $list = _list($Rule->{$name}) or next 10 56 66
3218 10 ▶ croak "recurrence $name has too many entries" if @$list > $MaxRuleList;
Branch: 1 branch
BranchTrueFalseTotal
if @$list > $Text::JSCalendar::MaxRuleList 0 10 10
3219 }
3220 33 ▶ if (my $list = _list($Rule->{byMonth})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = _list($Rule->{"byMonth"})) 2 31 33
3221 # a leap month ("5L") never matches in the Gregorian calendar
3222 2 ▶ $by{byMonth} = { map { (defined $_ and /^(\d+)$/) ? (0 + $1 => 1) : () } @$list };
Branch: 1 branch
BranchTrueFalseTotal
defined $_ && /^(\d+)$/ ? : 2 0 2
Condition33%1/3
defined $_ and /^(\d+)$/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $_ and /^(\d+)$/
defined $_ /^(\d+)$/
Truth table33%1/3
A and B
A= defined $_B= /^(\d+)$/
ABresult
0X0
100
111
3223 }
3224 33 ▶ if (my $list = _list($Rule->{byDay})) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $list = _list($Rule->{"byDay"})) 8 25 33
3225 $by{byDay} = [ map {
3226 8 ▶ croak 'recurrence byDay is not valid' unless ref $_ eq 'HASH' and defined $_->{day} and exists $DayNum{lc $_->{day}};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}} 0 15 15
Condition33%2/6
ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}}
!ll&&!rl&&r
0015
ref $_ eq "HASH" and defined $_->{"day"}
!ll&&!rl&&r
0015
MC/DC0%0/3
ref $_ eq "HASH" and defined $_->{"day"} and exists $DayNum{lc $_->{"day"}}
ref $_ eq "HASH" defined $_->{"day"} exists $DayNum{lc $_->{"day"}}
Truth table25%1/4
A and B and C
A= ref $_ eq "HASH"B= defined $_->{"day"}C= exists $DayNum{lc $_->{"day"}}
ABCresult
0XX0
10X0
1100
1111
3227 15 ▶ [ $DayNum{lc $_->{day}}, $_->{nthOfPeriod} ? 0 + $_->{nthOfPeriod} : 0 ];
Branch: 1 branch
BranchTrueFalseTotal
$_->{'nthOfPeriod'} ? : 4 11 15
3228 } @$list ];
3229 }
3230 33 my $startDow = _weekday($startDay);
3231 33 ▶ $by{bySecond} //= [$sS] unless $freq eq 'secondly';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" 30 3 33
Condition50%1/2
$by{"bySecond"} //= [$sS]
l!l
030
MC/DC0%0/1
$by{"bySecond"} //= [$sS]
$by{"bySecond"}
Truth table50%1/2
A
A= $by{"bySecond"}
Aresult
11
00
3232 33 ▶ $by{byMinute} //= [$sM] unless $freq eq 'secondly' or $freq eq 'minutely';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" or $freq eq "minutely" 28 5 33
Condition100%5/5
$freq eq "secondly" or $freq eq "minutely"
l!l&&r!l&&!r
3228
$by{"byMinute"} //= [$sM]
l!l
127
MC/DC100%2/2
$freq eq "secondly" or $freq eq "minutely"
$freq eq "secondly" $freq eq "minutely"
MC/DC100%1/1
$by{"byMinute"} //= [$sM]
$by{"byMinute"}
Truth table100%3/3
A or B
A= $freq eq "secondly"B= $freq eq "minutely"
ABresult
1X1
011
000
Truth table100%2/2
A
A= $by{"byMinute"}
Aresult
11
00
3233 33 ▶ $by{byHour} //= [$sH] unless $freq eq 'secondly' or $freq eq 'minutely' or $freq eq 'hourly';
Branch: 1 branch
BranchTrueFalseTotal
unless $freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly" 26 7 33
Condition100%8/8
$freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly"
l!l&&r!l&&!r
5226
$freq eq "secondly" or $freq eq "minutely"
l!l&&r!l&&!r
3228
$by{"byHour"} //= [$sH]
l!l
125
MC/DC100%3/3
$freq eq "secondly" or $freq eq "minutely" or $freq eq "hourly"
$freq eq "secondly" $freq eq "minutely" $freq eq "hourly"
MC/DC100%1/1
$by{"byHour"} //= [$sH]
$by{"byHour"}
Truth table100%4/4
A or B or C
A= $freq eq "secondly"B= $freq eq "minutely"C= $freq eq "hourly"
ABCresult
1XX1
01X1
0011
0000
Truth table100%2/2
A
A= $by{"byHour"}
Aresult
11
00
3234 33 ▶ if ($freq eq 'weekly' and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "weekly" and not $by{"byDay"}) 1 32 33
Condition100%3/3
$freq eq "weekly" and not $by{"byDay"}
!ll&&!rl&&r
3021
MC/DC100%2/2
$freq eq "weekly" and not $by{"byDay"}
$freq eq "weekly" not $by{"byDay"}
Truth table100%3/3
A and not(B)
A= $freq eq "weekly"B= not $by{"byDay"}
ABresult
0X0
100
111
3235 1 $by{byDay} = [[$startDow, 0]];
3236 }
3237 33 ▶ if ($freq eq 'monthly' and !$by{byDay} and !$by{byMonthDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}) 2 31 33
Condition100%6/6
$freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}
!ll&&!rl&&r
2922
$freq eq "monthly" and not $by{"byDay"}
!ll&&!rl&&r
2634
MC/DC100%3/3
$freq eq "monthly" and not $by{"byDay"} and not $by{"byMonthDay"}
$freq eq "monthly" not $by{"byDay"} not $by{"byMonthDay"}
Truth table100%4/4
A and not(B) and not(C)
A= $freq eq "monthly"B= not $by{"byDay"}C= not $by{"byMonthDay"}
ABCresult
0XX0
10X0
1100
1111
3238 2 $by{byMonthDay} = [$sd];
3239 }
3240 33 ▶ if ($freq eq 'yearly' and !$by{byYearDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "yearly" and not $by{"byYearDay"}) 7 26 33
Condition100%3/3
$freq eq "yearly" and not $by{"byYearDay"}
!ll&&!rl&&r
2517
MC/DC100%2/2
$freq eq "yearly" and not $by{"byYearDay"}
$freq eq "yearly" not $by{"byYearDay"}
Truth table100%3/3
A and not(B)
A= $freq eq "yearly"B= not $by{"byYearDay"}
ABresult
0X0
100
111
3241 7 ▶ if (!$by{byMonth} and !$by{byWeekNo} and ($by{byMonthDay} or !$by{byDay})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}) 2 5 7
Condition88%8/9
not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}
!ll&&!rl&&r
412
$by{'byMonth'} || $by{'byWeekNo'}
l!l&&r!l&&!r
223
$by{"byMonthDay"} or not $by{"byDay"}
l!l&&r!l&&!r
021
MC/DC75%3/4
not $by{"byMonth"} || $by{"byWeekNo"} and $by{"byMonthDay"} || !$by{"byDay"}
$by{'byMonth'} $by{'byWeekNo'} $by{"byMonthDay"} not $by{"byDay"}
Truth table80%4/5
not(A || B) and C or not(D)
A= $by{'byMonth'}B= $by{'byWeekNo'}C= $by{"byMonthDay"}D= not $by{"byDay"}
ABCDresult
1XXX0
01XX0
00000
001X1
00011
3242 2 $by{byMonth} = { $sm => 1 };
3243 }
3244 7 ▶ if (!$by{byMonthDay} and !$by{byWeekNo} and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}) 2 5 7
Condition100%6/6
$by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}
l!l&&r!l&&!r
322
$by{"byMonthDay"} or $by{"byWeekNo"}
l!l&&r!l&&!r
124
MC/DC100%3/3
$by{"byMonthDay"} or $by{"byWeekNo"} or $by{"byDay"}
$by{"byMonthDay"} $by{"byWeekNo"} $by{"byDay"}
Truth table100%4/4
A or B or C
A= $by{"byMonthDay"}B= $by{"byWeekNo"}C= $by{"byDay"}
ABCresult
1XX1
01X1
0011
0000
3245 2 $by{byMonthDay} = [$sd];
3246 }
3247 7 ▶ if ($by{byWeekNo} and !$by{byMonthDay} and !$by{byDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}) 1 6 7
Condition83%5/6
$by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}
!ll&&!rl&&r
511
$by{"byWeekNo"} and not $by{"byMonthDay"}
!ll&&!rl&&r
502
MC/DC66%2/3
$by{"byWeekNo"} and not $by{"byMonthDay"} and not $by{"byDay"}
$by{"byWeekNo"} not $by{"byMonthDay"} not $by{"byDay"}
Truth table75%3/4
A and not(B) and not(C)
A= $by{"byWeekNo"}B= not $by{"byMonthDay"}C= not $by{"byDay"}
ABCresult
0XX0
10X0
1100
1111
3248 1 $by{byDay} = [[$startDow, 0]];
3249 }
3250 }
3251 33 ▶ my $nthInYear = ($freq eq 'yearly' and !$by{byMonth});
Condition100%3/3
$freq eq 'yearly' && !$by{'byMonth'}
!ll&&!rl&&r
2544
MC/DC100%2/2
$freq eq 'yearly' && !$by{'byMonth'}
$freq eq 'yearly' !$by{'byMonth'}
Truth table100%3/3
A && not(B)
A= $freq eq 'yearly'B= !$by{'byMonth'}
ABresult
0X0
100
111
3252 33 ▶ my %inList = map { $_ => { map { $_ => 1 } @{$by{$_} || []} } } qw(byHour byMinute bySecond);
Condition100%2/2
$by{$_} || []
l!l
8613
MC/DC100%1/1
$by{$_} || []
$by{$_}
Truth table100%2/2
A
A= $by{$_}
Aresult
11
00
3253  
3254 # does a (valid) day pass byMonth, byWeekNo, byYearDay, byMonthDay?
3255 516132 ▶ my $dayMatchesUpToMonthDay = sub {
Subroutine __ANON__: called CC=14 SCAR=26.5
3256 516132 my ($day, $y, $m, $d, $skipMonthDay) = @_;
3257 516132 ▶ return 0 if $by{byMonth} and !$by{byMonth}{$m};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byMonth"} and not $by{"byMonth"}{$m} 0 516132 516132
Condition66%2/3
$by{"byMonth"} and not $by{"byMonth"}{$m}
!ll&&!rl&&r
516065670
MC/DC0%0/2
$by{"byMonth"} and not $by{"byMonth"}{$m}
$by{"byMonth"} not $by{"byMonth"}{$m}
Truth table66%2/3
A and not(B)
A= $by{"byMonth"}B= not $by{"byMonth"}{$m}
ABresult
0X0
100
111
3258 516132 ▶ if ($by{byWeekNo}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byWeekNo"}) 2557 513575 516132
3259 2557 my ($wn, $wy) = _weekNo($day, $wkst);
3260 2557 my $total = _weeksInYear($wy, $wkst);
3261 2557 ▶ return 0 unless grep { $_ > 0 ? $_ == $wn : $total + 1 + $_ == $wn } @{$by{byWeekNo}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $wn : $total + 1 + $_ == $wn;} @{$by{"byWeekNo"};} 2508 49 2557
$_ > 0 ? : 1461 1096 2557
3262 }
3263 513624 ▶ if ($by{byYearDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byYearDay"}) 1461 512163 513624
3264 1461 my $yd = $day - _dayNumber($y, 1, 1) + 1;
3265 1461 ▶ my $diy = _isLeap($y) ? 366 : 365;
Branch: 1 branch
BranchTrueFalseTotal
_isLeap($y) ? : 366 1095 1461
3266 1461 ▶ return 0 unless grep { $_ > 0 ? $_ == $yd : $diy + 1 + $_ == $yd } @{$by{byYearDay}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $yd : $diy + 1 + $_ == $yd;} @{$by{"byYearDay"};} 1449 12 1461
$_ > 0 ? : 4383 0 4383
3267 }
3268 512175 ▶ if ($by{byMonthDay} and !$skipMonthDay) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byMonthDay"} and not $skipMonthDay) 16 512159 512175
Condition100%3/3
$by{"byMonthDay"} and not $skipMonthDay
!ll&&!rl&&r
512152716
MC/DC100%2/2
$by{"byMonthDay"} and not $skipMonthDay
$by{"byMonthDay"} not $skipMonthDay
Truth table100%3/3
A and not(B)
A= $by{"byMonthDay"}B= not $skipMonthDay
ABresult
0X0
100
111
3269 16 my $dim = _daysInMonth($y, $m);
3270 16 ▶ return 0 unless grep { $_ > 0 ? $_ == $d : $dim + 1 + $_ == $d } @{$by{byMonthDay}};
Branch: 2 branches
BranchTrueFalseTotal
unless grep {$_ > 0 ? $_ == $d : $dim + 1 + $_ == $d;} @{$by{"byMonthDay"};} 0 16 16
$_ > 0 ? : 9 7 16
3271 }
3272 512175 return 1;
3273 33 };
3274 512182 ▶ my $dayMatchesByDay = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
3275 512182 my ($day, $y, $m, $d) = @_;
3276 512182 ▶ return 1 unless $by{byDay};
Branch: 1 branch
BranchTrueFalseTotal
unless $by{"byDay"} 510108 2074 512182
3277 2074 my $dow = _weekday($day);
3278 2074 foreach my $bd (@{$by{byDay}}) {
3279 2462 ▶ next unless $bd->[0] == $dow;
Branch: 1 branch
BranchTrueFalseTotal
unless $bd->[0] == $dow 2095 367 2462
3280 367 ▶ return 1 unless $bd->[1];
Branch: 1 branch
BranchTrueFalseTotal
unless $bd->[1] 97 270 367
3281 270 ▶ my ($pos, $len) = $nthInYear
Branch: 2 branches
BranchTrueFalseTotal
$nthInYear ? : 208 62 270
_isLeap($y) ? : 52 156 208
3282 ? ($day - _dayNumber($y, 1, 1) + 1, _isLeap($y) ? 366 : 365)
3283 : ($d, _daysInMonth($y, $m));
3284 270 ▶ my $n = $bd->[1] > 0 ? int(($pos - 1) / 7) + 1 : -(int(($len - $pos) / 7) + 1);
Branch: 1 branch
BranchTrueFalseTotal
$bd->[1] > 0 ? : 256 14 270
3285 270 ▶ return 1 if $n == $bd->[1];
Branch: 1 branch
BranchTrueFalseTotal
if $n == $bd->[1] 19 251 270
3286 }
3287 1958 return 0;
3288 33 };
3289  
3290 # the candidate days of a year or month when skip moves invalid dates
3291 # (jscalendarbis-22 3.3.3.1, step 2): byMonthDay is applied to every
3292 # month as if it had 31 days, and an invalid date moves
3293 33 ▶ my $skipping = ($skip ne 'omit' and $by{byMonthDay} and ($freq eq 'yearly' or $freq eq 'monthly'));
Condition66%6/9
$skip ne 'omit' && $by{'byMonthDay'} && ($freq eq 'yearly' || $freq eq 'monthly')
!ll&&!rl&&r
3003
$skip ne "omit" and $by{"byMonthDay"}
!ll&&!rl&&r
3003
$freq eq "yearly" or $freq eq "monthly"
l!l&&r!l&&!r
120
MC/DC25%1/4
$skip ne 'omit' && $by{'byMonthDay'} && ($freq eq 'yearly' || $freq eq 'monthly')
$skip ne "omit" $by{"byMonthDay"} $freq eq "yearly" $freq eq "monthly"
Truth table60%3/5
A and B && C or D
A= $skip ne "omit"B= $by{"byMonthDay"}C= $freq eq "yearly"D= $freq eq "monthly"
ABCDresult
0XXX0
10XX0
11000
111X1
11011
3294 14 ▶ my $skipDays = sub {
Subroutine __ANON__: called CC=15 SCAR=29.9
3295 14 my ($y, @months) = @_;
3296 14 my %days;
3297 14 foreach my $m (@months) {
3298 58 ▶ next if $by{byMonth} and !$by{byMonth}{$m};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byMonth"} and not $by{"byMonth"}{$m} 44 14 58
Condition100%3/3
$by{"byMonth"} and not $by{"byMonth"}{$m}
!ll&&!rl&&r
10444
MC/DC100%2/2
$by{"byMonth"} and not $by{"byMonth"}{$m}
$by{"byMonth"} not $by{"byMonth"}{$m}
Truth table100%3/3
A and not(B)
A= $by{"byMonth"}B= not $by{"byMonth"}{$m}
ABresult
0X0
100
111
3299 14 my $dim = _daysInMonth($y, $m);
3300 14 foreach my $v (@{$by{byMonthDay}}) {
3301 14 my $day;
3302 14 ▶ if ($v > 0 and $v <= $dim) { $day = _dayNumber($y, $m, $v) }
Branch: 2 branches
BranchTrueFalseTotal
if ($v > 0 and $v <= $dim) { } 7 7 14
elsif ($v < 0 and $dim + 1 + $v >= 1) { } 0 7 7
Condition66%2/3
$v > 0 and $v <= $dim
!ll&&!rl&&r
077
MC/DC50%1/2
$v > 0 and $v <= $dim
$v > 0 $v <= $dim
Truth table66%2/3
A and B
A= $v > 0B= $v <= $dim
ABresult
0X0
100
111
3303 0 ▶ elsif ($v < 0 and $dim + 1 + $v >= 1) { $day = _dayNumber($y, $m, $dim + 1 + $v) }
Condition33%1/3
$v < 0 and $dim + 1 + $v >= 1
!ll&&!rl&&r
700
MC/DC0%0/2
$v < 0 and $dim + 1 + $v >= 1
$v < 0 $dim + 1 + $v >= 1
Truth table33%1/3
A and B
A= $v < 0B= $dim + 1 + $v >= 1
ABresult
0X0
100
111
3304 else {
3305 # invalid: byWeekNo and byYearDay never match it
3306 7 ▶ next if $by{byWeekNo} or $by{byYearDay};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byWeekNo"} or $by{"byYearDay"} 0 7 7
Condition33%1/3
$by{"byWeekNo"} or $by{"byYearDay"}
l!l&&r!l&&!r
007
MC/DC0%0/2
$by{"byWeekNo"} or $by{"byYearDay"}
$by{"byWeekNo"} $by{"byYearDay"}
Truth table33%1/3
A or B
A= $by{"byWeekNo"}B= $by{"byYearDay"}
ABresult
1X1
011
000
3307 7 ▶ if ($v > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($v > 0) { } 7 0 7
3308 7 ▶ $day = $skip eq 'forward' ? _dayNumber($y, $m, $dim) + 1 : _dayNumber($y, $m, $dim);
Branch: 1 branch
BranchTrueFalseTotal
$skip eq 'forward' ? : 5 2 7
3309 }
3310 else {
3311 0 ▶ $day = $skip eq 'forward' ? _dayNumber($y, $m, 1) : _dayNumber($y, $m, 1) - 1;
Branch: 1 branch
BranchTrueFalseTotal
$skip eq 'forward' ? : 0 0 0
3312 }
3313 7 $days{$day} = 1;
3314 7 next;
3315 }
3316 7 my (undef, undef, $d) = _civil($day);
3317 7 ▶ $days{$day} = 1 if $dayMatchesUpToMonthDay->($day, $y, $m, $d, 1);
Branch: 1 branch
BranchTrueFalseTotal
if &$dayMatchesUpToMonthDay($day, $y, $m, $d, 1) 7 0 7
3318 }
3319 }
3320 0 return grep { $dayMatchesByDay->($_, _civil($_)) } sort { $a <=> $b } keys %days;
3321 33 };
3322  
3323 # the days of a period that pass every date filter
3324 510273 ▶ my $daysOf = sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
3325 510273 my ($first, $last) = @_;
3326 510273 my @days;
3327 510273 for my $day ($first .. $last) {
3328 516109 my ($y, $m, $d) = _civil($day);
3329 516109 ▶ push @days, $day if $dayMatchesUpToMonthDay->($day, $y, $m, $d) and $dayMatchesByDay->($day, $y, $m, $d);
Branch: 1 branch
BranchTrueFalseTotal
if &$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d) 510194 5915 516109
Condition100%3/3
&$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d)
!ll&&!rl&&r
39571958510194
MC/DC100%2/2
&$dayMatchesUpToMonthDay($day, $y, $m, $d) and &$dayMatchesByDay($day, $y, $m, $d)
&$dayMatchesUpToMonthDay($day, $y, $m, $d) &$dayMatchesByDay($day, $y, $m, $d)
Truth table100%3/3
A and B
A= &$dayMatchesUpToMonthDay($day, $y, $m, $d)B= &$dayMatchesByDay($day, $y, $m, $d)
ABresult
0X0
100
111
3330 }
3331 510273 return @days;
3332 33 };
3333  
3334 # the days of the given months of year $y that pass every date filter:
3335 # $daysOf over only the months byMonth allows, or, with byMonthDay (and
3336 # no byWeekNo or byYearDay to widen it), straight from its values -- not
3337 # every day of the year tested in turn
3338 461 ▶ my $daysOfMonths = sub {
Subroutine __ANON__: called CC=11 SCAR=24.4
3339 461 my ($y, @months) = @_;
3340 461 ▶ @months = grep { $by{byMonth}{$_} } @months if $by{byMonth};
Branch: 1 branch
BranchTrueFalseTotal
if $by{"byMonth"} 417 44 461
3341 461 ▶ if ($by{byMonthDay} and !$by{byWeekNo} and !$by{byYearDay}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"byMonthDay"} and not $by{"byWeekNo"} and not $by{"byYearDay"}) 430 31 461
Condition66%4/6
$by{"byMonthDay"} and not $by{"byWeekNo"} and not $by{"byYearDay"}
!ll&&!rl&&r
310430
$by{"byMonthDay"} and not $by{"byWeekNo"}
!ll&&!rl&&r
310430
MC/DC33%1/3
$by{"byMonthDay"} and not $by{"byWeekNo"} and not $by{"byYearDay"}
$by{"byMonthDay"} not $by{"byWeekNo"} not $by{"byYearDay"}
Truth table50%2/4
A and not(B) and not(C)
A= $by{"byMonthDay"}B= not $by{"byWeekNo"}C= not $by{"byYearDay"}
ABCresult
0XX0
10X0
1100
1111
3342 430 my %days;
3343 430 foreach my $m (@months) {
3344 430 my $dim = _daysInMonth($y, $m);
3345 430 foreach my $v (@{$by{byMonthDay}}) {
3346 430 ▶ my $d = $v > 0 ? $v : $dim + 1 + $v;
Branch: 1 branch
BranchTrueFalseTotal
$v > 0 ? : 423 7 430
3347 430 ▶ $days{_dayNumber($y, $m, $d)} = 1 if $d >= 1 and $d <= $dim;
Branch: 1 branch
BranchTrueFalseTotal
if $d >= 1 and $d <= $dim 16 414 430
Condition66%2/3
$d >= 1 and $d <= $dim
!ll&&!rl&&r
041416
MC/DC50%1/2
$d >= 1 and $d <= $dim
$d >= 1 $d <= $dim
Truth table66%2/3
A and B
A= $d >= 1B= $d <= $dim
ABresult
0X0
100
111
3348 }
3349 }
3350 16 ▶ return grep { my @c = _civil($_); $dayMatchesUpToMonthDay->($_, @c) and $dayMatchesByDay->($_, @c) }
Condition33%1/3
&$dayMatchesUpToMonthDay($_, @c) && &$dayMatchesByDay($_, @c)
!ll&&!rl&&r
0016
MC/DC0%0/2
&$dayMatchesUpToMonthDay($_, @c) && &$dayMatchesByDay($_, @c)
&$dayMatchesUpToMonthDay($_, @c) &$dayMatchesByDay($_, @c)
Truth table33%1/3
A && B
A= &$dayMatchesUpToMonthDay($_, @c)B= &$dayMatchesByDay($_, @c)
ABresult
0X0
100
111
3351 0 sort { $a <=> $b } keys %days;
3352 }
3353 31 return map { $daysOf->(_dayNumber($y, $_, 1), _dayNumber($y, $_, _daysInMonth($y, $_))) } @months;
3354 33 };
3355  
3356 33 my @hours = sort { $a <=> $b } keys %{$inList{byHour}};
3357 33 my @minutes = sort { $a <=> $b } keys %{$inList{byMinute}};
3358 0 my @seconds = sort { $a <=> $b } keys %{$inList{bySecond}};
3359 770306 ▶ my $fmt = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
3360 770306 my ($day, $H, $M, $S) = @_;
3361 770306 my ($y, $m, $d) = _civil($day);
3362 770306 return sprintf('%04d-%02d-%02dT%02d:%02d:%02d', $y, $m, $d, $H, $M, $S);
3363 33 };
3364  
3365 # the candidates of period $n, in order
3366 33 my $periodStart; # the first date-time of the period, as a string
3367 my $noDays; # no day of the period passed the date filters
3368 510552 ▶ my $candidates = sub {
Subroutine __ANON__: called CC=26 SCAR=32.8
3369 510552 my $n = shift;
3370 510552 my (@days, @H, @M, @S);
3371 510552 @H = @hours; @M = @minutes; @S = @seconds;
3372 510552 ▶ if ($freq eq 'yearly') {
Branch: 4 branches
BranchTrueFalseTotal
if ($freq eq 'yearly') { } 436 510116 510552
elsif ($freq eq 'monthly') { } 39 510077 510116
elsif ($freq eq 'weekly') { } 11 510066 510077
elsif ($freq eq 'daily') { } 5039 505027 510066
3373 436 my $y = $sy + $n * $interval;
3374 436 $periodStart = sprintf('%04d-01-01T00:00:00', $y);
3375 436 ▶ @days = $skipping ? $skipDays->($y, 1 .. 12) : $daysOfMonths->($y, 1 .. 12);
Branch: 1 branch
BranchTrueFalseTotal
$skipping ? : 4 432 436
3376 }
3377 elsif ($freq eq 'monthly') {
3378 39 my $mi = ($sy * 12 + $sm - 1) + $n * $interval;
3379 39 my ($y, $m) = (int($mi / 12), $mi % 12 + 1);
3380 39 $periodStart = sprintf('%04d-%02d-01T00:00:00', $y, $m);
3381 39 ▶ @days = $skipping ? $skipDays->($y, $m) : $daysOfMonths->($y, $m);
Branch: 1 branch
BranchTrueFalseTotal
$skipping ? : 10 29 39
3382 }
3383 elsif ($freq eq 'weekly') {
3384 11 my $first = $startDay - ((_weekday($startDay) - $wkst) % 7) + 7 * $n * $interval;
3385 11 $periodStart = $fmt->($first, 0, 0, 0);
3386 11 @days = $daysOf->($first, $first + 6);
3387 }
3388 elsif ($freq eq 'daily') {
3389 5039 my $day = $startDay + $n * $interval;
3390 5039 $periodStart = $fmt->($day, 0, 0, 0);
3391 5039 @days = $daysOf->($day, $day);
3392 }
3393 else {
3394 505027 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3395 505027 my $t = (($startDay * 24 + $sH) * 60 + $sM) * 60 + $sS;
3396 505027 $t -= $t % $unit;
3397 505027 $t += $n * $interval * $unit;
3398 505027 my $day = int($t / 86400);
3399 505027 ▶ $day-- if $t < 0 and $t % 86400;
Branch: 1 branch
BranchTrueFalseTotal
if $t < 0 and $t % 86400 0 505027 505027
Condition33%1/3
$t < 0 and $t % 86400
!ll&&!rl&&r
50502700
MC/DC0%0/2
$t < 0 and $t % 86400
$t < 0 $t % 86400
Truth table33%1/3
A and B
A= $t < 0B= $t % 86400
ABresult
0X0
100
111
3400 505027 my $secs = $t - $day * 86400;
3401 505027 my ($H, $M, $S) = (int($secs / 3600), int(($secs % 3600) / 60), $secs % 60);
3402 505027 ▶ $periodStart = $fmt->($day, $H, $M, $freq eq 'secondly' ? $S : 0);
Branch: 1 branch
BranchTrueFalseTotal
$freq eq 'secondly' ? : 255011 250016 505027
3403 505027 @days = $daysOf->($day, $day);
3404 505027 ▶ @H = $inList{byHour}{$H} || !%{$inList{byHour}} ? ($H) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'byHour'}{$H} || !%{$inList{'byHour'};} ? : 505027 0 505027
Condition66%2/3
$inList{"byHour"}{$H} or not %{$inList{"byHour"};}
l!l&&r!l&&!r
55050220
MC/DC0%0/2
$inList{"byHour"}{$H} or not %{$inList{"byHour"};}
$inList{"byHour"}{$H} not %{$inList{"byHour"};}
Truth table66%2/3
A or not(B)
A= $inList{"byHour"}{$H}B= not %{$inList{"byHour"};}
ABresult
1X1
011
000
3405 505027 ▶ if ($freq ne 'hourly') {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq ne "hourly") 505017 10 505027
3406 505017 ▶ @M = $inList{byMinute}{$M} || !%{$inList{byMinute}} ? ($M) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'byMinute'}{$M} || !%{$inList{'byMinute'};} ? : 505017 0 505017
Condition33%1/3
$inList{"byMinute"}{$M} or not %{$inList{"byMinute"};}
l!l&&r!l&&!r
05050170
MC/DC0%0/2
$inList{"byMinute"}{$M} or not %{$inList{"byMinute"};}
$inList{"byMinute"}{$M} not %{$inList{"byMinute"};}
Truth table33%1/3
A or not(B)
A= $inList{"byMinute"}{$M}B= not %{$inList{"byMinute"};}
ABresult
1X1
011
000
3407 }
3408 505027 ▶ if ($freq eq 'secondly') {
Branch: 1 branch
BranchTrueFalseTotal
if ($freq eq "secondly") 255011 250016 505027
3409 255011 ▶ @S = $inList{bySecond}{$S} || !%{$inList{bySecond}} ? ($S) : ();
Branch: 1 branch
BranchTrueFalseTotal
$inList{'bySecond'}{$S} || !%{$inList{'bySecond'};} ? : 5010 250001 255011
Condition66%2/3
$inList{"bySecond"}{$S} or not %{$inList{"bySecond"};}
l!l&&r!l&&!r
05010250001
MC/DC50%1/2
$inList{"bySecond"}{$S} or not %{$inList{"bySecond"};}
$inList{"bySecond"}{$S} not %{$inList{"bySecond"};}
Truth table66%2/3
A or not(B)
A= $inList{"bySecond"}{$S}B= not %{$inList{"bySecond"};}
ABresult
1X1
011
000
3410 }
3411 }
3412 510552 $noDays = !@days;
3413 510552 my @out;
3414 510552 foreach my $day (@days) {
3415 510224 foreach my $H (@H) {
3416 510226 foreach my $M (@M) {
3417 510230 push @out, map { $fmt->($day, $H, $M, $_) } @S;
3418 }
3419 }
3420 }
3421 510552 ▶ if ($by{bySetPosition}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($by{"bySetPosition"}) 250004 260548 510552
3422 250004 my @keep;
3423 250004 foreach my $p (@{$by{bySetPosition}}) {
3424 250004 ▶ my $i = $p > 0 ? $p - 1 : @out + $p;
Branch: 1 branch
BranchTrueFalseTotal
$p > 0 ? : 250001 3 250004
3425 250004 ▶ push @keep, $out[$i] if $i >= 0 and $i < @out;
Branch: 1 branch
BranchTrueFalseTotal
if $i >= 0 and $i < @out 3 250001 250004
Condition66%2/3
$i >= 0 and $i < @out
!ll&&!rl&&r
02500013
MC/DC50%1/2
$i >= 0 and $i < @out
$i >= 0 $i < @out
Truth table66%2/3
A and B
A= $i >= 0B= $i < @out
ABresult
0X0
100
111
3426 }
3427 250004 my %u;
3428 250004 @out = sort grep { !$u{$_}++ } @keep;
3429 }
3430 510552 return @out;
3431 33 };
3432  
3433 33 my $produced = 0;
3434 33 my %seen;
3435 10185 ▶ my $emit = sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
3436 10185 my $rid = shift;
3437 10185 ▶ return 1 if $seen{$rid}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen{$rid}++ 26 10159 10185
3438 10159 ▶ return 0 if defined $until and $rid gt $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $rid gt $until 0 10159 10159
Condition66%2/3
defined $until and $rid gt $until
!ll&&!rl&&r
1015270
MC/DC0%0/2
defined $until and $rid gt $until
defined $until $rid gt $until
Truth table66%2/3
A and B
A= defined $untilB= $rid gt $until
ABresult
0X0
100
111
3439 10159 ▶ return 0 if defined $before and $rid ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $rid ge $before 1 10158 10159
Condition100%3/3
defined $before and $rid ge $before
!ll&&!rl&&r
10146121
MC/DC100%2/2
defined $before and $rid ge $before
defined $before $rid ge $before
Truth table100%3/3
A and B
A= defined $beforeB= $rid ge $before
ABresult
0X0
100
111
3440 10158 ▶ return 0 if defined $count and $produced >= $count;
Branch: 1 branch
BranchTrueFalseTotal
if defined $count and $produced >= $count 23 10135 10158
Condition100%3/3
defined $count and $produced >= $count
!ll&&!rl&&r
5031510423
MC/DC100%2/2
defined $count and $produced >= $count
defined $count $produced >= $count
Truth table100%3/3
A and B
A= defined $countB= $produced >= $count
ABresult
0X0
100
111
3441 10135 $produced++;
3442 10135 ▶ return $take->($rid) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&$take($rid) ? : 10132 3 10135
3443 33 };
3444  
3445 # the start is always the first occurrence
3446 33 ▶ return unless $emit->($start);
Branch: 1 branch
BranchTrueFalseTotal
unless &$emit($start) 0 33 33
3447  
3448 # how many periods may pass without an occurrence: 400 years' worth
3449 my $idle = { yearly => 400, monthly => 4800, weekly => 20871, daily => 146097,
3450 33 hourly => 3506328, minutely => 210379680, secondly => 12622780800 }->{$freq};
3451 33 $idle = int($idle / $interval) + 1;
3452 33 my $sinceLast = 0;
3453 # a sub-daily rule on a day no date filter lets through skips the day
3454 33 ▶ my $subDaily = ($freq eq 'hourly' or $freq eq 'minutely' or $freq eq 'secondly');
Condition100%6/6
$freq eq 'hourly' || $freq eq 'minutely' || $freq eq 'secondly'
l!l&&r!l&&!r
4326
$freq eq "hourly" or $freq eq "minutely"
l!l&&r!l&&!r
2229
MC/DC100%3/3
$freq eq 'hourly' || $freq eq 'minutely' || $freq eq 'secondly'
$freq eq "hourly" $freq eq "minutely" $freq eq 'secondly'
Truth table100%4/4
A or B || C
A= $freq eq "hourly"B= $freq eq "minutely"C= $freq eq 'secondly'
ABCresult
1XX1
01X1
0011
0000
3455  
3456 # without a count, the periods before the one holding $after cannot
3457 # matter: start there (one early, for a date a skip moved forward)
3458 33 my $n0 = 0;
3459 33 ▶ if (defined $after and !defined $count and $after gt $start) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $after and not defined $count and $after gt $start) 2 31 33
Condition100%6/6
defined $after and not defined $count and $after gt $start
!ll&&!rl&&r
3012
defined $after and not defined $count
!ll&&!rl&&r
2823
MC/DC100%3/3
defined $after and not defined $count and $after gt $start
defined $after not defined $count $after gt $start
Truth table100%4/4
A and not(B) and C
A= defined $afterB= not defined $countC= $after gt $start
ABCresult
0XX0
10X0
1100
1111
3460 2 my ($ay, $am, $ad, $aH, $aM, $aS) = map { 0 + $_ } $after =~ /^(\d+)-(\d+)-(\d+)T(\d+):(\d+):(\d+)$/;
3461 2 my $aDay = _dayNumber($ay, $am, $ad);
3462 2 my $steps;
3463 0 ▶ if ($freq eq 'yearly') { $steps = ($ay - $sy) }
Branch: 4 branches
BranchTrueFalseTotal
if ($freq eq 'yearly') { } 0 2 2
elsif ($freq eq 'monthly') { } 0 2 2
elsif ($freq eq 'weekly') { } 0 2 2
elsif ($freq eq 'daily') { } 1 1 2
3464 0 elsif ($freq eq 'monthly') { $steps = ($ay * 12 + $am) - ($sy * 12 + $sm) }
3465 0 elsif ($freq eq 'weekly') { $steps = int(($aDay - $startDay) / 7) }
3466 1 elsif ($freq eq 'daily') { $steps = $aDay - $startDay }
3467 else {
3468 1 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3469 1 my $secs = ((($aDay - $startDay) * 24 + $aH - $sH) * 60 + $aM - $sM) * 60 + $aS - $sS;
3470 1 $steps = int($secs / $unit);
3471 }
3472 2 $n0 = int($steps / $interval) - 1;
3473 2 ▶ $n0 = 0 if $n0 < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n0 < 0 0 2 2
3474 }
3475  
3476 # a hard bound on the work one expansion may do: whatever the rule, it
3477 # ends after this many periods and candidates looked at
3478 33 my $work = 0;
3479 33 for (my $n = $n0; ; $n++) {
3480 510552 my @c = $candidates->($n);
3481 510552 ▶ return if ($work += 1 + @c) > $MaxExpandWork;
Branch: 1 branch
BranchTrueFalseTotal
if ($work += 1 + @c) > $Text::JSCalendar::MaxExpandWork 2 510550 510552
3482 510550 ▶ return if defined $until and $periodStart gt $until;
Branch: 1 branch
BranchTrueFalseTotal
if defined $until and $periodStart gt $until 2 510548 510550
Condition100%3/3
defined $until and $periodStart gt $until
!ll&&!rl&&r
51054172
MC/DC100%2/2
defined $until and $periodStart gt $until
defined $until $periodStart gt $until
Truth table100%3/3
A and B
A= defined $untilB= $periodStart gt $until
ABresult
0X0
100
111
3483 510548 ▶ return if defined $before and $periodStart ge $before;
Branch: 1 branch
BranchTrueFalseTotal
if defined $before and $periodStart ge $before 1 510547 510548
Condition100%3/3
defined $before and $periodStart ge $before
!ll&&!rl&&r
2605372500101
MC/DC100%2/2
defined $before and $periodStart ge $before
defined $before $periodStart ge $before
Truth table100%3/3
A and B
A= defined $beforeB= $periodStart ge $before
ABresult
0X0
100
111
3484 510547 my $any = 0;
3485 510547 foreach my $rid (@c) {
3486 10154 ▶ next if $rid lt $start;
Branch: 1 branch
BranchTrueFalseTotal
if $rid lt $start 2 10152 10154
3487 10152 $any = 1;
3488 10152 ▶ return unless $emit->($rid);
Branch: 1 branch
BranchTrueFalseTotal
unless &$emit($rid) 27 10125 10152
3489 }
3490 510520 ▶ if ($any) { $sinceLast = 0 }
Branch: 4 branches
BranchTrueFalseTotal
if ($any) { } 10105 500415 510520
elsif (++$sinceLast > $idle) { } 1 500414 500415
elsif ($subDaily and $noDays) { } 0 500414 500414
elsif ($subDaily and not @c) { } 500000 828 500828
3491 1 elsif (++$sinceLast > $idle) { return }
3492 ▶ elsif ($subDaily and $noDays) {
Condition66%2/3
$subDaily and $noDays
!ll&&!rl&&r
4145000000
MC/DC0%0/2
$subDaily and $noDays
$subDaily $noDays
Truth table66%2/3
A and B
A= $subDailyB= $noDays
ABresult
0X0
100
111
3493 # jump to the last period that starts on this day
3494 0 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3495 0 my ($H, $M, $S) = $periodStart =~ /T(\d\d):(\d\d):(\d\d)$/;
3496 0 my $left = int((86400 - ($H * 3600 + $M * 60 + $S) - 1) / ($unit * $interval));
3497 0 $n += $left;
3498 0 $sinceLast += $left;
3499 }
3500 ▶ elsif ($subDaily and !@c) {
Condition66%2/3
$subDaily and not @c
!ll&&!rl&&r
4140500000
MC/DC50%1/2
$subDaily and not @c
$subDaily not @c
Truth table66%2/3
A and not(B)
A= $subDailyB= not @c
ABresult
0X0
100
111
3501 # the day passed but this period's hour (or minute) did not: jump to
3502 # the last period that starts before the next allowed one, as above
3503 # for a day (MINUTELY;BYHOUR=9 looked at every minute of the day)
3504 500000 my $unit = { hourly => 3600, minutely => 60, secondly => 1 }->{$freq};
3505 500000 my ($H, $M, $S) = map { 0 + $_ } $periodStart =~ /T(\d\d):(\d\d):(\d\d)$/;
3506 500000 my $now = $H * 3600 + $M * 60 + $S;
3507 500000 my $next;
3508 500000 ▶ if (%{$inList{byHour}} and !$inList{byHour}{$H}) {
Branch: 2 branches
BranchTrueFalseTotal
if (%{$inList{'byHour'};} and not $inList{'byHour'}{$H}) { } 0 500000 500000
elsif ($freq ne 'hourly' and %{$inList{'byMinute'};} and not $inList{'byMinute'}{$M}) { } 0 1000000 1000000
Condition33%1/3
%{$inList{"byHour"};} and not $inList{"byHour"}{$H}
!ll&&!rl&&r
50000000
MC/DC0%0/2
%{$inList{"byHour"};} and not $inList{"byHour"}{$H}
%{$inList{"byHour"};} not $inList{"byHour"}{$H}
Truth table33%1/3
A and not(B)
A= %{$inList{"byHour"};}B= not $inList{"byHour"}{$H}
ABresult
0X0
100
111
3509 0 my ($h) = grep { $_ > $H } @hours;
3510 0 ▶ $next = defined $h ? $h * 3600 : 86400;
Branch: 1 branch
BranchTrueFalseTotal
defined $h ? : 0 0 0
3511 }
3512 500000 ▶ elsif ($freq ne 'hourly' and %{$inList{byMinute}} and !$inList{byMinute}{$M}) {
Condition33%2/6
$freq ne "hourly" and %{$inList{"byMinute"};} and not $inList{"byMinute"}{$M}
!ll&&!rl&&r
50000000
$freq ne "hourly" and %{$inList{"byMinute"};}
!ll&&!rl&&r
05000000
MC/DC0%0/3
$freq ne "hourly" and %{$inList{"byMinute"};} and not $inList{"byMinute"}{$M}
$freq ne "hourly" %{$inList{"byMinute"};} not $inList{"byMinute"}{$M}
Truth table25%1/4
A and B and not(C)
A= $freq ne "hourly"B= %{$inList{"byMinute"};}C= not $inList{"byMinute"}{$M}
ABCresult
0XX0
10X0
1100
1111
3513 0 my ($m) = grep { $_ > $M } @minutes;
3514 0 ▶ $next = $H * 3600 + (defined $m ? $m * 60 : 3600);
Branch: 1 branch
BranchTrueFalseTotal
defined $m ? : 0 0 0
3515 }
3516 500000 ▶ if (defined $next) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $next) 0 500000 500000
3517 0 my $left = int(($next - $now - 1) / ($unit * $interval));
3518 0 $n += $left;
3519 0 $sinceLast += $left;
3520 }
3521 }
3522 }
3523 }
3524  
3525 # Order two instances by their RECURRENCE-ID (then DTSTART)
3526 5 ▶sub _compareInstances {
Subroutine _compareInstances: called CC=9 SCAR=34.1
3527 5 my ($A, $B) = @_;
3528 5 my ($ra, $rb) = map { $_->{_recurrenceObj} } $A, $B;
3529 5 ▶ if ($ra and $rb) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ra and $rb) 5 0 5
Condition33%1/3
$ra and $rb
!ll&&!rl&&r
005
MC/DC0%0/2
$ra and $rb
$ra $rb
Truth table33%1/3
A and B
A= $raB= $rb
ABresult
0X0
100
111
3530 5 my $c = DateTime->compare($ra, $rb);
3531 5 ▶ return $c if $c;
Branch: 1 branch
BranchTrueFalseTotal
if $c 5 0 5
3532 }
3533 0 ▶ return ($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{start} // '') cmp ($B->{start} // '');
Branch: 2 branches
BranchTrueFalseTotal
$ra ? : 0 0 0
$rb ? : 0 0 0
Condition0%0/7
($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{'start'} // '') cmp ($B->{'start'} // '')
l!l&&r!l&&!r
000
$A->{"start"} // ""
l!l
00
$B->{"start"} // ""
l!l
00
MC/DC0%0/2
($ra ? 0 : 1) <=> ($rb ? 0 : 1) || ($A->{'start'} // '') cmp ($B->{'start'} // '')
($ra ? 0 : 1) <=> ($rb ? 0 : 1) $A->{"start"}
MC/DC0%0/1
$B->{"start"} // ""
$B->{"start"}
Truth table0%0/3
A || B
A= ($ra ? 0 : 1) <=> ($rb ? 0 : 1)B= $A->{"start"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $B->{"start"}
Aresult
11
00
3534 }
3535  
3536 119 ▶sub _quotekey {
Subroutine _quotekey: called CC=1 SCAR=0.0
3537 119 my $key = shift;
3538 119 $key =~ s/\~/~0/gs;
3539 119 $key =~ s/\//~1/gs;
3540 119 return $key;
3541 }
3542  
3543 249 ▶sub _unquotekey {
Subroutine _unquotekey: called CC=1 SCAR=0.0
3544 249 my $key = shift;
3545 249 $key =~ s/\~1/\//gs;
3546 249 $key =~ s/\~0/~/gs;
3547 249 return $key;
3548 }
3549  
3550 119 ▶sub _add_override {
Subroutine _add_override: called CC=8 SCAR=20.9
3551 119 my ($override, $prefix, $New, $Old) = @_;
3552  
3553 # basic case - it's not an object, so we just override
3554 119 ▶ if (ref($New) ne 'HASH' or ref($Old) ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $New ne "HASH" or ref $Old ne "HASH") 92 27 119
Condition100%3/3
ref $New ne "HASH" or ref $Old ne "HASH"
l!l&&r!l&&!r
722027
MC/DC100%2/2
ref $New ne "HASH" or ref $Old ne "HASH"
ref $New ne "HASH" ref $Old ne "HASH"
Truth table100%3/3
A or B
A= ref $New ne "HASH"B= ref $Old ne "HASH"
ABresult
1X1
011
000
3555 92 $override->{$prefix} = $New;
3556 92 return;
3557 }
3558  
3559 # XXX - if too many, we could just abort...
3560 27 my %subover;
3561 27 my %oldkeys = map { $_ => 1 } keys %$Old;
3562 27 foreach my $Key (sort keys %$New) {
3563 80 delete $oldkeys{$Key};
3564 80 ▶ next if _safeeq($New->{$Key}, $Old->{$Key});
Branch: 1 branch
BranchTrueFalseTotal
if _safeeq($New->{$Key}, $Old->{$Key}) 53 27 80
3565 27 _add_override(\%subover, "$prefix/" . _quotekey($Key), $New->{$Key}, $Old->{$Key});
3566 }
3567 27 foreach my $Key (sort keys %oldkeys) {
3568 0 $subover{"$prefix/" . _quotekey($Key)} = $JSON::null;
3569 }
3570  
3571 # which one is better?
3572 27 ▶ if (length(encode_json($New)) < length(encode_json(\%subover))) {
Branch: 1 branch
BranchTrueFalseTotal
if (length &encode_json($New) < length &encode_json(\%subover)) { } 0 27 27
3573 0 $override->{$prefix} = $New; # cheaper to just encode the whole object
3574 }
3575 else {
3576 27 $override->{$_} = $subover{$_} for keys %subover;
3577 }
3578 }
3579  
3580 114 ▶sub _apply_patch {
Subroutine _apply_patch: called CC=5 SCAR=16.1
3581 114 my $path = shift;
3582 114 my $hash = shift;
3583 114 my $value = shift;
3584  
3585 114 ▶ return unless $path =~ s{^([^/]+)(/?)}{};
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ s[^([^/]+)(/?)][] 0 114 114
3586 114 ▶ return unless ref($hash) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $hash eq "HASH" 0 114 114
3587 114 my $qkey = $1;
3588 114 my $slash = $2;
3589 114 my $key = _unquotekey($qkey);
3590 114 ▶ if ($slash) {
Branch: 2 branches
BranchTrueFalseTotal
if ($slash) { } 24 90 114
elsif (defined $value) { } 84 6 90
3591 24 _apply_patch($path, $hash->{$key}, $value);
3592 }
3593 elsif(defined $value) {
3594 84 $hash->{$key} = $value;
3595 }
3596 else {
3597 6 delete $hash->{$key};
3598 }
3599 }
3600  
3601 44 ▶sub _maximise {
Subroutine _maximise: called CC=4 SCAR=13.9
3602 44 my $Self = shift;
3603 44 my $Event = shift;
3604 44 my $Recurrence = shift;
3605 44 my $recurrenceId = shift;
3606  
3607 # a copy of the master without its rule and overrides (copying them for
3608 # every override and then dropping them made writing an event O(N^2) in
3609 # its overrides)
3610 44 my %master = %$Event;
3611 44 delete @master{'recurrenceRule', 'recurrenceOverrides', SYNTHETIC_MASTER()};
3612 44 my $new = _deepcopy(\%master);
3613 44 $new->{start} = $recurrenceId;
3614  
3615 44 foreach my $path (sort keys %$Recurrence) {
3616 # overrides can't change the identity or type of the master event
3617 97 my ($first) = $path =~ m{^([^/]*)};
3618 97 my $key = _unquotekey($first);
3619 97 ▶ next if $MustBeTopLevel{$key};
Branch: 1 branch
BranchTrueFalseTotal
if $MustBeTopLevel{$key} 5 92 97
3620 92 ▶ next if $path =~ m{^participants/[^/]+/calendarAddress$};
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[^participants/[^/]+/calendarAddress$] 2 90 92
3621 90 my $value = $Recurrence->{$path};
3622 90 _apply_patch($path, $new, $value);
3623 }
3624  
3625 44 return $new;
3626 }
3627  
3628 0 ▶sub _stripNonICal {
Subroutine _stripNonICal: not called CC=4 SCAR=30.0
3629 0 my $Self = shift;
3630 0 my $Event = shift;
3631  
3632 0 delete $Event->{alerts};
3633 0 delete $Event->{participants};
3634 0 delete $Event->{organizerCalendarAddress};
3635  
3636 0 ▶ foreach my $exception (values %{$Event->{recurrenceOverrides} || {}}) {
Condition0%0/2
$Event->{'recurrenceOverrides'} || {}
l!l
00
MC/DC0%0/1
$Event->{'recurrenceOverrides'} || {}
$Event->{'recurrenceOverrides'}
Truth table0%0/2
A
A= $Event->{'recurrenceOverrides'}
Aresult
11
00
3637 0 ▶ next unless ref($exception) eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $exception eq "HASH" 0 0 0
3638 0 $Self->_stripNonICal($exception);
3639 }
3640 }
3641  
3642 1518 ▶sub _safeeq {
Subroutine _safeeq: called CC=1 SCAR=0.0
3643 1518 my ($a, $b) = @_;
3644 1518 my $json = JSON::XS->new->canonical;
3645 1518 return $json->encode([$a]) eq $json->encode([$b]);
3646 }
3647  
3648 44 ▶sub _deepcopy {
Subroutine _deepcopy: called CC=1 SCAR=0.0
3649 44 my $data = shift;
3650 44 my $json = JSON::XS->new->canonical;
3651 44 my $enc = $json->encode([$data]);
3652 44 my $copy = $json->decode($enc);
3653 44 return $copy->[0];
3654 }
3655  
3656  
3657 =head1 AUTHOR
3658  
3659 Bron Gondwana, C<< <brong at cpan.org> >>
3660  
3661 =head1 LICENSE AND COPYRIGHT
3662  
3663 Copyright 2019-2026 Fastmail Pty Ltd.
3664  
3665 This program is free software; you can redistribute it and/or modify it
3666 under the same terms as Perl itself; that is, either the GNU General
3667 Public License as published by the Free Software Foundation (version 1,
3668 or at your option any later version), or the Artistic License.
3669  
3670 See L<http://dev.perl.org/licenses/> and the LICENSE file included with
3671 this distribution for more information.
3672  
3673 =cut
3674  
3675 19 1; # End of Text::JSCalendar
« JSCalendar/TimeZones.pm ↑ Summary