aboutsummaryrefslogtreecommitdiff
path: root/challenge-332/barroff/raku/ch-1.p6
blob: 7f0bb5fbc8d48320718c3280eb84ba33d2f3a6f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env raku

use v6.d;

my $bin-format = sub ($self) {
    sprintf "%d-%d-%d",
    .year.base(2),
    .month.base(2),
    .day.base(2)
    given $self;
}

sub binary-date(Str $date --> Str) {
    Str(Date.new($date, formatter => $bin-format))
}

#| Run test cases
multi sub MAIN('test') {
    use Test;
    plan 3;

    is binary-date("2025-07-26"), "11111101001-111-11010",
        'works for "2025-07-26"';
    is binary-date("2000-02-02"), "11111010000-10-10",
        'works for "2000-02-02"';
    is binary-date("2024-12-31"), "11111101000-1100-11111",
        'works for "2024-12-31"';
}

#| Take user provided date like "2025-07-26"
multi sub MAIN(Str $date) {
    say binary-date($date);
}