summaryrefslogtreecommitdiff
path: root/amount.cc
diff options
context:
space:
mode:
Diffstat (limited to 'amount.cc')
-rw-r--r--amount.cc62
1 files changed, 31 insertions, 31 deletions
diff --git a/amount.cc b/amount.cc
index ff1bcc6b..91981e2d 100644
--- a/amount.cc
+++ b/amount.cc
@@ -747,7 +747,7 @@ amount_t::operator double() const
return std::atof(num.str().c_str());
}
-amount_t amount_t::value(const ptime& moment) const
+amount_t amount_t::value(const moment_t& moment) const
{
if (quantity) {
amount_t amt(commodity().value(moment));
@@ -1132,7 +1132,7 @@ static void parse_commodity(std::istream& in, std::string& symbol)
}
bool parse_annotations(std::istream& in, amount_t& price,
- ptime& date, std::string& tag)
+ moment_t& date, std::string& tag)
{
bool has_date = false;
@@ -1162,7 +1162,7 @@ bool parse_annotations(std::istream& in, amount_t& price,
price = price.round(); // no need to retain individual precision
}
else if (c == '[') {
- if (! date.is_not_a_date_time())
+ if (is_valid_moment(date))
throw new amount_error("Commodity specifies more than one date");
in.get(c);
@@ -1212,7 +1212,7 @@ void amount_t::parse(std::istream& in, unsigned char flags)
std::string symbol;
std::string quant;
amount_t tprice;
- ptime tdate;
+ moment_t tdate;
bool had_date = false;
std::string tag;
unsigned int comm_flags = COMMODITY_STYLE_DEFAULTS;
@@ -1552,7 +1552,7 @@ bool amount_t::valid() const
}
void amount_t::annotate_commodity(const amount_t& tprice,
- const ptime& tdate,
+ const moment_t& tdate,
const std::string& tag)
{
const commodity_t * this_base;
@@ -1575,7 +1575,7 @@ void amount_t::annotate_commodity(const amount_t& tprice,
commodity_t * ann_comm =
annotated_commodity_t::find_or_create
(*this_base, ! tprice && this_ann ? this_ann->price : tprice,
- tdate.is_not_a_date_time() && this_ann ? this_ann->date : tdate,
+ ! is_valid_moment(tdate) && this_ann ? this_ann->date : tdate,
tag.empty() && this_ann ? this_ann->tag : tag);
if (ann_comm)
set_commodity(*ann_comm);
@@ -1604,12 +1604,12 @@ amount_t amount_t::strip_annotations(const bool _keep_price,
commodity_t * new_comm;
if ((_keep_price && ann_comm.price) ||
- (_keep_date && ! ann_comm.date.is_not_a_date_time()) ||
+ (_keep_date && is_valid_moment(ann_comm.date)) ||
(_keep_tag && ! ann_comm.tag.empty()))
{
new_comm = annotated_commodity_t::find_or_create
(*ann_comm.ptr, _keep_price ? ann_comm.price : amount_t(),
- _keep_date ? ann_comm.date : ptime(),
+ _keep_date ? ann_comm.date : moment_t(),
_keep_tag ? ann_comm.tag : "");
} else {
new_comm = commodity_t::find_or_create(ann_comm.base_symbol());
@@ -1635,7 +1635,7 @@ amount_t amount_t::price() const
return *this;
}
-ptime amount_t::date() const
+moment_t amount_t::date() const
{
if (commodity_ && commodity_->annotated) {
DEBUG_PRINT("amounts.commodities",
@@ -1643,12 +1643,12 @@ ptime amount_t::date() const
<< ((annotated_commodity_t *)commodity_)->date);
return ((annotated_commodity_t *)commodity_)->date;
}
- return ptime();
+ return moment_t();
}
-void commodity_base_t::add_price(const ptime& date,
- const amount_t& price)
+void commodity_base_t::add_price(const moment_t& date,
+ const amount_t& price)
{
if (! history)
history = new history_t;
@@ -1663,7 +1663,7 @@ void commodity_base_t::add_price(const ptime& date,
}
}
-bool commodity_base_t::remove_price(const ptime& date)
+bool commodity_base_t::remove_price(const moment_t& date)
{
if (history) {
history_map::size_type n = history->prices.erase(date);
@@ -1773,15 +1773,15 @@ commodity_t * commodity_t::find(const std::string& symbol)
return NULL;
}
-amount_t commodity_base_t::value(const ptime& moment)
+amount_t commodity_base_t::value(const moment_t& moment)
{
- ptime age;
+ moment_t age;
amount_t price;
if (history) {
assert(history->prices.size() > 0);
- if (moment.is_not_a_date_time()) {
+ if (! is_valid_moment(moment)) {
history_map::reverse_iterator r = history->prices.rbegin();
age = (*r).first;
price = (*r).second;
@@ -1799,7 +1799,7 @@ amount_t commodity_base_t::value(const ptime& moment)
age = (*i).first;
price = (*i).second;
} else {
- age = ptime();
+ age = moment_t();
}
} else {
price = (*i).second;
@@ -1811,7 +1811,7 @@ amount_t commodity_base_t::value(const ptime& moment)
if (updater && ! (flags & COMMODITY_STYLE_NOMARKET))
(*updater)(*this, moment, age,
(history && history->prices.size() > 0 ?
- (*history->prices.rbegin()).first : ptime()), price);
+ (*history->prices.rbegin()).first : moment_t()), price);
return price;
}
@@ -1827,7 +1827,7 @@ bool annotated_commodity_t::operator==(const commodity_t& comm) const
price != static_cast<const annotated_commodity_t&>(comm).price))
return false;
- if (! date.is_not_a_date_time() &&
+ if (is_valid_moment(date) &&
(! comm.annotated ||
date != static_cast<const annotated_commodity_t&>(comm).date))
return false;
@@ -1843,13 +1843,13 @@ bool annotated_commodity_t::operator==(const commodity_t& comm) const
void
annotated_commodity_t::write_annotations(std::ostream& out,
const amount_t& price,
- const ptime& date,
+ const moment_t& date,
const std::string& tag)
{
if (price)
out << " {" << price << '}';
- if (! date.is_not_a_date_time())
+ if (is_valid_moment(date))
out << " [" << date << ']';
if (! tag.empty())
@@ -1859,7 +1859,7 @@ annotated_commodity_t::write_annotations(std::ostream& out,
commodity_t *
annotated_commodity_t::create(const commodity_t& comm,
const amount_t& price,
- const ptime& date,
+ const moment_t& date,
const std::string& tag,
const std::string& mapping_key)
{
@@ -1900,7 +1900,7 @@ annotated_commodity_t::create(const commodity_t& comm,
namespace {
std::string make_qualified_name(const commodity_t& comm,
const amount_t& price,
- const ptime& date,
+ const moment_t& date,
const std::string& tag)
{
if (price < 0)
@@ -1926,7 +1926,7 @@ namespace {
commodity_t *
annotated_commodity_t::find_or_create(const commodity_t& comm,
const amount_t& price,
- const ptime& date,
+ const moment_t& date,
const std::string& tag)
{
std::string name = make_qualified_name(comm, price, date, tag);
@@ -1989,16 +1989,16 @@ bool compare_amount_commodities::operator()(const amount_t * left,
}
}
- if (aleftcomm.date.is_not_a_date_time() &&
- ! arightcomm.date.is_not_a_date_time())
+ if (! is_valid_moment(aleftcomm.date) &&
+ is_valid_moment(arightcomm.date))
return true;
- if (! aleftcomm.date.is_not_a_date_time() &&
- arightcomm.date.is_not_a_date_time())
+ if (is_valid_moment(aleftcomm.date) &&
+ ! is_valid_moment(arightcomm.date))
return false;
- if (! aleftcomm.date.is_not_a_date_time() &&
- ! arightcomm.date.is_not_a_date_time()) {
- time_duration diff = aleftcomm.date - arightcomm.date;
+ if (is_valid_moment(aleftcomm.date) &&
+ is_valid_moment(arightcomm.date)) {
+ duration_t diff = aleftcomm.date - arightcomm.date;
return diff.is_negative();
}