diff --git a/src/A3.cpp b/src/A3.cpp index 607e927ac..49fdec91b 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -694,9 +694,6 @@ const A3 A3::tokenize (const A3& input) const // List of operators for recognition. std::vector operators = A3::operator_list (); - // Date format, for both parsing and rendering. - std::string date_format = context.config.get ("dateformat"); - // Nibble them apart. A3 output; Nibbler n (combined); @@ -757,9 +754,9 @@ const A3 A3::tokenize (const A3& input) const // Must be higher than number. // Must be higher than operator. // Note that Nibbler::getDate does not read durations. - else if (n.getDate (date_format, t)) + else if (is_date (n, s)) { - output.push_back (Arg (Date (t).toString (date_format), Arg::type_date, Arg::cat_literal)); + output.push_back (Arg (s, Arg::type_date, Arg::cat_literal)); if (found_sequence) found_something_after_sequence = true; } @@ -1569,6 +1566,23 @@ bool A3::is_dom (Nibbler& n, Arg& arg) return false; } +//////////////////////////////////////////////////////////////////////////////// +bool A3::is_date (Nibbler& n, std::string& result) +{ + std::string date_format = context.config.get ("dateformat"); + std::string::size_type start = n.save (); + time_t t; + + if (n.getDate (date_format, t)) + { + result = n.str ().substr (start, n.cursor () - start); + return true; + } + + n.restore (); + return false; +} + //////////////////////////////////////////////////////////////////////////////// // A duration may only be followed by \0, ), +, -, *, / or ' '. // diff --git a/src/A3.h b/src/A3.h index 10cd1739e..c8ce0fbee 100644 --- a/src/A3.h +++ b/src/A3.h @@ -79,6 +79,7 @@ public: static bool is_attribute (const std::string&, std::string&); static bool is_modifier (const std::string&, std::string&); static bool is_dom (Nibbler&, Arg&); + static bool is_date (Nibbler&, std::string&); static bool is_duration (Nibbler&, std::string&); static bool is_pattern (Nibbler&, std::string&); static bool is_subst (Nibbler&, std::string&);