| 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 = '202008.24'; | |||||||||||||||||||||||||||||||
| 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
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 | sub next_meeting_dt { | ||||||||||||||||||||||||||||||||
| 31 | 0 | ▶ | my $dt = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
next_meeting_dt: not called CC=10 SCAR=47.0
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
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 | # Regular meetings | ||||||||||||||||||||||||||||||||
| 56 | 0 | my $last_wed_of_month = _get_last_wed_of_month($dt_berlin); | |||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($last_wed_of_month <= $dt_berlin) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 58 | 0 | $dt_berlin->add(months => 1, end_of_month => 'limit'); | |||||||||||||||||||||||||||||||
| 59 | 0 | $last_wed_of_month = _get_last_wed_of_month($dt_berlin); | |||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if ($last_wed_of_month->month == 12) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 62 | 0 | return _get_dec_meeting($last_wed_of_month); | |||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||
| 64 | 0 | $last_wed_of_month; | |||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | sub _get_last_wed_of_month { | ||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my $dt_berlin = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_get_last_wed_of_month: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 69 | 0 | my $last_day_of_month = DateTime->last_day_of_month(year => $dt_berlin->year, month => $dt_berlin->month, time_zone => 'Europe/Berlin'); | |||||||||||||||||||||||||||||||
| 70 | 0 | my $dow = $last_day_of_month->day_of_week; | |||||||||||||||||||||||||||||||
| 71 | 0 | ▶ | my $last_wed_of_month = $last_day_of_month->add(days => $dow < 3 ? -$dow-4 : -$dow+3); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 72 | 0 | _adjust_hour($last_wed_of_month); | |||||||||||||||||||||||||||||||
| 73 | 0 | $last_wed_of_month; | |||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | sub _get_dec_meeting { | ||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | my $dt = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_get_dec_meeting: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 78 | 0 | $dt = $dt->clone; | |||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ($dt->month == 12) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 80 | 0 | $dt->add(months => 1); # end_of_month does not matter | |||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||
| 82 | 0 | $dt->set(day => 3); | |||||||||||||||||||||||||||||||
| 83 | 0 | my $dow = $dt->day_of_week; | |||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $dt->add(days => $dow < 4 ? -$dow+3 : -$dow+10); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 85 | 0 | _adjust_hour($dt); | |||||||||||||||||||||||||||||||
| 86 | 0 | $dt; | |||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | sub _adjust_hour { | ||||||||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $dt = shift; | ||||||||||||||||||||||||||||||
|
Subroutine
_adjust_hour: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ($dt->year >= 2016) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 92 | 0 | $dt->set(hour => 19); | |||||||||||||||||||||||||||||||
| 93 | } else { | ||||||||||||||||||||||||||||||||
| 94 | 0 | $dt->set(hour => 20); | |||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||
| 98 | 4 | 1; | |||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||
| 100 | __END__ | ||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||
| 102 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | Acme::PM::Berlin::Meetings - get the next date of the Berlin PM meeting | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | use Acme::PM::Berlin::Meetings; | ||||||||||||||||||||||||||||||||
| 109 | next_meeting(1) | ||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||
| 111 | Or use the bundled script: | ||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||
| 113 | berlin-pm | ||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||
| 115 | =head1 NOTES | ||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||
| 117 | This module knows about special Berlin.PM traditions like postponing | ||||||||||||||||||||||||||||||||
| 118 | the December meeting to the first or second week in January. | ||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||
| 120 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||
| 122 | Slaven Rezic | ||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||
| 126 | L<Acme::PM::Barcelona::Meeting>, L<Acme::PM::Paris::Meetings>. | ||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||||||