aboutsummaryrefslogtreecommitdiff
path: root/challenge-132
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-11-14 10:29:37 +0000
committerGitHub <noreply@github.com>2021-11-14 10:29:37 +0000
commitc88e862def1520e15bc4430d3684603cf0b33187 (patch)
tree4a8a6e2d5d7c7bbb55c314846606941ee70b84c3 /challenge-132
parent1fa50ff5ba3c5d3f4da9892989ecf042f5f03886 (diff)
parented0f1f1c40bc9491497b091456ad8f1c35c47805 (diff)
downloadperlweeklychallenge-club-c88e862def1520e15bc4430d3684603cf0b33187.tar.gz
perlweeklychallenge-club-c88e862def1520e15bc4430d3684603cf0b33187.tar.bz2
perlweeklychallenge-club-c88e862def1520e15bc4430d3684603cf0b33187.zip
Merge pull request #5208 from E7-87-83/newt
Submission for Week 138
Diffstat (limited to 'challenge-132')
-rw-r--r--challenge-132/cheok-yin-fung/perl/ch-1.pl28
1 files changed, 15 insertions, 13 deletions
diff --git a/challenge-132/cheok-yin-fung/perl/ch-1.pl b/challenge-132/cheok-yin-fung/perl/ch-1.pl
index ed95f49ea2..3dd745440b 100644
--- a/challenge-132/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-132/cheok-yin-fung/perl/ch-1.pl
@@ -1,23 +1,25 @@
#!/usr/bin/perl
-# The Weekly Challenge 131
+# The Weekly Challenge 132
# Task 1 Mirror Dates
# Usage: ch-1.pl YYYY/MM/DD
+# modified: 14th Nov 2021
use v5.24.0;
use warnings;
-use Time::Local qw'timelocal timegm_nocheck';
+use Time::Local qw'timegm_nocheck';
+use Time::gmtime;
use Test::More tests => 3;
say mirror_str($ARGV[0]) if defined($ARGV[0]);
sub mirror {
my @arr_today = (22, 8, 2021); # Wed Sep 22 2021
- my $_today = timelocal(0, 0, 0, @arr_today);
+ my $_today = timegm_nocheck(0, 0, 0, @arr_today);
my @arr_birth = ($_[2], $_[1]-1, $_[0]);
- my $_birth = timelocal(0, 0, 0, @arr_birth);
+ my $_birth = timegm_nocheck(0, 0, 0, @arr_birth);
my $y1 = int (($_today - $_birth)/86400);
- my @d_senior = localtime timegm_nocheck 0, 0, 0, $arr_birth[0]-$y1, $arr_birth[1], $arr_birth[2];
- my @d_junior = localtime timegm_nocheck 0, 0, 0, $arr_today[0]+$y1, $arr_today[1], $arr_today[2];
- return [ [@d_senior], [@d_junior] ];
+ my $d_senior = gmtime timegm_nocheck 0, 0, 0, $arr_birth[0]-$y1, $arr_birth[1], $arr_birth[2];
+ my $d_junior = gmtime timegm_nocheck 0, 0, 0, $arr_today[0]+$y1, $arr_today[1], $arr_today[2];
+ return [ $d_senior, $d_junior ];
}
sub mirror_str {
@@ -27,13 +29,13 @@ sub mirror_str {
my ($d_s, $d_j) = mirror($byear, $bmonth, $bday)->@*;
return
- ($d_s->[5]+1900)."/"
- .($d_s->[4]<=8 ? 0 : "").($d_s->[4]+1)."/"
- .($d_s->[3]<10 ? 0 : "").($d_s->[3])
+ ($d_s->year()+1900)."/"
+ .($d_s->mon()<=8 ? 0 : "").($d_s->mon()+1)."/"
+ .($d_s->mday()<10 ? 0 : "").($d_s->mday())
.", "
- .($d_j->[5]+1900)."/"
- .($d_j->[4]<=8 ? 0 : "").($d_j->[4]+1)."/"
- .($d_j->[3]<10 ? 0 : "").($d_j->[3]);
+ .($d_j->year()+1900)."/"
+ .($d_j->mon()<=8 ? 0 : "").($d_j->mon()+1)."/"
+ .($d_j->mday()<10 ? 0 : "").($d_j->mday());
}
ok mirror_str("2021/09/18") eq "2021/09/14, 2021/09/26", "Example 1";