Duration
- Allowed durations to be specified numerically as seconds, in string form.
This flexibility allows the removal of special-case handling that stores
recurrence periods in raw form ('monthly'), reducing code size. As a
consequence this means that recurrence may now be rendered according to
Duration::formatCompact, which is desirable.
- Added supporting unit tests.
This commit is contained in:
@@ -134,7 +134,13 @@ Duration::Duration (const std::string& input)
|
||||
: mSecs (0)
|
||||
, mNegative (false)
|
||||
{
|
||||
parse (input);
|
||||
if (digitsOnly (input))
|
||||
{
|
||||
mSecs = (time_t) strtol (input.c_str (), NULL, 10);
|
||||
mNegative = false;
|
||||
}
|
||||
else
|
||||
parse (input);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -342,6 +348,12 @@ bool Duration::valid (const std::string& input)
|
||||
std::string units;
|
||||
n.getUntilEOS (units);
|
||||
|
||||
// Non-trivial value with no units means the duration is specified in
|
||||
// seconds, and therefore a time_t. Consider it valid.
|
||||
if (value != 0.0 &&
|
||||
units == "")
|
||||
return true;
|
||||
|
||||
// Auto complete against all supported durations.
|
||||
std::vector <std::string> supported;
|
||||
for (unsigned int i = 0; i < NUM_DURATIONS; ++i)
|
||||
|
||||
Reference in New Issue
Block a user