diff --git a/src/Variant.cpp b/src/Variant.cpp index 08610fd61..cefbaf96c 100644 --- a/src/Variant.cpp +++ b/src/Variant.cpp @@ -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: