- Attempts legacy date conversion ahead of ISO.
This commit is contained in:
Paul Beckingham 2014-06-02 23:30:40 -04:00
parent 7196ac8554
commit a470e50ee6

View file

@ -277,10 +277,15 @@ bool Variant::operator< (const Variant& other) const
case type_string: case type_string:
switch (right._type) switch (right._type)
{ {
case type_unknown: throw std::string ("Cannot compare unknown type"); case type_unknown:
case type_boolean: right.cast (type_string); return left._string < right._string; throw std::string ("Cannot compare unknown type");
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_boolean:
case type_integer:
case type_real:
right.cast (type_string);
return left._string < right._string;
case type_string: case type_string:
if (left.source () == "priority" || right.source () == "priority") if (left.source () == "priority" || right.source () == "priority")
{ {
@ -293,6 +298,7 @@ bool Variant::operator< (const Variant& other) const
{ {
return left._string < right._string; return left._string < right._string;
} }
case type_date: left.cast (type_date); return left._date < right._date; case type_date: left.cast (type_date); return left._date < right._date;
case type_duration: left.cast (type_duration); return left._duration < right._duration; 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: case type_date:
switch (right._type) switch (right._type)
{ {
case type_unknown: throw std::string ("Cannot compare unknown type"); case type_unknown:
case type_boolean: right.cast (type_date); return left._date < right._date; throw std::string ("Cannot compare unknown type");
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_boolean:
case type_string: right.cast (type_date); return left._date < right._date; case type_integer:
case type_date: return left._date < right._date; case type_real:
case type_duration: return left._date < right._duration; 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; break;
case type_duration: case type_duration:
switch (right._type) switch (right._type)
{ {
case type_unknown: throw std::string ("Cannot compare unknown type"); case type_unknown:
case type_boolean: right.cast (type_duration); return left._duration < right._duration; throw std::string ("Cannot compare unknown type");
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_boolean:
case type_string: right.cast (type_duration); return left._duration < right._duration; case type_integer:
case type_date: return left._duration < right._date; case type_real:
case type_duration: return left._duration < right._duration; 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; break;
} }
@ -1661,6 +1681,13 @@ void Variant::cast (const enum type new_type)
case type_date: case type_date:
{ {
_date = 0; _date = 0;
if (dateFormat != "")
{
Date d (_string, dateFormat);
_date = d.toEpoch ();
}
else
{
ISO8601d iso; ISO8601d iso;
std::string::size_type pos = 0; std::string::size_type pos = 0;
if (iso.parse (_string, pos) && if (iso.parse (_string, pos) &&
@ -1668,11 +1695,6 @@ void Variant::cast (const enum type new_type)
{ {
_date = (time_t) iso; _date = (time_t) iso;
} }
// Support legacy date formats.
else if (dateFormat != "")
{
Date d (_string, dateFormat);
_date = d.toEpoch ();
} }
} }
break; break;