diff options
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | src/filters.cc | 4 | ||||
-rw-r--r-- | src/global.cc | 4 | ||||
-rw-r--r-- | src/interactive.cc | 13 | ||||
-rw-r--r-- | src/pool.cc | 7 | ||||
-rw-r--r-- | src/pool.h | 5 | ||||
-rw-r--r-- | src/quotes.cc | 15 | ||||
-rw-r--r-- | src/quotes.h | 3 | ||||
-rw-r--r-- | src/report.cc | 10 | ||||
-rw-r--r-- | src/report.h | 12 | ||||
-rw-r--r-- | test/regress/647D5DB9.test | 2 |
11 files changed, 45 insertions, 34 deletions
diff --git a/Makefile.am b/Makefile.am index b7b19c7f..8ed18fbb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,6 +30,7 @@ libledger_util_la_LDFLAGS = -release $(VERSION).0 libledger_math_la_SOURCES = \ src/value.cc \ src/balance.cc \ + src/quotes.cc \ src/pool.cc \ src/annotate.cc \ src/commodity.cc \ @@ -67,7 +68,6 @@ libledger_data_la_CPPFLAGS = $(lib_cppflags) libledger_data_la_LDFLAGS = -release $(VERSION).0 libledger_report_la_SOURCES = \ - src/quotes.cc \ src/stats.cc \ src/generate.cc \ src/derive.cc \ @@ -98,6 +98,7 @@ pkginclude_HEADERS = \ src/commodity.h \ src/annotate.h \ src/pool.h \ + src/quotes.h \ src/balance.h \ src/value.h \ \ @@ -130,7 +131,6 @@ pkginclude_HEADERS = \ src/stats.h \ src/output.h \ src/emacs.h \ - src/quotes.h \ \ src/global.h \ \ diff --git a/src/filters.cc b/src/filters.cc index ab7d4b74..c7c49907 100644 --- a/src/filters.cc +++ b/src/filters.cc @@ -390,8 +390,8 @@ void related_posts::flush() void changed_value_posts::flush() { - if (last_post && last_post->date() <= report.terminus) { - output_revaluation(last_post, report.terminus); + if (last_post && last_post->date() <= report.terminus.date()) { + output_revaluation(last_post, report.terminus.date()); last_post = NULL; } item_handler<post_t>::flush(); diff --git a/src/global.cc b/src/global.cc index 084b92da..1c94cfcb 100644 --- a/src/global.cc +++ b/src/global.cc @@ -507,8 +507,8 @@ void global_scope_t::normalize_report_options(const string& verb) // settings that may be there. if (rep.HANDLED(exchange_) && rep.HANDLER(exchange_).str().find('=') != string::npos) { - value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(), - true, datetime_t(rep.terminus)); + value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(), true, + rep.terminus); } long cols = 0; diff --git a/src/interactive.cc b/src/interactive.cc index 528ef9f2..1ae976e7 100644 --- a/src/interactive.cc +++ b/src/interactive.cc @@ -75,7 +75,13 @@ void interactive_t::verify_arguments() const break; case 'd': label = _("a date"); - wrong_arg = ! next_arg->is_date(); + wrong_arg = (! next_arg->is_date() && + ! next_arg->is_datetime()); + break; + case 't': + label = _("a date/time"); + wrong_arg = (! next_arg->is_date() && + ! next_arg->is_datetime()); break; case 'i': case 'l': @@ -106,11 +112,6 @@ void interactive_t::verify_arguments() const label = _("a string"); wrong_arg = ! next_arg->is_string(); break; - case 't': - label = _("a date or time"); - wrong_arg = (! next_arg->is_date() && - ! next_arg->is_datetime()); - break; case 'v': label = _("any value"); wrong_arg = false; diff --git a/src/pool.cc b/src/pool.cc index 48dd7f84..e21b900c 100644 --- a/src/pool.cc +++ b/src/pool.cc @@ -35,12 +35,14 @@ #include "commodity.h" #include "annotate.h" #include "pool.h" +#include "quotes.h" namespace ledger { commodity_pool_t::commodity_pool_t() : default_commodity(NULL), keep_base(false), - quote_leeway(86400), get_quotes(false) + quote_leeway(86400), get_quotes(false), + get_commodity_quote(commodity_quote_from_script) { TRACE_CTOR(commodity_pool_t, ""); null_commodity = create(""); @@ -311,8 +313,11 @@ optional<price_point_t> commodity_pool_t::parse_price_directive(char * line) point.price.parse(symbol_and_price); VERIFY(point.price.valid()); + DEBUG("commodity.download", "Looking up symbol: " << symbol); if (commodity_t * commodity = amount_t::current_pool->find_or_create(symbol)) { + DEBUG("commodity.download", "Adding price for " << symbol << ": " + << point.when << " " << point.price); commodity->add_price(point.when, point.price, true); commodity->add_flags(COMMODITY_KNOWN); return point; @@ -86,10 +86,9 @@ public: long quote_leeway; // --leeway= bool get_quotes; // --download -public: function<optional<price_point_t> - (const commodity_t& commodity, - const optional<commodity_t&>& in_terms_of)> get_commodity_quote; + (commodity_t& commodity, const optional<commodity_t&>& in_terms_of)> + get_commodity_quote; explicit commodity_pool_t(); diff --git a/src/quotes.cc b/src/quotes.cc index ef7b769e..d4be462e 100644 --- a/src/quotes.cc +++ b/src/quotes.cc @@ -94,10 +94,17 @@ commodity_quote_from_script(commodity_t& commodity, return point; } } else { - throw_(std::runtime_error, - _("Failed to download price for '%1' (command: \"getquote %2 %3\")") - << commodity.symbol() << commodity.symbol() - << (exchange_commodity ? exchange_commodity->symbol() : "''")); + DEBUG("commodity.download", + "Failed to download price for '" << commodity.symbol() << + "' (command: \"getquote " << commodity.symbol() << + " " << (exchange_commodity ? + exchange_commodity->symbol() : "''") << "\")"); + + // Don't try to download this commodity again. + + // jww (2009-06-24): This flag should be removed in order to try again + // when using a GUI. + commodity.add_flags(COMMODITY_NOMARKET); } return none; } diff --git a/src/quotes.h b/src/quotes.h index ea47d4c2..5db69d1f 100644 --- a/src/quotes.h +++ b/src/quotes.h @@ -49,7 +49,8 @@ namespace ledger { optional<price_point_t> -commodity_quote_from_script(const optional<commodity_t&>& exchange_commodity); +commodity_quote_from_script(commodity_t& commodity, + const optional<commodity_t&>& exchange_commodity); } // namespace ledger diff --git a/src/report.cc b/src/report.cc index 731de501..3e38aef2 100644 --- a/src/report.cc +++ b/src/report.cc @@ -259,9 +259,11 @@ value_t report_t::fn_join(call_scope_t& args) return string_value(out.str()); } -value_t report_t::fn_format_date(call_scope_t& args) +value_t report_t::fn_format_date(call_scope_t& scope) { - return string_value(format_date(args[0].to_date(), args[1].to_string())); + interactive_t args(scope, "ds"); + return string_value(format_date(args.get<date_t>(0), + args.get<string>(1))); } value_t report_t::fn_ansify_if(call_scope_t& scope) @@ -752,7 +754,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name) else if (is_eq(p, "display_total")) return MAKE_FUNCTOR(report_t::fn_display_total); else if (is_eq(p, "date")) - return MAKE_FUNCTOR(report_t::fn_today); + return MAKE_FUNCTOR(report_t::fn_now); break; case 'f': @@ -789,10 +791,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name) case 'n': if (is_eq(p, "null")) return WRAP_FUNCTOR(fn_null); -#if 0 else if (is_eq(p, "now")) return MAKE_FUNCTOR(report_t::fn_now); -#endif break; case 'o': diff --git a/src/report.h b/src/report.h index 862be9fa..6f442b5d 100644 --- a/src/report.h +++ b/src/report.h @@ -121,11 +121,11 @@ public: #define BUDGET_BUDGETED 0x01 #define BUDGET_UNBUDGETED 0x02 - date_t terminus; + datetime_t terminus; uint_least8_t budget_flags; explicit report_t(session_t& _session) - : session(_session), terminus(CURRENT_DATE()), + : session(_session), terminus(CURRENT_TIME()), budget_flags(BUDGET_NO_BUDGET) {} virtual ~report_t() { @@ -159,13 +159,11 @@ public: value_t fn_ansify_if(call_scope_t& scope); value_t fn_percent(call_scope_t& scope); -#if 0 value_t fn_now(call_scope_t&) { - return CURRENT_TIME(); + return terminus; } -#endif value_t fn_today(call_scope_t&) { - return terminus; + return terminus.date(); } value_t fn_options(call_scope_t&) { @@ -484,7 +482,7 @@ public: "date<[" + to_iso_extended_string(*interval.start) + "]"; parent->HANDLER(limit_).on(string("--end"), predicate); - parent->terminus = *interval.start; + parent->terminus = datetime_t(*interval.start); }); OPTION(report_t, equity); diff --git a/test/regress/647D5DB9.test b/test/regress/647D5DB9.test index 3f187b36..2d6b78e3 100644 --- a/test/regress/647D5DB9.test +++ b/test/regress/647D5DB9.test @@ -1,4 +1,4 @@ -bal --end 2008/12/31 -JV bal Equities +bal --end 2008/12/31 -JV Equities <<< 2008/01/01 * Purchase Apple shares Equities 1000 AAPL @ $2 |