summaryrefslogtreecommitdiff
path: root/value.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2008-08-01 17:37:22 -0400
committerJohn Wiegley <johnw@newartisans.com>2008-08-01 17:37:22 -0400
commit858978de8931ce5c98882472b10051f4e57dd029 (patch)
tree2da6d0d78cc223b9f60c3161951b3b67bd1ccd4a /value.h
parentea3b386062e62379c546239f2e95cb1e11c56d23 (diff)
downloadfork-ledger-858978de8931ce5c98882472b10051f4e57dd029.tar.gz
fork-ledger-858978de8931ce5c98882472b10051f4e57dd029.tar.bz2
fork-ledger-858978de8931ce5c98882472b10051f4e57dd029.zip
Journal data structures now use date_t instead of datetime_t.
This means transactions can only have day-level granularity -- which has always been the case from an data file point of view. The advantage to this restriction is that reports will now be immune from daylight savings related bugs, where a transaction falls to the wrong side of a --monthly report, for example.
Diffstat (limited to 'value.h')
-rw-r--r--value.h30
1 files changed, 28 insertions, 2 deletions
diff --git a/value.h b/value.h
index 35a44828..4754de61 100644
--- a/value.h
+++ b/value.h
@@ -102,6 +102,7 @@ public:
VOID, // a null value (i.e., uninitialized)
BOOLEAN, // a boolean
DATETIME, // a date and time (Boost posix_time)
+ DATE, // a date (Boost gregorian::date)
INTEGER, // a signed integer value
AMOUNT, // a ledger::amount_t
BALANCE, // a ledger::balance_t
@@ -267,10 +268,14 @@ public:
set_boolean(val);
}
- value_t(const datetime_t val) {
- TRACE_CTOR(value_t, "const datetime_t");
+ value_t(const datetime_t& val) {
+ TRACE_CTOR(value_t, "const datetime_t&");
set_datetime(val);
}
+ value_t(const date_t& val) {
+ TRACE_CTOR(value_t, "const date_t&");
+ set_date(val);
+ }
value_t(const long val) {
TRACE_CTOR(value_t, "const long");
@@ -459,6 +464,7 @@ public:
* is_boolean()
* is_long()
* is_datetime()
+ * is_date()
* is_amount()
* is_balance()
* is_balance_pair()
@@ -514,6 +520,23 @@ public:
new(reinterpret_cast<datetime_t *>(storage->data)) datetime_t(val);
}
+ bool is_date() const {
+ return is_type(DATE);
+ }
+ date_t& as_date_lval() {
+ assert(is_date());
+ _dup();
+ return *reinterpret_cast<date_t *>(storage->data);
+ }
+ const date_t& as_date() const {
+ assert(is_date());
+ return *reinterpret_cast<date_t *>(storage->data);
+ }
+ void set_date(const date_t& val) {
+ set_type(DATE);
+ new(reinterpret_cast<date_t *>(storage->data)) date_t(val);
+ }
+
bool is_long() const {
return is_type(INTEGER);
}
@@ -695,6 +718,7 @@ public:
bool to_boolean() const;
long to_long() const;
datetime_t to_datetime() const;
+ date_t to_date() const;
amount_t to_amount() const;
balance_t to_balance() const;
balance_pair_t to_balance_pair() const;
@@ -828,6 +852,8 @@ public:
return "a boolean";
case DATETIME:
return "a date/time";
+ case DATE:
+ return "a date";
case INTEGER:
return "an integer";
case AMOUNT: