lib/Acme/PM/Berlin/Meetings.pm

filter: Statementstmt 22.5% 14 / 62 Branchbran 0.0% 0 / 24 Conditioncond 5.8% 1 / 17 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 50.0% 4 / 8 Podpod 0.0% 0 / 2 totaltotal 15.3% 19 / 124 CC 19 SCAR 47.5
CC
19
Cov
15%
next_meeting_dt
210.0
_get_dec_meeting
12.0
_get_last_wed_of_month
6.0
CRAP 115.7
↑ Summary script/berlin-pm »
1 # -*- perl -*-
2  
3 #
4 # Author: Slaven Rezic
5 #
6 # Copyright (C) 2010,2012,2015,2016,2017,2020 Slaven Rezic. All rights reserved.
7 # This package is free software; you can redistribute it and/or
8 # modify it under the same terms as Perl itself.
9 #
10 # Mail: slaven@rezic.de
11 # WWW: http://www.rezic.de/eserte/
12 #
13  
14 package Acme::PM::Berlin::Meetings;
15  
16 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 our $VERSION = '202009.26';
18  
19 4 ▶use Exporter 'import'; # needs Exporter 5.57
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 our @EXPORT = qw(next_meeting);
21  
22 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 sub next_meeting {
25 3 ▶ my $count = shift || 1;
Subroutine next_meeting: called CC=2 SCAR=9.2
Pod undocumented
Condition50%1/2
shift() || 1
l!l
30
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
26 3 my $dt = DateTime->now(time_zone => 'local');
27 0 map { $dt = next_meeting_dt($dt) } (1 .. $count);
28 }
29  
30 sub next_meeting_dt {
31 0 ▶ my $dt = shift;
Subroutine next_meeting_dt: not called CC=14 SCAR=53.5
Pod undocumented
32 0 my $dt_berlin = $dt->clone->set_time_zone('Europe/Berlin');
33  
34 # Regular exception: December meeting is in January
35 0 ▶ if ($dt_berlin->month == 1 && $dt_berlin->day < 10) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt_berlin->month == 1 and $dt_berlin->day < 10) 0 0 0
Condition0%0/3
$dt_berlin->month == 1 and $dt_berlin->day < 10
!ll&&!rl&&r
000
MC/DC0%0/2
$dt_berlin->month == 1 and $dt_berlin->day < 10
$dt_berlin->month == 1 $dt_berlin->day < 10
Truth table0%0/3
A and B
A= $dt_berlin->month == 1B= $dt_berlin->day < 10
ABresult
0X0
100
111
36 0 my $dec_meeting = _get_dec_meeting($dt_berlin);
37 0 ▶ if ($dec_meeting > $dt_berlin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dec_meeting > $dt_berlin) 0 0 0
38 0 return $dec_meeting;
39 }
40 }
41  
42 # Exceptions
43 {
44 # August 2020 (last Wed -> last Tue)
45 0 my $dt_aug_2020 = DateTime->new(year=>2020, month=>8, day=>25, hour=>19, time_zone=>"Europe/Berlin");
46 0 my $dt_aug_2020_from = DateTime->new(year=>2020, month=>7, day=>29, hour=>19, time_zone=>"Europe/Berlin");
47 0 my $dt_aug_2020_until = DateTime->new(year=>2020, month=>8, day=>26, hour=>19, time_zone=>"Europe/Berlin");
48 0 ▶ if ($dt_berlin > $dt_aug_2020_from && $dt_berlin < $dt_aug_2020) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dt_berlin > $dt_aug_2020_from and $dt_berlin < $dt_aug_2020) { } 0 0 0
elsif ($dt_berlin >= $dt_aug_2020 and $dt_berlin < $dt_aug_2020_until) { } 0 0 0
Condition0%0/3
$dt_berlin > $dt_aug_2020_from and $dt_berlin < $dt_aug_2020
!ll&&!rl&&r
000
MC/DC0%0/2
$dt_berlin > $dt_aug_2020_from and $dt_berlin < $dt_aug_2020
$dt_berlin > $dt_aug_2020_from $dt_berlin < $dt_aug_2020
Truth table0%0/3
A and B
A= $dt_berlin > $dt_aug_2020_fromB= $dt_berlin < $dt_aug_2020
ABresult
0X0
100
111
49 0 return $dt_aug_2020;
50 ▶ } elsif ($dt_berlin >= $dt_aug_2020 && $dt_berlin < $dt_aug_2020_until) {
Condition0%0/3
$dt_berlin >= $dt_aug_2020 and $dt_berlin < $dt_aug_2020_until
!ll&&!rl&&r
000
MC/DC0%0/2
$dt_berlin >= $dt_aug_2020 and $dt_berlin < $dt_aug_2020_until
$dt_berlin >= $dt_aug_2020 $dt_berlin < $dt_aug_2020_until
Truth table0%0/3
A and B
A= $dt_berlin >= $dt_aug_2020B= $dt_berlin < $dt_aug_2020_until
ABresult
0X0
100
111
51 0 $dt_berlin = $dt_aug_2020_until;
52 }
53 }
54 {
55 # September 2020 (last Wed, 19h -> pre-last Wed, 18h)
56 0 my $dt_sep_2020 = DateTime->new(year=>2020, month=>9, day=>23, hour=>18, time_zone=>"Europe/Berlin");
57 0 my $dt_sep_2020_from = DateTime->new(year=>2020, month=>8, day=>25, hour=>19, time_zone=>"Europe/Berlin");
58 0 my $dt_sep_2020_until = DateTime->new(year=>2020, month=>9, day=>30, hour=>19, time_zone=>"Europe/Berlin");
59 0 ▶ if ($dt_berlin > $dt_sep_2020_from && $dt_berlin < $dt_sep_2020) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dt_berlin > $dt_sep_2020_from and $dt_berlin < $dt_sep_2020) { } 0 0 0
elsif ($dt_berlin >= $dt_sep_2020 and $dt_berlin < $dt_sep_2020_until) { } 0 0 0
Condition0%0/3
$dt_berlin > $dt_sep_2020_from and $dt_berlin < $dt_sep_2020
!ll&&!rl&&r
000
MC/DC0%0/2
$dt_berlin > $dt_sep_2020_from and $dt_berlin < $dt_sep_2020
$dt_berlin > $dt_sep_2020_from $dt_berlin < $dt_sep_2020
Truth table0%0/3
A and B
A= $dt_berlin > $dt_sep_2020_fromB= $dt_berlin < $dt_sep_2020
ABresult
0X0
100
111
60 0 return $dt_sep_2020;
61 ▶ } elsif ($dt_berlin >= $dt_sep_2020 && $dt_berlin < $dt_sep_2020_until) {
Condition0%0/3
$dt_berlin >= $dt_sep_2020 and $dt_berlin < $dt_sep_2020_until
!ll&&!rl&&r
000
MC/DC0%0/2
$dt_berlin >= $dt_sep_2020 and $dt_berlin < $dt_sep_2020_until
$dt_berlin >= $dt_sep_2020 $dt_berlin < $dt_sep_2020_until
Truth table0%0/3
A and B
A= $dt_berlin >= $dt_sep_2020B= $dt_berlin < $dt_sep_2020_until
ABresult
0X0
100
111
62 0 $dt_berlin = $dt_sep_2020_until;
63 }
64 }
65  
66 # Regular meetings
67 0 my $last_wed_of_month = _get_last_wed_of_month($dt_berlin);
68 0 ▶ if ($last_wed_of_month <= $dt_berlin) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_wed_of_month <= $dt_berlin) 0 0 0
69 0 $dt_berlin->add(months => 1, end_of_month => 'limit');
70 0 $last_wed_of_month = _get_last_wed_of_month($dt_berlin);
71 }
72 0 ▶ if ($last_wed_of_month->month == 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_wed_of_month->month == 12) 0 0 0
73 0 return _get_dec_meeting($last_wed_of_month);
74 }
75 0 $last_wed_of_month;
76 }
77  
78 sub _get_last_wed_of_month {
79 0 ▶ my $dt_berlin = shift;
Subroutine _get_last_wed_of_month: not called CC=2 SCAR=17.9
80 0 my $last_day_of_month = DateTime->last_day_of_month(year => $dt_berlin->year, month => $dt_berlin->month, time_zone => 'Europe/Berlin');
81 0 my $dow = $last_day_of_month->day_of_week;
82 0 ▶ my $last_wed_of_month = $last_day_of_month->add(days => $dow < 3 ? -$dow-4 : -$dow+3);
Branch: 1 branch
BranchTrueFalseTotal
$dow < 3 ? : 0 0 0
83 0 _adjust_hour($last_wed_of_month);
84 0 $last_wed_of_month;
85 }
86  
87 sub _get_dec_meeting {
88 0 ▶ my $dt = shift;
Subroutine _get_dec_meeting: not called CC=3 SCAR=24.8
89 0 $dt = $dt->clone;
90 0 ▶ if ($dt->month == 12) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->month == 12) 0 0 0
91 0 $dt->add(months => 1); # end_of_month does not matter
92 }
93 0 $dt->set(day => 3);
94 0 my $dow = $dt->day_of_week;
95 0 ▶ $dt->add(days => $dow < 4 ? -$dow+3 : -$dow+10);
Branch: 1 branch
BranchTrueFalseTotal
$dow < 4 ? : 0 0 0
96 0 _adjust_hour($dt);
97 0 $dt;
98 }
99  
100 sub _adjust_hour {
101 0 ▶ my $dt = shift;
Subroutine _adjust_hour: not called CC=2 SCAR=17.9
102 0 ▶ if ($dt->year >= 2016) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->year >= 2016) { } 0 0 0
103 0 $dt->set(hour => 19);
104 } else {
105 0 $dt->set(hour => 20);
106 }
107 }
108  
109 4 1;
110  
111 __END__
112  
113 =head1 NAME
114  
115 Acme::PM::Berlin::Meetings - get the next date of the Berlin PM meeting
116  
117 =head1 SYNOPSIS
118  
119 use Acme::PM::Berlin::Meetings;
120 next_meeting(1)
121  
122 Or use the bundled script:
123  
124 berlin-pm
125  
126 =head1 NOTES
127  
128 This module knows about special Berlin.PM traditions like postponing
129 the December meeting to the first or second week in January.
130  
131 =head1 AUTHOR
132  
133 Slaven Rezic
134  
135 =head1 SEE ALSO
136  
137 L<Acme::PM::Barcelona::Meeting>, L<Acme::PM::Paris::Meetings>.
138  
139 =cut
↑ Summary script/berlin-pm »