mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +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& input,
|
||||||
const std::string& format /* = "m/d/Y" */,
|
const std::string& format /* = "m/d/Y" */,
|
||||||
const bool iso /* = true */,
|
const bool iso /* = true */,
|
||||||
const bool epoch /* = true */,
|
const bool epoch /* = true */)
|
||||||
const bool require_depletion /* = true */)
|
|
||||||
{
|
{
|
||||||
// Check first to see if this is supported as a named date.
|
// Check first to see if this is supported as a named date.
|
||||||
Variant v;
|
Variant v;
|
||||||
|
@ -146,13 +145,13 @@ Date::Date (
|
||||||
Nibbler n (input);
|
Nibbler n (input);
|
||||||
n.save ();
|
n.save ();
|
||||||
#ifdef NIBBLER_FEATURE_DATE
|
#ifdef NIBBLER_FEATURE_DATE
|
||||||
if (n.getDate (format, _t) && (!require_depletion || n.depleted ()))
|
if (n.getDate (format, _t) && n.depleted ())
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Parse an ISO date.
|
// Parse an ISO date.
|
||||||
n.restore ();
|
n.restore ();
|
||||||
if (iso && n.getDateISO (_t) && (!require_depletion || n.depleted ()))
|
if (iso && n.getDateISO (_t) && n.depleted ())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Perhaps it is an epoch date, in string form?
|
// Perhaps it is an epoch date, in string form?
|
||||||
|
@ -163,6 +162,53 @@ Date::Date (
|
||||||
throw ::format (STRING_DATE_INVALID_FORMAT, input, format);
|
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)
|
Date::Date (const Date& rhs)
|
||||||
{
|
{
|
||||||
|
|
|
@ -43,8 +43,12 @@ public:
|
||||||
Date (const std::string&,
|
Date (const std::string&,
|
||||||
const std::string& format = "m/d/Y",
|
const std::string& format = "m/d/Y",
|
||||||
const bool iso = true,
|
const bool iso = true,
|
||||||
const bool epoch = true,
|
const bool epoch = true);
|
||||||
const bool require_depletion = true);
|
Date (const std::string&,
|
||||||
|
std::string::size_type&,
|
||||||
|
const std::string& format = "m/d/Y",
|
||||||
|
const bool iso = true,
|
||||||
|
const bool epoch = true);
|
||||||
Date (const Date&);
|
Date (const Date&);
|
||||||
virtual ~Date ();
|
virtual ~Date ();
|
||||||
|
|
||||||
|
|
|
@ -660,17 +660,10 @@ bool Lexer::is_date (std::string& result)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TODO Why stop at the space? This seems wrong.
|
std::string::size_type legacy_i = 0;
|
||||||
std::string::size_type legacy_i = _input.find (' ', _i);
|
Date legacyDate (_input.substr (_shift_counter), legacy_i, Lexer::dateFormat, false, false);
|
||||||
if (legacy_i == std::string::npos)
|
result = _input.substr (_shift_counter, legacy_i);
|
||||||
legacy_i = _input.length ();
|
|
||||||
|
|
||||||
std::string legacy_result = _input.substr (_shift_counter, legacy_i - _shift_counter);
|
|
||||||
Date legacyDate (legacy_result, Lexer::dateFormat, false, false, false);
|
|
||||||
|
|
||||||
legacy_i -= _shift_counter;
|
|
||||||
while (legacy_i--) shift ();
|
while (legacy_i--) shift ();
|
||||||
result = legacy_result;
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue