mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
- Added support for ordinal relative dates, like "23rd".
This commit is contained in:
parent
42d164863a
commit
0d3a93ea20
4 changed files with 64 additions and 3 deletions
|
@ -18,6 +18,7 @@ represents a feature release, and the Z represents a patch.
|
|||
+ Added averages to the "task history" report
|
||||
+ Added ability to override ~/.taskrc with rc:<file>
|
||||
+ Added bar chart history report "task ghistory"
|
||||
+ Supports relative due: dates (tomorrow, wednesday, 23rd, eom ...)
|
||||
+ Bug: Fixed where Esc[0m sequences were being emitted for no good reason
|
||||
+ Bug: Fixed underlined table headers when color is turned off
|
||||
|
||||
|
|
|
@ -54,6 +54,8 @@
|
|||
<li>Added bar chart history report "task ghistory"
|
||||
<li>Added support for rc:<file> to allow override of the default
|
||||
~/.taskrc file
|
||||
<li>Added support for relative due: dates, such as "tomorrow", "friday",
|
||||
"23rd", "eom"
|
||||
<li>Fixed bug where Esc[0m sequences were being emitted for no good reason
|
||||
<li>Fixed bug where table headers are underlined when color is turned off
|
||||
</ul>
|
||||
|
|
61
src/Date.cpp
61
src/Date.cpp
|
@ -508,6 +508,7 @@ time_t Date::operator- (const Date& rhs)
|
|||
bool Date::isRelativeDate (const std::string& input)
|
||||
{
|
||||
std::string in (lowerCase (input));
|
||||
Date today;
|
||||
|
||||
std::vector <std::string> supported;
|
||||
supported.push_back ("monday");
|
||||
|
@ -528,7 +529,6 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
if (autoComplete (in, supported, matches) == 1)
|
||||
{
|
||||
std::string found = matches[0];
|
||||
Date today;
|
||||
|
||||
// If day name.
|
||||
int dow;
|
||||
|
@ -575,7 +575,64 @@ bool Date::isRelativeDate (const std::string& input)
|
|||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
// \d|\d\d|\d\d\d|\d\d\d\d st|nd|rd|th
|
||||
}
|
||||
|
||||
// Support "21st" to indicate the next date that is the 21st day.
|
||||
else if (input.length () <= 4 &&
|
||||
isdigit (input[0]))
|
||||
{
|
||||
int number;
|
||||
std::string ordinal;
|
||||
|
||||
if (isdigit (input[1]))
|
||||
{
|
||||
number = ::atoi (input.substr (0, 2).c_str ());
|
||||
ordinal = lowerCase (input.substr (2, std::string::npos));
|
||||
}
|
||||
else
|
||||
{
|
||||
number = ::atoi (input.substr (0, 2).c_str ());
|
||||
ordinal = lowerCase (input.substr (1, std::string::npos));
|
||||
}
|
||||
|
||||
// Sanity check.
|
||||
if (number <= 31)
|
||||
{
|
||||
if (ordinal == "st" ||
|
||||
ordinal == "nd" ||
|
||||
ordinal == "rd" ||
|
||||
ordinal == "th")
|
||||
{
|
||||
int m = today.month ();
|
||||
int d = today.day ();
|
||||
int y = today.year ();
|
||||
|
||||
// If it is this month.
|
||||
if (d < number &&
|
||||
number <= Date::daysInMonth (m, y))
|
||||
{
|
||||
Date then (m, number, y);
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
m++;
|
||||
|
||||
if (m > 12)
|
||||
{
|
||||
m = 1;
|
||||
y++;
|
||||
}
|
||||
}
|
||||
while (number > Date::daysInMonth (m, y));
|
||||
|
||||
Date then (m, number, y);
|
||||
mT = then.mT;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -211,7 +211,8 @@ int main (int argc, char** argv)
|
|||
|
||||
catch (std::string& e)
|
||||
{
|
||||
std::cout << e << std::endl;
|
||||
fail ("Exception thrown.");
|
||||
diag (e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue