diff options
| author | Mark Anderson <mark@frontrangerunner.com> | 2019-12-07 21:08:14 -0700 |
|---|---|---|
| committer | Mark Anderson <mark@frontrangerunner.com> | 2019-12-07 21:08:14 -0700 |
| commit | 6c74ae80f5c6808f655e945d65a739af8faf59ea (patch) | |
| tree | 4ea0c6d01ee93df5349f772a979425fc6291df33 /challenge-037 | |
| parent | 1bc39b559acfabc89a8baacda6c665a0329a52fb (diff) | |
| download | perlweeklychallenge-club-6c74ae80f5c6808f655e945d65a739af8faf59ea.tar.gz perlweeklychallenge-club-6c74ae80f5c6808f655e945d65a739af8faf59ea.tar.bz2 perlweeklychallenge-club-6c74ae80f5c6808f655e945d65a739af8faf59ea.zip | |
ch-2.pl again
Diffstat (limited to 'challenge-037')
| -rw-r--r-- | challenge-037/mark-anderson/perl5/ch-2.pl | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/challenge-037/mark-anderson/perl5/ch-2.pl b/challenge-037/mark-anderson/perl5/ch-2.pl index 18be5de613..aa2902b2a9 100644 --- a/challenge-037/mark-anderson/perl5/ch-2.pl +++ b/challenge-037/mark-anderson/perl5/ch-2.pl @@ -1,24 +1,27 @@ #!/usr/bin/env perl use Modern::Perl '2018'; use Mojo::UserAgent; +use feature 'signatures'; +no warnings 'experimental::signatures'; -my $ua = Mojo::UserAgent->new; +# make a date from the seconds difference and print the hh:mm:ss +my $hms = (split /\s/, Mojo::Date->new(secs(11) - secs(12)))[4]; +say "Dec has $hms less daylight"; -my $nov = "https://www.timeanddate.com/sun/uk/london?month=11&year=2019"; -my $dec = "https://www.timeanddate.com/sun/uk/london?month=12&year=2019"; +sub secs($month) { + my $ua = Mojo::UserAgent->new; -# load the 'Length' column values into a collection -my $nov_c = $ua->get($nov)->result->dom->find('td[class="c tr sep-l"]')->map('text'); -my $dec_c = $ua->get($dec)->result->dom->find('td[class="c tr sep-l"]')->map('text'); + my $link = "https://www.timeanddate.com/sun/uk/london?month=$month&year=2019"; -# convert the values from hh:mm:ss to seconds -$nov_c->map(sub { $_ = Mojo::Date->new("1970-01-01T$_")->epoch }); -$dec_c->map(sub { $_ = Mojo::Date->new("1970-01-01T$_")->epoch }); + # load the 'Length' column values into a collection + my $c = $ua->get($link)->result->dom->find('td[class="c tr sep-l"]')->map('text'); -# sum the seconds in each collection -my $nov_sum = $nov_c->reduce(sub { $a + $b }); -my $dec_sum = $dec_c->reduce(sub { $a + $b }); + # convert the values from hh:mm:ss to seconds + $c->map(sub { $_ = Mojo::Date->new("1970-01-01T$_")->epoch }); -# make a date from the seconds difference and print the hh:mm:ss -my $hms = (split /\s/, Mojo::Date->new(abs($dec_sum - $nov_sum)))[4]; -say "Dec has $hms", $dec_sum > $nov_sum ? " more " : " less ", "daylight"; + # sum the seconds in the collection + $c->reduce(sub { $a + $b }); +} + +# Output: +# Dec has 21:15:39 less daylight |
