diff options
| author | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-03-05 20:30:43 +0100 |
|---|---|---|
| committer | Jörg Sommrey <28217714+jo-37@users.noreply.github.com> | 2024-03-08 15:12:36 +0100 |
| commit | 19e16354b50ceb8d568b142af3a033e0b7381f62 (patch) | |
| tree | 63914a41b69bf16d31ae09fa0223012999fcbeb5 /challenge-259 | |
| parent | 510484bb98b0d2413f8c09c0a827e91b992d2533 (diff) | |
| download | perlweeklychallenge-club-19e16354b50ceb8d568b142af3a033e0b7381f62.tar.gz perlweeklychallenge-club-19e16354b50ceb8d568b142af3a033e0b7381f62.tar.bz2 perlweeklychallenge-club-19e16354b50ceb8d568b142af3a033e0b7381f62.zip | |
Solution to task 1
Diffstat (limited to 'challenge-259')
| -rwxr-xr-x | challenge-259/jo-37/perl/ch-1.pl | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/challenge-259/jo-37/perl/ch-1.pl b/challenge-259/jo-37/perl/ch-1.pl new file mode 100755 index 0000000000..3b85253922 --- /dev/null +++ b/challenge-259/jo-37/perl/ch-1.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl -s + +use v5.24; +use Test2::V0; +use File::Temp 'tempfile'; +use Date::Manip::Date; +use experimental 'signatures'; + +our ($tests, $examples, $verbose); + +run_tests() if $tests || $examples; # does not return + +die <<EOS unless @ARGV >= 2; +usage: $0 [-examples] [-tests] [START OFFS [HOLIDAY...]] + +-examples + run the examples from the challenge + +-tests + run some tests + +START + start date in format YYYY-MM-DD + +OFFS + business days offset + +HOLIDAY... + list of bank holidays in format YYYY-MM-DD + +EOS + + +### Input and Output + +say bdo(@ARGV[0, 1], [@ARGV[2..$#ARGV]]); + + +### Implementation + +sub bdo ($start, $offs, $bank=[]) { + my ($fh, $fn) = tempfile(); + print $fh "*HOLIDAYS\n"; + print $fh "$_ =\n" for @$bank; + close $fh; + + my $sd = Date::Manip::Date->new($start); + $sd->config(ConfigFile => $fn); + + $sd->next_business_day($offs); + $sd->printf('%Y-%m-%d'); +} + + +### Examples and tests + +sub run_tests { + SKIP: { + skip "examples" unless $examples; + + is bdo('2018-06-28', 3, ['2018-07-03']), '2018-07-04', 'example 1'; + is bdo('2018-06-28', 3), '2018-07-03', 'example 2'; + } + + SKIP: { + skip "tests" unless $tests; + + is bdo('2018-06-30', 1), '2018-07-03', 'start on weekend'; + is bdo('2018-06-28', 2, + [qw(2018-07-03 2018-06-29 2018-07-01 2018-07-04)]), '2018-07-05', + 'multiple holidays'; + } + + done_testing; + exit; +} |
