mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
ISO8601: Restored support for the UTC & local non-extended full form
This commit is contained in:
parent
a7982e434a
commit
b0c8f4ca4f
3 changed files with 44 additions and 3 deletions
|
@ -48,7 +48,9 @@ ISO8601d::operator time_t () const
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Supported:
|
||||
//
|
||||
// result ::= date-ext 'T' time-ext 'Z' # UTC
|
||||
// result ::= date 'T' time 'Z' # UTC
|
||||
// | date 'T' time # Local
|
||||
// | date-ext 'T' time-ext 'Z' # UTC
|
||||
// | date-ext 'T' time-ext offset-ext # Specified TZ
|
||||
// | date-ext 'T' time-ext # Local
|
||||
// | date-ext # Local
|
||||
|
@ -93,7 +95,8 @@ bool ISO8601d::parse (const std::string& input, std::string::size_type& start)
|
|||
auto i = start;
|
||||
Nibbler n (input.substr (i));
|
||||
|
||||
if (parse_date_time_ext (n) || // Most complex first.
|
||||
if (parse_date_time (n) || // Most complex first.
|
||||
parse_date_time_ext (n) ||
|
||||
parse_date_ext (n) ||
|
||||
parse_time_utc_ext (n) ||
|
||||
parse_time_off_ext (n) ||
|
||||
|
@ -135,6 +138,39 @@ void ISO8601d::set_default_time (int hours, int minutes, int seconds)
|
|||
_default_seconds = (hours * 3600) + (minutes * 60) + seconds;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
bool ISO8601d::parse_date_time (Nibbler& n)
|
||||
{
|
||||
n.save ();
|
||||
int year, month, day, hour, minute, second;
|
||||
if (n.getDigit4 (year) &&
|
||||
n.getDigit2 (month) &&
|
||||
n.getDigit2 (day) &&
|
||||
n.skip ('T') &&
|
||||
n.getDigit2 (hour) &&
|
||||
n.getDigit2 (minute) &&
|
||||
n.getDigit2 (second))
|
||||
{
|
||||
if (n.skip ('Z'))
|
||||
_utc = true;
|
||||
|
||||
_year = year;
|
||||
_month = month;
|
||||
_day = day;
|
||||
_seconds = (((hour * 60) + minute) * 60) + second;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_year = 0;
|
||||
_month = 0;
|
||||
_day = 0;
|
||||
_seconds = 0;
|
||||
|
||||
n.restore ();
|
||||
return false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// date-ext 'T' time-ext 'Z'
|
||||
// date-ext 'T' time-ext offset-ext
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
void set_default_time (int, int, int);
|
||||
|
||||
private:
|
||||
bool parse_date_time (Nibbler&);
|
||||
bool parse_date_time_ext (Nibbler&);
|
||||
bool parse_date_ext (Nibbler&);
|
||||
bool parse_off_ext (Nibbler&);
|
||||
|
|
|
@ -71,7 +71,7 @@ void testParse (
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
int main (int argc, char** argv)
|
||||
{
|
||||
UnitTest t (734);
|
||||
UnitTest t (758);
|
||||
|
||||
ISO8601d iso;
|
||||
std::string::size_type start = 0;
|
||||
|
@ -212,6 +212,10 @@ int main (int argc, char** argv)
|
|||
testParse (t, "2013-W49T12:34-01:00", 20, 2013, 0, 49, 0, 0, 0, hm, -3600, false, utc1+hm+z );
|
||||
testParse (t, "2013-W49T12:34-01", 17, 2013, 0, 49, 0, 0, 0, hm, -3600, false, utc1+hm+z );
|
||||
|
||||
// The only non-extended forms.
|
||||
testParse (t, "20131206T123456Z", 16, 2013, 12, 0, 0, 0, 6, hms, 0, true, utc6+hms );
|
||||
testParse (t, "20131206T123456", 15, 2013, 12, 0, 0, 0, 6, hms, 0, false, local6+hms);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue