From cb4fe4fffb5e3dcaba5cff9c5c40479069cd583d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 25 Jul 2010 22:02:41 -0400 Subject: [PATCH] Enhancement - Date::operator- - Implemented Date::operator-, to allow subtractions of Durations. --- src/Date.cpp | 9 +++++++-- src/Date.h | 1 + src/tests/date.t.cpp | 2 ++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Date.cpp b/src/Date.cpp index 6e5a74030..8aaa1187c 100644 --- a/src/Date.cpp +++ b/src/Date.cpp @@ -24,7 +24,6 @@ // USA // //////////////////////////////////////////////////////////////////////////////// -#include #include #include #include @@ -138,7 +137,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */) throw std::string ("\"") + input + "\" is not a valid date (d)."; } - if (i + 1 < input.length () && + if (i + 1 < input.length () && (input[i + 0] == '0' || input[i + 0] == '1' || input[i + 0] == '2' || input[i + 0] == '3') && isdigit (input[i + 1])) { @@ -808,6 +807,12 @@ bool Date::sameYear (const Date& rhs) return false; } +//////////////////////////////////////////////////////////////////////////////// +Date Date::operator- (const int delta) +{ + return Date (mT - delta); +} + //////////////////////////////////////////////////////////////////////////////// Date Date::operator+ (const int delta) { diff --git a/src/Date.h b/src/Date.h index 0523e4366..39195d520 100644 --- a/src/Date.h +++ b/src/Date.h @@ -85,6 +85,7 @@ public: bool sameYear (const Date&); Date operator+ (const int); + Date operator- (const int); Date& operator+= (const int); Date& operator-= (const int); diff --git a/src/tests/date.t.cpp b/src/tests/date.t.cpp index 44bbf44d9..5f235c708 100644 --- a/src/tests/date.t.cpp +++ b/src/tests/date.t.cpp @@ -314,6 +314,8 @@ int main (int argc, char** argv) Date r16 ("6/7/2010 00:59:59", "m/d/Y H:N:S"); t.notok (r14.sameHour (r16), "two dates not within the same hour"); + + // TODO Date::operator- } catch (std::string& e)