mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Date
- Added a new date parse method that indicates the length of the parsed item, and does not require Nibbler::depletion.
This commit is contained in:
parent
17ffe3d222
commit
0c0e36993d
3 changed files with 59 additions and 16 deletions
54
src/Date.cpp
54
src/Date.cpp
|
@ -131,8 +131,7 @@ Date::Date (
|
|||
const std::string& input,
|
||||
const std::string& format /* = "m/d/Y" */,
|
||||
const bool iso /* = true */,
|
||||
const bool epoch /* = true */,
|
||||
const bool require_depletion /* = true */)
|
||||
const bool epoch /* = true */)
|
||||
{
|
||||
// Check first to see if this is supported as a named date.
|
||||
Variant v;
|
||||
|
@ -146,13 +145,13 @@ Date::Date (
|
|||
Nibbler n (input);
|
||||
n.save ();
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
if (n.getDate (format, _t) && (!require_depletion || n.depleted ()))
|
||||
if (n.getDate (format, _t) && n.depleted ())
|
||||
return;
|
||||
#endif
|
||||
|
||||
// Parse an ISO date.
|
||||
n.restore ();
|
||||
if (iso && n.getDateISO (_t) && (!require_depletion || n.depleted ()))
|
||||
if (iso && n.getDateISO (_t) && n.depleted ())
|
||||
return;
|
||||
|
||||
// Perhaps it is an epoch date, in string form?
|
||||
|
@ -163,6 +162,53 @@ Date::Date (
|
|||
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (
|
||||
const std::string& input,
|
||||
std::string::size_type& i,
|
||||
const std::string& format /* = "m/d/Y" */,
|
||||
const bool iso /* = true */,
|
||||
const bool epoch /* = true */)
|
||||
{
|
||||
// Check first to see if this is supported as a named date.
|
||||
Variant v;
|
||||
if (namedDates (input, v))
|
||||
{
|
||||
i = v.source ().length ();
|
||||
_t = v.get_date ();
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse a formatted date.
|
||||
Nibbler n (input);
|
||||
n.save ();
|
||||
#ifdef NIBBLER_FEATURE_DATE
|
||||
if (n.getDate (format, _t))
|
||||
{
|
||||
i = n.cursor ();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Parse an ISO date.
|
||||
n.restore ();
|
||||
if (iso && n.getDateISO (_t))
|
||||
{
|
||||
i = n.cursor ();
|
||||
return;
|
||||
}
|
||||
|
||||
// Perhaps it is an epoch date, in string form?
|
||||
n.restore ();
|
||||
if (epoch && isEpoch (input))
|
||||
{
|
||||
i = 10;
|
||||
return;
|
||||
}
|
||||
|
||||
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
Date::Date (const Date& rhs)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue