Skip Menu |

This queue is for tickets about the Finance-Quote CPAN distribution.

Report information
The Basics
Id: 44249
Status: open
Priority: 0/
Queue: Finance-Quote

People
Owner: Nobody in particular
Requestors: lmamane-bitcard [...] conuropsis.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.15
Fixed in: (no value)



Subject: Misparses times 12:00pm to 12:59pm
If the time of last trade is reported by yahoo as 12:XXpm, with XX replaced by any numbers, Finance::Quote returns time 00:00. That's because it computes a time of 24:XX, recognises it as invalid and falls back to 00:00. Here is a patch that fixes the problem.
Subject: 44245.patch
diff -u --recursive libfinance-quote-perl-1.15/lib/Finance/Quote.pm /usr/share/perl5/Finance/Quote.pm --- libfinance-quote-perl-1.15/lib/Finance/Quote.pm 2008-10-26 09:15:50.000000000 +0100 +++ /usr/share/perl5/Finance/Quote.pm 2009-03-17 18:44:49.657872693 +0100 @@ -671,7 +671,14 @@ 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) ; - $hours+=12 if ($3 && ($3 eq "PM")) ; + if ($hours==12) { + if ($3 && ($3 eq "AM")) { + $hours=0; + } + } + elsif ($3 && ($3 eq "PM")) { + $hours+=12; + } if ($hours>=0 && $hours<=23 && $mins>=0 && $mins<=59 ) { $retTime = sprintf ("%02d:%02d", $hours, $mins) ; }
Subject: Re: [rt.cpan.org #44249] Misparses times 12:00pm to 12:59pm
Date: Wed, 18 Mar 2009 01:16:32 +0100
To: bug-Finance-Quote [...] rt.cpan.org
From: Erik Colson <eco [...] ecocode.net>
Hi Lionel, Thanks for the report and patch. On 17 Mar 2009, at 18:59, Lionel Elie Mamane via RT wrote: Show quoted text
> If the time of last trade is reported by yahoo as 12:XXpm, with XX
well, that's weird that yahoo returns 12:XXpm formatted hours. To me that should be 00:XXam. Would you mind sending a test which we could add to the test base? Show quoted text
> > Here is a patch that fixes the problem. > if ($timeString=~m/^(\d+)[\.:UH](\d+)(AM|PM)?/) { > my ($hours,$mins)= ($1-0,$2-0) ; > - $hours+=12 if ($3 && ($3 eq "PM")) ; > + if ($hours==12) { > + if ($3 && ($3 eq "AM")) { > + $hours=0; > + } > + } > + elsif ($3 && ($3 eq "PM")) { > + $hours+=12; > + }
wouldn't this do the job ? (I didn't test this code) $hours+=12 if ($3 && ($3 eq "PM")) ; + $hours=0 if ($hours eq 24) ; # sometimes hours are 12:XXpm formatted by yahoo -- erik
Subject: Re: [rt.cpan.org #44249] Misparses times 12:00pm to 12:59pm
Date: Wed, 18 Mar 2009 15:17:48 -0400
To: bug-Finance-Quote [...] rt.cpan.org
From: David Hampton <hampton [...] employees.org>
On Tue, 2009-03-17 at 20:16 -0400, Erik Colson via RT wrote: Show quoted text
> Queue: Finance-Quote > Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=44249 > > > Hi Lionel, > > Thanks for the report and patch. > > On 17 Mar 2009, at 18:59, Lionel Elie Mamane via RT wrote: >
> > If the time of last trade is reported by yahoo as 12:XXpm, with XX
> > well, that's weird that yahoo returns 12:XXpm formatted hours. To me > that should be 00:XXam. > Would you mind sending a test which we could add to the test base? >
> > > > Here is a patch that fixes the problem. > > if ($timeString=~m/^(\d+)[\.:UH](\d+)(AM|PM)?/) { > > my ($hours,$mins)= ($1-0,$2-0) ; > > - $hours+=12 if ($3 && ($3 eq "PM")) ; > > + if ($hours==12) { > > + if ($3 && ($3 eq "AM")) { > > + $hours=0; > > + } > > + } > > + elsif ($3 && ($3 eq "PM")) { > > + $hours+=12; > > + }
> > > wouldn't this do the job ? (I didn't test this code) > > $hours+=12 if ($3 && ($3 eq "PM")) ; > + $hours=0 if ($hours eq 24) ; # sometimes hours are 12:XXpm > formatted by yahoo
No, this doesn't work. Its ends up swapping the noon and midnight hours. Lionel's solution appears to handle all three conversion cases (12AM: convert to 0, 1AM-12PM do nothing, 1PM-11PM add 12). I'm at a loss to come up with an elegant solution. The best I can do is: if ($hours == 12) { $hours -= 12; } if ($3 && ($3 eq "PM")) { $hours += 12; } This is untested. David
Subject: Re: [rt.cpan.org #44249] Misparses times 12:00pm to 12:59pm
Date: Thu, 19 Mar 2009 09:33:12 +0100
To: bug-Finance-Quote [...] rt.cpan.org
From: Erik Colson <eco [...] ecocode.net>
David Hampton via RT wrote: Show quoted text
       Queue: Finance-Quote
 Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=44249 >

On Tue, 2009-03-17 at 20:16 -0400, Erik Colson via RT wrote:
  
Queue: Finance-Quote
 Ticket <URL: http://rt.cpan.org/Ticket/Display.html?id=44249 >

Hi Lionel,

Thanks for the report and patch.

On 17 Mar 2009, at 18:59, Lionel Elie Mamane via RT wrote:

    
If the time of last trade is reported by yahoo as 12:XXpm, with XX
      
well, that's weird that yahoo returns 12:XXpm formatted hours. To me  
that should be 00:XXam.
Would you mind sending a test which we could add to the test base?

    
Here is a patch that fixes the problem.
  if ($timeString=~m/^(\d+)[\.:UH](\d+)(AM|PM)?/) {
    my ($hours,$mins)= ($1-0,$2-0) ;
-    $hours+=12 if ($3 && ($3 eq "PM")) ;
+    if ($hours==12) {
+      if ($3 && ($3 eq "AM")) {
+	$hours=0;
+      }
+    }
+    elsif ($3 && ($3 eq "PM")) {
+      $hours+=12;
+    }
      
wouldn't this do the job ? (I didn't test this code)

       $hours+=12 if ($3 && ($3 eq "PM")) ;
+     $hours=0 if ($hours eq 24) ;  # sometimes hours are 12:XXpm  
formatted by yahoo
    
No, this doesn't work. Its ends up swapping the noon and midnight hours.
  
oh yes, I'm not used to am-pm formatting here in Europe ;) so I guess 12:10PM means 10 minutes past midday instead of 10 past midnight.

Show quoted text
Lionel's solution appears to handle all three conversion cases (12AM:  
Show quoted text
convert to 0, 1AM-12PM do nothing, 1PM-11PM add 12).
Show quoted text
I'm at a loss to come up with an elegant solution. The best I can do is:

  if ($hours == 12) {
      $hours -= 12;
  }
  if ($3 && ($3 eq "PM")) {
      $hours += 12;
  }

This is untested.
  
Show quoted text
I patched the quote.t to add some tests for this.
They do succeed with your code, so I patched Quote.pm also

thanks for the code !

-- 
Erik