diff options
| author | Adam Russell <ac.russell@live.com> | 2021-10-03 15:12:06 -0400 |
|---|---|---|
| committer | Adam Russell <ac.russell@live.com> | 2021-10-03 15:12:06 -0400 |
| commit | 9a7352c378bbea7491d0b1f4ee9973ab2670a47a (patch) | |
| tree | c0e34dab482a37bc8bc40e4ef268e1ab6f8ec44f | |
| parent | 5fcd70c1a734cb266d63fe0512bf9cfeb1efe04b (diff) | |
| download | perlweeklychallenge-club-9a7352c378bbea7491d0b1f4ee9973ab2670a47a.tar.gz perlweeklychallenge-club-9a7352c378bbea7491d0b1f4ee9973ab2670a47a.tar.bz2 perlweeklychallenge-club-9a7352c378bbea7491d0b1f4ee9973ab2670a47a.zip | |
solution to challenge 132
| -rw-r--r-- | challenge-132/adam-russell/perl/ch-1.pl | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/challenge-132/adam-russell/perl/ch-1.pl b/challenge-132/adam-russell/perl/ch-1.pl new file mode 100644 index 0000000000..5cf04756a2 --- /dev/null +++ b/challenge-132/adam-russell/perl/ch-1.pl @@ -0,0 +1,42 @@ +use strict; +use warnings; +## +# You are given a date (yyyy/mm/dd). +# Assuming, the given date is your date of birth. +# Write a script to find the mirror dates of the given date. +## +use Time::Piece; +use Time::Seconds; + +sub mirror_dates{ + my($date_string, $start_date_string) = @_; + my $date = Time::Piece->strptime($date_string, q[%Y/%m/%e]); + my $today; + if($start_date_string){ + $today = Time::Piece->strptime($start_date_string, q[%Y/%m/%e]); + } + else{ + $today = localtime; + } + my $age = $today - $date; + my $past = $date - $age; + my $future = $today + $age; + return $past->strftime(q[%Y/%m/%d]), $future->strftime(q[%Y/%m/%d]); +} + +MAIN:{ + my($past, $future); + ($past, $future) = mirror_dates("2021/09/18", "2021/09/22"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1975/10/10", "2021/09/22"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1967/02/14", "2021/09/22"); + print "$past, $future\n"; + + ($past, $future) = mirror_dates("2021/09/18"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1975/10/10"); + print "$past, $future\n"; + ($past, $future) = mirror_dates("1967/02/14"); + print "$past, $future\n"; +}
\ No newline at end of file |
