aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2018-03-20 11:27:29 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2018-03-20 11:27:29 +0200
commitecffe5ab30a72a9b9e5909926d507213e123b0e1 (patch)
tree7e24757d7f0e1cba59a9a47f2b703eaf35139e37
parent6847ed7c688002fef356ae0832242efe024a5511 (diff)
Change git <snapsn> format in stdver to YYYYMMDDhhmmss
-rw-r--r--build2/types.hxx1
-rw-r--r--build2/version/snapshot-git.cxx15
2 files changed, 13 insertions, 3 deletions
diff --git a/build2/types.hxx b/build2/types.hxx
index aba36a4..86a53f2 100644
--- a/build2/types.hxx
+++ b/build2/types.hxx
@@ -245,6 +245,7 @@ namespace build2
using butl::timestamp_unknown;
using butl::timestamp_unknown_rep;
using butl::timestamp_nonexistent;
+ using butl::to_string;
using butl::operator<<;
// <libbutl/sha256.mxx>
diff --git a/build2/version/snapshot-git.cxx b/build2/version/snapshot-git.cxx
index dff5579..9dd50c5 100644
--- a/build2/version/snapshot-git.cxx
+++ b/build2/version/snapshot-git.cxx
@@ -2,6 +2,8 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
+#include <ctime> // time_t
+
#include <libbutl/sha1.mxx>
#include <build2/version/snapshot.hxx>
@@ -85,7 +87,7 @@ namespace build2
throw invalid_argument ("missing timestamp");
string ts (l, p2 + 1, p1 - p2 - 1);
- r.sn = stoull (ts);
+ time_t t (static_cast<time_t> (stoull (ts)));
if (tz.size () != 5)
throw invalid_argument ("invalid timezone");
@@ -99,10 +101,17 @@ namespace build2
//
switch (tz[0])
{
- case '+': r.sn -= s; break;
- case '-': r.sn += s; break;
+ case '+': t -= s; break;
+ case '-': t += s; break;
default: throw invalid_argument ("invalid timezone sign");
}
+
+ // Represent as YYYYMMDDhhmmss.
+ //
+ r.sn = stoull (to_string (system_clock::from_time_t (t),
+ "%Y%m%d%H%M%S",
+ false /* special */,
+ true /* local (already in UTC) */));
}
catch (const invalid_argument& e)
{