diff options
author | John Wiegley <johnw@newartisans.com> | 2009-10-31 00:55:56 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2009-10-31 00:55:56 -0400 |
commit | a2cb549b1dff9024e3f700203e424e496b25fd91 (patch) | |
tree | 1c03e9eb6f649a1446021dfb2a5d93a697f81feb /src/times.h | |
parent | 349fc5d175bc5c4acbc478b4d78c12dc507c4f58 (diff) | |
parent | a88a4c55b2b11d58d3b9e49bf785be42afe63510 (diff) | |
download | fork-ledger-a2cb549b1dff9024e3f700203e424e496b25fd91.tar.gz fork-ledger-a2cb549b1dff9024e3f700203e424e496b25fd91.tar.bz2 fork-ledger-a2cb549b1dff9024e3f700203e424e496b25fd91.zip |
Merge branch 'next'
Diffstat (limited to 'src/times.h')
-rw-r--r-- | src/times.h | 88 |
1 files changed, 84 insertions, 4 deletions
diff --git a/src/times.h b/src/times.h index 69e3af51..db83d175 100644 --- a/src/times.h +++ b/src/times.h @@ -119,10 +119,71 @@ void set_input_date_format(const char * format); class date_interval_t : public equality_comparable<date_interval_t> { public: - typedef variant<gregorian::days, - gregorian::weeks, - gregorian::months, - gregorian::years> duration_t; + struct duration_t + { + enum skip_quantum_t { + DAYS, WEEKS, MONTHS, YEARS + } quantum; + int length; + + duration_t() : quantum(DAYS), length(0) { + TRACE_CTOR(date_interval_t::duration_t, ""); + } + duration_t(skip_quantum_t _quantum, int _length) + : quantum(_quantum), length(_length) { + TRACE_CTOR(date_interval_t::duration_t, "skip_quantum_t, int"); + } + duration_t(const duration_t& dur) + : quantum(dur.quantum), length(dur.length) { + TRACE_CTOR(date_interval_t::duration_t, "copy"); + } + ~duration_t() throw() { + TRACE_DTOR(date_interval_t::duration_t); + } + + date_t add(const date_t& date) const { + switch (quantum) { + case DAYS: + return date + gregorian::days(length); + case WEEKS: + return date + gregorian::weeks(length); + case MONTHS: + return date + gregorian::months(length); + case YEARS: + return date + gregorian::years(length); + default: + assert(0); return date_t(); + } + } + + date_t subtract(const date_t& date) const { + switch (quantum) { + case DAYS: + return date - gregorian::days(length); + case WEEKS: + return date - gregorian::weeks(length); + case MONTHS: + return date - gregorian::months(length); + case YEARS: + return date - gregorian::years(length); + default: + assert(0); return date_t(); + } + } + +#if defined(HAVE_BOOST_SERIALIZATION) + private: + /** Serialization. */ + + friend class boost::serialization::access; + + template<class Archive> + void serialize(Archive & ar, const unsigned int /* version */) { + ar & quantum; + ar & length; + } +#endif // HAVE_BOOST_SERIALIZATION + }; static date_t add_duration(const date_t& date, const duration_t& duration); @@ -196,6 +257,25 @@ public: } date_interval_t& operator++(); + +#if defined(HAVE_BOOST_SERIALIZATION) +private: + /** Serialization. */ + + friend class boost::serialization::access; + + template<class Archive> + void serialize(Archive & ar, const unsigned int /* version */) { + ar & start; + ar & aligned; + ar & skip_duration; + ar & factor; + ar & next; + ar & duration; + ar & end_of_duration; + ar & end; + } +#endif // HAVE_BOOST_SERIALIZATION }; void times_initialize(); |