gnucash maint: Bug 752879 - Finance::Quote TZ Date::Manip config variable is deprecated
John Ralls
jralls at code.gnucash.org
Sun Jul 26 16:12:04 EDT 2015
Updated via https://github.com/Gnucash/gnucash/commit/d2798b8c (commit)
from https://github.com/Gnucash/gnucash/commit/6d5002d9 (commit)
commit d2798b8c3f1076756428180b9f5200d0171ce907
Author: John Ralls <jralls at ceridwen.us>
Date: Sun Jul 26 13:11:45 2015 -0700
Bug 752879 - Finance::Quote TZ Date::Manip config variable is deprecated
Rewrite get_quote_time() to use the modern OO interface to Date::Manip.
This requires perl-5.12 or later, so require that. schemify_date() isn't
used anywhere, so remove that.
diff --git a/src/quotes/gnc-fq-helper.in b/src/quotes/gnc-fq-helper.in
index c2c91d4..16dd452 100755
--- a/src/quotes/gnc-fq-helper.in
+++ b/src/quotes/gnc-fq-helper.in
@@ -114,6 +114,10 @@ non-zero - failure
=cut
+# Set a base date with the current time in the current TZ:
+my $base_date = new Date::Manip::Date;
+$base_date->parse("now");
+
# The methods we know about. For now we assume they all have the same
# signature so this works OK.
@@ -190,18 +194,6 @@ sub schemify_num {
}
}
-sub schemify_date {
- # return the date in epoch seconds.
- my ($datestr) = @_;
-
- my $date = ParseDate($datestr);
- my $result = UnixDate($date, "%s");
- if($result !~ /^(\+|-)?\d+$/) {
- $result = "failed-conversion";
- }
- return("$result");
-}
-
# sub schemify_range {
# #convert range in form ``num1 - num2'' to ``(num1 num2)''.
# }
@@ -212,33 +204,19 @@ sub get_quote_time {
my $datestr = $$quotehash{$item, 'date'};
my $timestr = $$quotehash{$item, 'time'};
-
- if(!$datestr) {
- return undef;
+ my $format = "%Y-%m-%d %H:%M:%S";
+
+ if ($datestr) {
+ my $parsestr = $datestr . " " . ($timestr ? $timestr : "12:00:00");
+ my $date = $base_date->new();
+ my $err = $date->parse($parsestr);
+ if ($err) {
+ print $date->err(), " $parsestr\n";
+ return $base_date->printf($format);
+ }
+ return $date->printf($format);
}
-
- my $parsestr = $datestr;
- if(!$timestr) {
- #fix date handling for quotes with no time.
- #Keeps gnucash from getting date wrong in west longitude places.
- $parsestr .= " 12:00:00"
- } else {
- $parsestr .= " $timestr";
- }
-
- $parsestr = ParseDateString($parsestr);
-
- my $result = UnixDate($parsestr, "\"%Y-%m-%d %H:%M:%S\"");
- if(!$result) {
- # Fix date handling for quotes with no date: assume local date
- (my $second,my $minute,my $hour,my $dayofmonth,my $month,my $year,my $dayofweek,my $dayofyear,my $daylightsaving) = localtime();
-# $result = "\"".sprintf("%04d-%02d-%02d%02d:%02d:%02d",($year+1900),++$month,$dayOfMonth,$hour,$minute,$second)."\"";
- $result = "\"" . sprintf("%04d-%02d-%02d", ($year+1900), ++$month, $dayofmonth) . " 12:00:00\"";
- }
- if($result !~ /^\"\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d\"$/) {
- $result = "failed-conversion";
- }
- return $result;
+ return $base_date->printf($format);
}
sub schemify_quote {
@@ -341,9 +319,6 @@ sub parse_input_line {
# Check for and load non-standard modules
check_modules ();
-# Help Date::Manip on Windows
-Date_Init("TZ=UTC") if ($^O eq "MSWin32" && (!$ENV{'TZ'}));
-
# Create a stockquote object.
my $quoter = Finance::Quote->new();
my $prgnam = "gnc-fq-helper";
Summary of changes:
src/quotes/gnc-fq-helper.in | 57 +++++++++++++--------------------------------
1 file changed, 16 insertions(+), 41 deletions(-)
More information about the gnucash-changes
mailing list