Subject: | isoTime on "4pm" without minutes |
Date: | Sat, 30 Jan 2010 11:54:22 +1100 |
To: | bug-Finance-Quote [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
In my RBA module I wanted to convert a time like "4pm" with isoTime(),
use strict;
use warnings;
use Finance::Quote;
print Finance::Quote->isoTime('4pm'),"\n";
It'd be good if that function had the minutes field optional. Perhaps
something easy like below, or maybe tighter so a plain number input like
"4" is not accepted (only "4pm" or "4:00" or "4h00" etc).
diff --git a/lib/Finance/Quote.pm b/lib/Finance/Quote.pm
index 320a3b9..a6dca9f 100644
--- a/lib/Finance/Quote.pm
+++ b/lib/Finance/Quote.pm
@@ -759,8 +759,8 @@ sub isoTime {
$timeString =~ tr/ //d ;
$timeString = uc $timeString ;
my $retTime = "00:00"; # return zero time if unparsable input
- if ($timeString=~m/^(\d+)[\.:UH](\d+)(AM|PM)?/) {
- my ($hours,$mins)= ($1-0,$2-0) ;
+ if ($timeString=~m/^(\d+)(?:[\.:UH](\d+))?(AM|PM)?/) {
+ my ($hours,$mins)= ($1-0,$2||0) ;
$hours-=12 if ($hours==12);
$hours+=12 if ($3 && ($3 eq "PM")) ;
if ($hours>=0 && $hours<=23 && $mins>=0 && $mins<=59 ) {