Variant: Converted from ISO8601p to Duration

This commit is contained in:
Paul Beckingham
2016-12-11 21:03:15 -05:00
parent abd4cfc4ed
commit d9a3be9993

View File

@@ -32,6 +32,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <Variant.h> #include <Variant.h>
#include <ISO8601.h> #include <ISO8601.h>
#include <Datetime.h>
#include <Duration.h>
#include <Lexer.h> #include <Lexer.h>
#include <RX.h> #include <RX.h>
#include <shared.h> #include <shared.h>
@@ -1730,10 +1732,10 @@ Variant::operator std::string () const
return _string; return _string;
case type_date: case type_date:
return ISO8601d (_date).toISOLocalExtended (); return Datetime (_date).toISOLocalExtended ();
case type_duration: case type_duration:
return ISO8601p (_duration).format (); return Duration (_duration).formatISO ();
} }
return ""; return "";
@@ -1836,11 +1838,11 @@ void Variant::cast (const enum type new_type)
} }
pos = 0; pos = 0;
ISO8601p isop; Duration isop;
if (isop.parse (_string, pos) && if (isop.parse (_string, pos) &&
pos == _string.length ()) pos == _string.length ())
{ {
_date = ISO8601d ().toEpoch () + (time_t) isop; _date = ISO8601d ().toEpoch () + isop.toTime_t ();
break; break;
} }
@@ -1855,11 +1857,11 @@ void Variant::cast (const enum type new_type)
{ {
_duration = 0; _duration = 0;
std::string::size_type pos = 0; std::string::size_type pos = 0;
ISO8601p iso; Duration iso;
if (iso.parse (_string, pos) && if (iso.parse (_string, pos) &&
pos == _string.length ()) pos == _string.length ())
{ {
_duration = (time_t) iso; _duration = iso.toTime_t ();
} }
} }
break; break;