mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Feature #446 - start of {week, month, year}
- Bug fix for som and soy. - Added synonyms soww and eoww for sow and eow. - Added start/end of calendar week: socw and eocw.
This commit is contained in:
parent
96bd3ff8db
commit
903b5b34d4
5 changed files with 57 additions and 19 deletions
34
src/Date.cpp
34
src/Date.cpp
|
@ -885,9 +885,13 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
supported.push_back ("tomorrow");
|
||||
supported.push_back ("yesterday");
|
||||
supported.push_back ("eow");
|
||||
supported.push_back ("eoww");
|
||||
supported.push_back ("eocw");
|
||||
supported.push_back ("eom");
|
||||
supported.push_back ("eoy");
|
||||
supported.push_back ("sow");
|
||||
supported.push_back ("soww");
|
||||
supported.push_back ("socw");
|
||||
supported.push_back ("som");
|
||||
supported.push_back ("soy");
|
||||
supported.push_back ("goodfriday");
|
||||
|
@ -907,14 +911,23 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
int dow;
|
||||
if ((dow = Date::dayOfWeek (found)) != -1 ||
|
||||
found == "eow" ||
|
||||
found == "eoww" ||
|
||||
found == "eocw" ||
|
||||
found == "sow")
|
||||
found == "sow" ||
|
||||
found == "soww" ||
|
||||
found == "socw")
|
||||
{
|
||||
if (found == "eow")
|
||||
if (found == "eow" || found == "eoww")
|
||||
dow = 5;
|
||||
|
||||
if (found == "sow")
|
||||
dow =Date::dayOfWeek (context.config.get ("weekstart"));
|
||||
if (found == "eocw")
|
||||
dow = (Date::dayOfWeek (context.config.get ("weekstart")) + 6) % 7;
|
||||
|
||||
if (found == "sow" || found == "soww")
|
||||
dow = 1;
|
||||
|
||||
if (found == "socw")
|
||||
dow = Date::dayOfWeek (context.config.get ("weekstart"));
|
||||
|
||||
if (today.dayOfWeek () >= dow)
|
||||
today += (dow - today.dayOfWeek () + 7) * 86400;
|
||||
|
@ -968,15 +981,20 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
}
|
||||
else if (found == "som")
|
||||
{
|
||||
Date then (today.month (),
|
||||
1,
|
||||
today.year ());
|
||||
int m = today.month () + 1;
|
||||
int y = today.year ();
|
||||
if (m > 12)
|
||||
{
|
||||
m -=12;
|
||||
y++;
|
||||
}
|
||||
Date then (m, 1, y);
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
else if (found == "soy")
|
||||
{
|
||||
Date then (1, 1, today.year ());
|
||||
Date then (1, 1, today.year () + 1);
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (147);
|
||||
UnitTest t (149);
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -301,6 +301,9 @@ int main (int argc, char** argv)
|
|||
Date r11 ("eow");
|
||||
t.ok (r11 < now + (8 * 86400), "eow < 7 days away");
|
||||
|
||||
Date r20 ("eocw");
|
||||
t.ok (r20 < now + (8 * 86400), "eocw < 7 days away");
|
||||
|
||||
Date r12 ("eom");
|
||||
t.ok (r12.sameMonth (now), "eom in same month as now");
|
||||
|
||||
|
@ -310,11 +313,14 @@ int main (int argc, char** argv)
|
|||
Date r14 ("sow");
|
||||
t.ok (r14 < now + (8 * 86400), "sow < 7 days away");
|
||||
|
||||
Date r21 ("socw");
|
||||
t.ok (r21 < now + (8 * 86400), "sow < 7 days away");
|
||||
|
||||
Date r15 ("som");
|
||||
t.ok (r15.sameMonth (now), "eom in same month as now");
|
||||
t.notok (r15.sameMonth (now), "som not in same month as now");
|
||||
|
||||
Date r16 ("soy");
|
||||
t.ok (r16.sameYear (now), "eoy in same year as now");
|
||||
t.notok (r16.sameYear (now), "soy not in same year as now");
|
||||
|
||||
// Date::sameHour
|
||||
Date r17 ("6/7/2010 01:00:00", "m/d/Y H:N:S");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue