Feature #446 - start of {week, month, year}
- Added sow (depending on rc.weekstart), som and soy as possible dates (similar to eow, eom and eoy).
This commit is contained in:
24
src/Date.cpp
24
src/Date.cpp
@@ -887,6 +887,9 @@ bool Date::isRelativeDate (const std::string& input)
|
||||
supported.push_back ("eow");
|
||||
supported.push_back ("eom");
|
||||
supported.push_back ("eoy");
|
||||
supported.push_back ("sow");
|
||||
supported.push_back ("som");
|
||||
supported.push_back ("soy");
|
||||
supported.push_back ("goodfriday");
|
||||
supported.push_back ("easter");
|
||||
supported.push_back ("eastermonday");
|
||||
@@ -903,11 +906,16 @@ bool Date::isRelativeDate (const std::string& input)
|
||||
// If day name.
|
||||
int dow;
|
||||
if ((dow = Date::dayOfWeek (found)) != -1 ||
|
||||
found == "eow")
|
||||
found == "eow" ||
|
||||
found == "eocw" ||
|
||||
found == "sow")
|
||||
{
|
||||
if (found == "eow")
|
||||
dow = 5;
|
||||
|
||||
if (found == "sow")
|
||||
dow =Date::dayOfWeek (context.config.get ("weekstart"));
|
||||
|
||||
if (today.dayOfWeek () >= dow)
|
||||
today += (dow - today.dayOfWeek () + 7) * 86400;
|
||||
else
|
||||
@@ -958,6 +966,20 @@ bool Date::isRelativeDate (const std::string& input)
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
else if (found == "som")
|
||||
{
|
||||
Date then (today.month (),
|
||||
1,
|
||||
today.year ());
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
else if (found == "soy")
|
||||
{
|
||||
Date then (1, 1, today.year ());
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
else if (found == "goodfriday")
|
||||
{
|
||||
Date then (Date::easter(today.year()));
|
||||
|
||||
@@ -34,7 +34,7 @@ Context context;
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (144);
|
||||
UnitTest t (147);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -307,13 +307,22 @@ int main (int argc, char** argv)
|
||||
Date r13 ("eoy");
|
||||
t.ok (r13.sameYear (now), "eoy in same year as now");
|
||||
|
||||
// Date::sameHour
|
||||
Date r14 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
|
||||
Date r15 ("6/7/2010 01:59:59", "m/d/Y H:N:S");
|
||||
t.ok (r14.sameHour (r15), "two dates within the same hour");
|
||||
Date r14 ("sow");
|
||||
t.ok (r14 < now + (8 * 86400), "sow < 7 days away");
|
||||
|
||||
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");
|
||||
Date r15 ("som");
|
||||
t.ok (r15.sameMonth (now), "eom in same month as now");
|
||||
|
||||
Date r16 ("soy");
|
||||
t.ok (r16.sameYear (now), "eoy in same year as now");
|
||||
|
||||
// Date::sameHour
|
||||
Date r17 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
|
||||
Date r18 ("6/7/2010 01:59:59", "m/d/Y H:N:S");
|
||||
t.ok (r17.sameHour (r18), "two dates within the same hour");
|
||||
|
||||
Date r19 ("6/7/2010 00:59:59", "m/d/Y H:N:S");
|
||||
t.notok (r17.sameHour (r19), "two dates not within the same hour");
|
||||
|
||||
// TODO Date::operator-
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user