mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Duration
- Distinguishes between a 'standalone' duration like 'year', and one that requires a numeric leader, '2 weeks'.
This commit is contained in:
parent
9095f47ff3
commit
5170a842d6
1 changed files with 32 additions and 12 deletions
|
@ -290,26 +290,45 @@ bool Duration::parse (const std::string& input, std::string::size_type& start)
|
|||
|
||||
std::string number;
|
||||
std::string unit;
|
||||
if ((n.getNumber (number) && n.skipWS () && n.getOneOf (units, unit)) ||
|
||||
n.getOneOf (units, unit))
|
||||
|
||||
if (n.getOneOf (units, unit))
|
||||
{
|
||||
if (n.depleted () ||
|
||||
Lexer::is_ws (n.next ()))
|
||||
{
|
||||
// TODO Determine which unit matched, and therefore whether the unit can
|
||||
// exist as a standalone unit (with assumed quantity of 1), or
|
||||
// whether the quantity is required.
|
||||
|
||||
start = original_start + n.cursor ();
|
||||
double quantity = (number == "")
|
||||
? 1.0
|
||||
: strtod (number.c_str (), NULL);
|
||||
|
||||
// Linear lookup - should be logarithmic.
|
||||
double seconds = 1;
|
||||
for (int i = 0; i < NUM_DURATIONS; i++)
|
||||
{
|
||||
if (durations[i].unit == unit)
|
||||
if (durations[i].unit == unit &&
|
||||
durations[i].standalone == true)
|
||||
{
|
||||
_secs = static_cast <int> (durations[i].seconds);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (n.getNumber (number))
|
||||
{
|
||||
n.skipWS ();
|
||||
if (n.getOneOf (units, unit))
|
||||
{
|
||||
if (n.depleted () ||
|
||||
Lexer::is_ws (n.next ()))
|
||||
{
|
||||
start = original_start + n.cursor ();
|
||||
double quantity = strtod (number.c_str (), NULL);
|
||||
|
||||
// Linear lookup - should be logarithmic.
|
||||
double seconds = 1;
|
||||
for (int i = 0; i < NUM_DURATIONS; i++)
|
||||
{
|
||||
if (durations[i].unit == unit &&
|
||||
durations[i].standalone == false)
|
||||
{
|
||||
seconds = durations[i].seconds;
|
||||
_secs = static_cast <int> (quantity * static_cast <double> (seconds));
|
||||
|
@ -318,6 +337,7 @@ bool Duration::parse (const std::string& input, std::string::size_type& start)
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue