From 0682fba9a2de1142ff281c93ca066abc090c2ecc Mon Sep 17 00:00:00 2001 From: Lubos Kolouch Date: Sat, 20 Feb 2021 10:34:08 +0100 Subject: PWC 100 Task 1 Perl LK --- challenge-100/lubos-kolouch/perl/ch-1.pl | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 challenge-100/lubos-kolouch/perl/ch-1.pl diff --git a/challenge-100/lubos-kolouch/perl/ch-1.pl b/challenge-100/lubos-kolouch/perl/ch-1.pl new file mode 100644 index 0000000000..06b2962ba7 --- /dev/null +++ b/challenge-100/lubos-kolouch/perl/ch-1.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +#=============================================================================== +# +# FILE: ch-1.pl +# +# USAGE: ./ch-1.pl +# +# DESCRIPTION: Perl Weekly Challenge #100 +# Task 1 +# AUTHOR: Lubos Kolouch +# CREATED: 02/20/2021 10:16:51 AM +#=============================================================================== + +use strict; +use warnings; +use DateTime::Format::DateParse; + +sub convert_time { + my $what = shift; + + my $pattern = $what =~ /m/ ? '%H:%M' : '%I:%M %P'; + + return DateTime::Format::DateParse + -> parse_datetime($what) + -> strftime($pattern); + +} + +use Test::More; + +is(convert_time('05:15pm'), '17:15'); +is(convert_time('05:15 pm'), '17:15'); +is(convert_time('19:15'), '07:15 pm'); + +done_testing; -- cgit