aboutsummaryrefslogtreecommitdiff
path: root/mod/types-parsers.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-03-30 23:07:26 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-04-01 13:13:23 +0300
commit2b2f2dc54856b679e8fd42b053f7361241c0f836 (patch)
treecdba437bf14b65d729ed027869c9ad8041dbe4fd /mod/types-parsers.cxx
parent8dec2ac658d78d58437d77be08c9f2614c259cc6 (diff)
Invent alternative package rebuild timeout
Diffstat (limited to 'mod/types-parsers.cxx')
-rw-r--r--mod/types-parsers.cxx36
1 files changed, 36 insertions, 0 deletions
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 <mod/types-parsers.hxx>
+#include <libbutl/timestamp.mxx> // from_string()
+
#include <mod/module-options.hxx>
using namespace std;
@@ -50,6 +52,40 @@ namespace brep
parse_path (x, s);
}
+ // Parse time of day.
+ //
+ void parser<duration>::
+ 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<repository_location>::