summaryrefslogtreecommitdiff
path: root/src/times.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2012-04-26 16:39:25 -0500
committerJohn Wiegley <johnw@newartisans.com>2012-04-26 16:39:25 -0500
commit64a9b42381c26baf24e58b40f50f0b253e551811 (patch)
tree5447a29dff64c3a8b7be8100a01bcb4a2d73b0bb /src/times.h
parent7cc550fc22357e2ded194d3e65287c6b3317f5ae (diff)
parentb4407c10c0071365322b2963747bf42a57fd7304 (diff)
downloadfork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.gz
fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.tar.bz2
fork-ledger-64a9b42381c26baf24e58b40f50f0b253e551811.zip
Merge branch 'release/v3.0.0-20120426'
Diffstat (limited to 'src/times.h')
-rw-r--r--src/times.h29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/times.h b/src/times.h
index 39945824..3bb95903 100644
--- a/src/times.h
+++ b/src/times.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003-2010, John Wiegley. All rights reserved.
+ * Copyright (c) 2003-2012, John Wiegley. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -218,6 +218,9 @@ struct date_duration_t
case YEARS:
return date + gregorian::years(length);
}
+#if !defined(__clang__)
+ return date_t();
+#endif
}
date_t subtract(const date_t& date) const {
@@ -233,6 +236,9 @@ struct date_duration_t
case YEARS:
return date - gregorian::years(length);
}
+#if !defined(__clang__)
+ return date_t();
+#endif
}
string to_string() const {
@@ -301,13 +307,14 @@ public:
}
date_specifier_t(const date_t& date,
const optional<date_traits_t>& traits = none) {
- TRACE_CTOR(date_specifier_t, "date_t, date_traits_t");
if (! traits || traits->has_year)
year = date.year();
if (! traits || traits->has_month)
month = date.month();
if (! traits || traits->has_day)
day = date.day();
+
+ TRACE_CTOR(date_specifier_t, "date_t, date_traits_t");
}
date_specifier_t(const date_specifier_t& other)
: year(other.year), month(other.month),
@@ -532,8 +539,8 @@ public:
TRACE_CTOR(date_interval_t, "");
}
date_interval_t(const string& str) : aligned(false) {
- TRACE_CTOR(date_interval_t, "const string&");
parse(str);
+ TRACE_CTOR(date_interval_t, "const string&");
}
date_interval_t(const date_interval_t& other)
: range(other.range),
@@ -553,6 +560,10 @@ public:
return (start == other.start &&
(! start || *start == *other.start));
}
+ bool operator<(const date_interval_t& other) const {
+ return (start == other.start &&
+ (! start || *start < *other.start));
+ }
operator bool() const {
return is_valid();
@@ -574,10 +585,14 @@ public:
return start;
}
- /** Find the current or next period containing date. Returns true if the
- date_interval_t object has been altered to reflect the interval
- containing date, or false if no such period can be found. */
- bool find_period(const date_t& date = CURRENT_DATE());
+ /** Find the current or next period containing date. Returns false if
+ no such period can be found. If allow_shift is true, the default,
+ then the interval may be shifted in time to find the period. */
+ bool find_period(const date_t& date = CURRENT_DATE(),
+ const bool allow_shift = true);
+ bool within_period(const date_t& date = CURRENT_DATE()) {
+ return find_period(date, false);
+ }
optional<date_t> inclusive_end() const {
if (end_of_duration)