# # # patch "dates.cc" # from [f2cbec98589e45cd6f5cf8a1e7d69e6f54f8defd] # to [9bcad49bcaea432aa27a368de34027c582c0c960] # # patch "dates.hh" # from [96d6837b825444479af1813301dcd3216881167e] # to [bea2c2fefa4a7464ec575bdcc2ae8f4ad40961b8] # ============================================================ --- dates.cc f2cbec98589e45cd6f5cf8a1e7d69e6f54f8defd +++ dates.cc 9bcad49bcaea432aa27a368de34027c582c0c960 @@ -437,30 +437,47 @@ date_t & } date_t & -date_t::operator +=(u64 const & other) +date_t::operator +=(s64 const other) { - // prevent overflows - I(other < u64_C(253402300800000)); + // only operate on vaild dates (i..e. d != 0) + I(valid()); d += other; // make sure we are still before year 10'000 I(d < u64_C(253402300800000)); + // make sure the date is still valid + I(valid()); + return *this; } date_t & -date_t::operator -=(u64 const & other) +date_t::operator -=(s64 const other) { - // prevent underflows - I(d >= other); - d -= other; - return *this; + // simply use the addition operator with inversed sign + return operator+=(-other); } +date_t +date_t::operator +(s64 const other) const +{ + date_t result(d); + result += other; + return result; +} + +date_t +date_t::operator -(s64 const other) const +{ + date_t result(d); + result += -other; + return result; +} + s64 -date_t::operator -(date_t const & other) +date_t::operator -(date_t const & other) const { return d - other.d; } @@ -740,9 +757,9 @@ UNIT_TEST(date, comparisons) UNIT_TEST_CHECK(v == jun); // check limits for subtractions - v = date_t(12345000); + v = date_t(12345000 + 1000); v -= 12345000; - UNIT_TEST_CHECK(v == date_t::from_string("1970-01-01T00:00:00")); + UNIT_TEST_CHECK(v == date_t::from_string("1970-01-01T00:00:01")); UNIT_TEST_CHECK_THROW(v -= 1000, std::logic_error); // check limits for additions ============================================================ --- dates.hh 96d6837b825444479af1813301dcd3216881167e +++ dates.hh bea2c2fefa4a7464ec575bdcc2ae8f4ad40961b8 @@ -57,11 +57,13 @@ struct date_t { return d != other.d; }; // Addition and subtraction of millisecond amounts - date_t & operator +=(u64 const & addend); - date_t & operator -=(u64 const & addend); + date_t & operator +=(s64 const other); + date_t & operator -=(s64 const other); + date_t operator +(s64 const other) const; + date_t operator -(s64 const other) const; // Difference between two dates in milliseconds - s64 operator -(date_t const & other); + s64 operator -(date_t const & other) const; private: // The date as an unsigned 64-bit count of milliseconds since