summaryrefslogtreecommitdiff
path: root/src/times.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-03-11 04:38:02 -0400
committerJohn Wiegley <johnw@newartisans.com>2009-03-15 22:39:44 -0400
commit0de43f483b7472219564aafeffbe316ae6a0ac79 (patch)
tree45d6eef84c3a1f9d9713267e2cfc38de834a8c96 /src/times.h
parent63080a727540e5168d6eb230e86d06ad390dc6c5 (diff)
downloadfork-ledger-0de43f483b7472219564aafeffbe316ae6a0ac79.tar.gz
fork-ledger-0de43f483b7472219564aafeffbe316ae6a0ac79.tar.bz2
fork-ledger-0de43f483b7472219564aafeffbe316ae6a0ac79.zip
Started breaking up interval_t into range_t
Diffstat (limited to 'src/times.h')
-rw-r--r--src/times.h57
1 files changed, 43 insertions, 14 deletions
diff --git a/src/times.h b/src/times.h
index b83c65b5..5a40361e 100644
--- a/src/times.h
+++ b/src/times.h
@@ -128,42 +128,69 @@ inline std::string format_date(const date_t& when,
*
* Long.
*/
+struct range_t
+{
+ date_t begin;
+ date_t end;
+
+ date_range_t(const date_t& _begin = date_t(),
+ const date_t& _end = date_t())
+ : begin(_begin), end(_end) {
+ TRACE_CTOR(date_range_t, "const date_t&, const date_t&");
+ }
+ date_range_t(const date_range_t& other)
+ : begin(other.begin), end(other.end) {
+ TRACE_CTOR(date_range_t, "copy");
+ }
+ date_range_t(const string& desc) : begin(), end() {
+ TRACE_CTOR(date_range_t, "const string&");
+ std::istringstream stream(desc);
+ parse(stream);
+ }
+ ~date_range_t() throw() {
+ TRACE_DTOR(date_range_t);
+ }
+
+ bool date_in_range(const date_t& date) {
+ return ((! is_valid(begin) || date >= begin) &&
+ (! is_valid(end) || date < end));
+ }
+
+ void parse(std::istream& in);
+};
+
+/**
+ * @brief Brief
+ *
+ * Long.
+ */
struct interval_t
{
int years;
int months;
int days;
bool weekly;
- date_t begin;
- date_t end;
interval_t(int _days = 0,
int _months = 0,
int _years = 0,
- bool _weekly = false,
- const date_t& _begin = date_t(),
- const date_t& _end = date_t())
- : years(_years), months(_months), days(_days),
- weekly(_weekly), begin(_begin), end(_end) {
- TRACE_CTOR(interval_t,
- "int, int, int, bool, const date_t&, const date_t&");
+ bool _weekly = false)
+ : years(_years), months(_months), days(_days), weekly(_weekly) {
+ TRACE_CTOR(interval_t, "int, int, int, bool");
}
interval_t(const interval_t& other)
: years(other.years),
months(other.months),
days(other.days),
- weekly(other.weekly),
- begin(other.begin),
- end(other.end) {
+ weekly(other.weekly) {
TRACE_CTOR(interval_t, "copy");
}
interval_t(const string& desc)
- : years(0), months(0), days(0), weekly(false), begin(), end() {
+ : years(0), months(0), days(0), weekly(false) {
TRACE_CTOR(interval_t, "const string&");
std::istringstream stream(desc);
parse(stream);
}
-
~interval_t() throw() {
TRACE_DTOR(interval_t);
}
@@ -172,9 +199,11 @@ struct interval_t
return years != 0 || months != 0 || days != 0;
}
+#if 0
void set_start(const date_t& moment) {
begin = first(moment);
}
+#endif
date_t first(const optional<date_t>& moment = none);
date_t increment(const date_t&) const;