mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
- Supports durations like weekly, semiannual, daily ...
This commit is contained in:
parent
0d3a93ea20
commit
ef7ff55535
3 changed files with 76 additions and 17 deletions
|
@ -108,7 +108,7 @@ std::string formatSeconds (time_t);
|
|||
const std::string uuid ();
|
||||
const char* optionalBlankLine (Config&);
|
||||
int convertDuration (const std::string&);
|
||||
Date convertRelativeDate (const std::string&);
|
||||
int addDuration (const Date&, const std::string&);
|
||||
|
||||
// rules.cpp
|
||||
void initializeColorRules (Config&);
|
||||
|
|
|
@ -8,19 +8,18 @@
|
|||
#include <../task.h>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// daily, day, d, Nd
|
||||
// weekly, w, Nw, sennight, biweekly, fortnight
|
||||
// monthly, m, bimonthly, Nm, semimonthly
|
||||
// daily, day, Nd
|
||||
// weekly, Nw, sennight, biweekly, fortnight
|
||||
// monthly, bimonthly, Nm, semimonthly
|
||||
// 1st 2nd 3rd 4th .. 31st
|
||||
// quarterly, q, Nq
|
||||
// biannual, biyearly, annual, semiannual, yearly, y, Na, Ny
|
||||
// quarterly, Nq
|
||||
// biannual, biyearly, annual, semiannual, yearly, Ny
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
plan (19);
|
||||
plan (17);
|
||||
|
||||
is (convertDuration ("daily"), 1, "duration daily = 1");
|
||||
is (convertDuration ("day"), 1, "duration day = 1");
|
||||
is (convertDuration ("d"), 0, "duration d = 1");
|
||||
is (convertDuration ("0d"), 0, "duration 0d = 0");
|
||||
is (convertDuration ("1d"), 1, "duration 1d = 1");
|
||||
is (convertDuration ("7d"), 7, "duration 7d = 7");
|
||||
|
@ -32,7 +31,6 @@ int main (int argc, char** argv)
|
|||
is (convertDuration ("biweekly"), 14, "duration biweekly = 14");
|
||||
is (convertDuration ("fortnight"), 14, "duration fortnight = 14");
|
||||
is (convertDuration ("week"), 7, "duration week = 7");
|
||||
is (convertDuration ("w"), 7, "duration w = 7");
|
||||
is (convertDuration ("0w"), 0, "duration 0w = 0");
|
||||
is (convertDuration ("1w"), 7, "duration 1w = 7");
|
||||
is (convertDuration ("7w"), 49, "duration 7w = 49");
|
||||
|
|
77
src/util.cpp
77
src/util.cpp
|
@ -240,15 +240,76 @@ const std::string uuid ()
|
|||
// Recognize the following constructs, and return the number of days represented
|
||||
int convertDuration (const std::string& input)
|
||||
{
|
||||
// TODO
|
||||
std::string in (lowerCase (input));
|
||||
Date today;
|
||||
|
||||
std::vector <std::string> supported;
|
||||
supported.push_back ("daily");
|
||||
supported.push_back ("day");
|
||||
supported.push_back ("weekly");
|
||||
supported.push_back ("sennight");
|
||||
supported.push_back ("biweekly");
|
||||
supported.push_back ("fortnight");
|
||||
supported.push_back ("monthly");
|
||||
supported.push_back ("bimonthly");
|
||||
supported.push_back ("semimonthly");
|
||||
supported.push_back ("quarterly");
|
||||
supported.push_back ("biannual");
|
||||
supported.push_back ("biyearly");
|
||||
supported.push_back ("annual");
|
||||
supported.push_back ("semiannual");
|
||||
supported.push_back ("yearly");
|
||||
|
||||
std::vector <std::string> matches;
|
||||
if (autoComplete (in, supported, matches) == 1)
|
||||
{
|
||||
std::string found = matches[0];
|
||||
|
||||
if (found == "daily" || found == "day") return 1;
|
||||
else if (found == "weekly" || found == "sennight") return 7;
|
||||
else if (found == "biweekly" || found == "fortnight") return 14;
|
||||
else if (found == "semimonthly") return 15;
|
||||
else if (found == "monthly") return 30;
|
||||
else if (found == "bimonthly") return 61;
|
||||
else if (found == "quarterly") return 91;
|
||||
else if (found == "semiannual") return 183;
|
||||
else if (found == "yearly" || found == "annual") return 365;
|
||||
else if (found == "biannual" || found == "biyearly") return 730;
|
||||
}
|
||||
|
||||
// Support \d+ d|w|m|q|y
|
||||
|
||||
else
|
||||
{
|
||||
// Verify all digits followed by d, w, m, q, or y.
|
||||
int length = input.length ();
|
||||
for (unsigned int i = 0; i < length; ++i)
|
||||
{
|
||||
if (! isdigit (input[i]) &&
|
||||
i == length - 1)
|
||||
{
|
||||
int number = ::atoi (input.substr (0, i).c_str ());
|
||||
char ordinal = input[length - 1];
|
||||
|
||||
switch (input[length - 1])
|
||||
{
|
||||
case 'd': return number * 1; break;
|
||||
case 'w': return number * 7; break;
|
||||
case 'm': return number * 30; break;
|
||||
case 'q': return number * 91; break;
|
||||
case 'y': return number * 365; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // Error.
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int addDuration (const Date& base, const std::string& offset)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date convertRelativeDate (const std::string& input)
|
||||
{
|
||||
// TODO
|
||||
return Date ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue