From 2b2f2dc54856b679e8fd42b053f7361241c0f836 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 30 Mar 2020 23:07:26 +0300 Subject: Invent alternative package rebuild timeout --- mod/types-parsers.cxx | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'mod/types-parsers.cxx') diff --git a/mod/types-parsers.cxx b/mod/types-parsers.cxx index ceaab29..dc21e97 100644 --- a/mod/types-parsers.cxx +++ b/mod/types-parsers.cxx @@ -3,6 +3,8 @@ #include +#include // from_string() + #include using namespace std; @@ -50,6 +52,40 @@ namespace brep parse_path (x, s); } + // Parse time of day. + // + void parser:: + parse (duration& x, bool& xs, scanner& s) + { + xs = true; + + const char* o (s.next ()); + + if (!s.more ()) + throw missing_value (o); + + const char* v (s.next ()); + + // To avoid the manual time of day parsing and validation, let's parse + // it as the first Epoch day time and convert the result (timestamp) to + // the time elapsed since Epoch (duration). + // + try + { + string t ("1970-01-01 "); + t += v; + + x = butl::from_string (t.c_str (), + "%Y-%m-%d %H:%M", + false /* local */).time_since_epoch (); + return; + } + catch (const invalid_argument&) {} + catch (const system_error&) {} + + throw invalid_value (o, v); + } + // Parse repository_location. // void parser:: -- cgit v1.1