Enhancement - Date::operator-
- Implemented Date::operator-, to allow subtractions of Durations.
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
// USA
|
// USA
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -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).";
|
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') &&
|
(input[i + 0] == '0' || input[i + 0] == '1' || input[i + 0] == '2' || input[i + 0] == '3') &&
|
||||||
isdigit (input[i + 1]))
|
isdigit (input[i + 1]))
|
||||||
{
|
{
|
||||||
@@ -808,6 +807,12 @@ bool Date::sameYear (const Date& rhs)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Date Date::operator- (const int delta)
|
||||||
|
{
|
||||||
|
return Date (mT - delta);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Date Date::operator+ (const int delta)
|
Date Date::operator+ (const int delta)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public:
|
|||||||
bool sameYear (const Date&);
|
bool sameYear (const Date&);
|
||||||
|
|
||||||
Date operator+ (const int);
|
Date operator+ (const int);
|
||||||
|
Date operator- (const int);
|
||||||
Date& operator+= (const int);
|
Date& operator+= (const int);
|
||||||
Date& operator-= (const int);
|
Date& operator-= (const int);
|
||||||
|
|
||||||
|
|||||||
@@ -314,6 +314,8 @@ int main (int argc, char** argv)
|
|||||||
|
|
||||||
Date r16 ("6/7/2010 00:59:59", "m/d/Y H:N:S");
|
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");
|
t.notok (r14.sameHour (r16), "two dates not within the same hour");
|
||||||
|
|
||||||
|
// TODO Date::operator-
|
||||||
}
|
}
|
||||||
|
|
||||||
catch (std::string& e)
|
catch (std::string& e)
|
||||||
|
|||||||
Reference in New Issue
Block a user