| 1 | # -*- perl -*- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # Author: Slaven Rezic | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | # Copyright (C) 2010,2012,2015,2016,2017,2020,2024 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 = '202402.28'; | |||||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | sub next_meeting { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_meeting: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 3 | ▶ | my $count = shift || 1; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 3 | my $dt = DateTime->now(time_zone => 'local'); | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | map { $dt = next_meeting_dt($dt) } (1 .. $count); | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub next_meeting_dt { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
next_meeting_dt: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$dt_berlin->month == 1 and $dt_berlin->day < 10
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | my $dec_meeting = _get_dec_meeting($dt_berlin); | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if ($dec_meeting > $dt_berlin) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$dt_berlin > $dt_aug_2020_from and $dt_berlin < $dt_aug_2020
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
$dt_berlin > $dt_sep_2020_from and $dt_berlin < $dt_sep_2020
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return _get_dec_meeting($last_wed_of_month); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $last_wed_of_month; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub _get_last_wed_of_month { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_last_wed_of_month: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $dt_berlin = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | _adjust_hour($last_wed_of_month); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $last_wed_of_month; | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub _get_dec_meeting { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_dec_meeting: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $dt = $dt->clone; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | if ($dt->month == 12) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | _adjust_hour($dt); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $dt; | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub _adjust_hour { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_adjust_hour: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $dt = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | if ($dt->year >= 2024 || ($dt->year == 2023 && $dt->month >= 5)) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$dt->year >= 2024 or $dt->year == 2023 and $dt->month >= 5
$dt->year == 2023 and $dt->month >= 5
MC/DC0%0/3
$dt->year >= 2024 or $dt->year == 2023 and $dt->month >= 5
$dt->year >= 2024
$dt->year == 2023
$dt->month >= 5
Truth table0%0/4
A or B and C
A= $dt->year >= 2024B= $dt->year == 2023C= $dt->month >= 5
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $dt->set(hour => 18); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } elsif ($dt->year >= 2016) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | $dt->set(hour => 19); | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $dt->set(hour => 20); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||