mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Variant
- Attempts legacy date conversion ahead of ISO.
This commit is contained in:
parent
7196ac8554
commit
a470e50ee6
1 changed files with 49 additions and 27 deletions
|
@ -277,10 +277,15 @@ bool Variant::operator< (const Variant& other) const
|
|||
case type_string:
|
||||
switch (right._type)
|
||||
{
|
||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
||||
case type_boolean: right.cast (type_string); return left._string < right._string;
|
||||
case type_integer: right.cast (type_string); return left._string < right._string;
|
||||
case type_real: right.cast (type_string); return left._string < right._string;
|
||||
case type_unknown:
|
||||
throw std::string ("Cannot compare unknown type");
|
||||
|
||||
case type_boolean:
|
||||
case type_integer:
|
||||
case type_real:
|
||||
right.cast (type_string);
|
||||
return left._string < right._string;
|
||||
|
||||
case type_string:
|
||||
if (left.source () == "priority" || right.source () == "priority")
|
||||
{
|
||||
|
@ -293,6 +298,7 @@ bool Variant::operator< (const Variant& other) const
|
|||
{
|
||||
return left._string < right._string;
|
||||
}
|
||||
|
||||
case type_date: left.cast (type_date); return left._date < right._date;
|
||||
case type_duration: left.cast (type_duration); return left._duration < right._duration;
|
||||
}
|
||||
|
@ -301,26 +307,40 @@ bool Variant::operator< (const Variant& other) const
|
|||
case type_date:
|
||||
switch (right._type)
|
||||
{
|
||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
||||
case type_boolean: right.cast (type_date); return left._date < right._date;
|
||||
case type_integer: right.cast (type_date); return left._date < right._date;
|
||||
case type_real: right.cast (type_date); return left._date < right._date;
|
||||
case type_string: right.cast (type_date); return left._date < right._date;
|
||||
case type_date: return left._date < right._date;
|
||||
case type_duration: return left._date < right._duration;
|
||||
case type_unknown:
|
||||
throw std::string ("Cannot compare unknown type");
|
||||
|
||||
case type_boolean:
|
||||
case type_integer:
|
||||
case type_real:
|
||||
case type_string:
|
||||
case type_date:
|
||||
case type_duration:
|
||||
right.cast (type_date);
|
||||
if (left._date == 0 || right._date == 0)
|
||||
return false;
|
||||
|
||||
return left._date < right._date;
|
||||
}
|
||||
break;
|
||||
|
||||
case type_duration:
|
||||
switch (right._type)
|
||||
{
|
||||
case type_unknown: throw std::string ("Cannot compare unknown type");
|
||||
case type_boolean: right.cast (type_duration); return left._duration < right._duration;
|
||||
case type_integer: right.cast (type_duration); return left._duration < right._duration;
|
||||
case type_real: right.cast (type_duration); return left._duration < right._duration;
|
||||
case type_string: right.cast (type_duration); return left._duration < right._duration;
|
||||
case type_date: return left._duration < right._date;
|
||||
case type_duration: return left._duration < right._duration;
|
||||
case type_unknown:
|
||||
throw std::string ("Cannot compare unknown type");
|
||||
|
||||
case type_boolean:
|
||||
case type_integer:
|
||||
case type_real:
|
||||
case type_string:
|
||||
case type_date:
|
||||
case type_duration:
|
||||
right.cast (type_duration);
|
||||
if (left._duration == 0 || right._duration == 0)
|
||||
return false;
|
||||
|
||||
return left._duration < right._duration;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1661,19 +1681,21 @@ void Variant::cast (const enum type new_type)
|
|||
case type_date:
|
||||
{
|
||||
_date = 0;
|
||||
ISO8601d iso;
|
||||
std::string::size_type pos = 0;
|
||||
if (iso.parse (_string, pos) &&
|
||||
pos == _string.length ())
|
||||
{
|
||||
_date = (time_t) iso;
|
||||
}
|
||||
// Support legacy date formats.
|
||||
else if (dateFormat != "")
|
||||
if (dateFormat != "")
|
||||
{
|
||||
Date d (_string, dateFormat);
|
||||
_date = d.toEpoch ();
|
||||
}
|
||||
else
|
||||
{
|
||||
ISO8601d iso;
|
||||
std::string::size_type pos = 0;
|
||||
if (iso.parse (_string, pos) &&
|
||||
pos == _string.length ())
|
||||
{
|
||||
_date = (time_t) iso;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case type_duration:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue