aboutsummaryrefslogtreecommitdiff
path: root/brep/package
diff options
context:
space:
mode:
Diffstat (limited to 'brep/package')
-rw-r--r--brep/package24
1 files changed, 20 insertions, 4 deletions
diff --git a/brep/package b/brep/package
index 056e2a8..8a9dcb2 100644
--- a/brep/package
+++ b/brep/package
@@ -6,8 +6,10 @@
#define BREP_PACKAGE
#include <map>
+#include <ratio>
#include <chrono>
-#include <iosfwd> // ostream
+#include <iosfwd> // ostream
+#include <type_traits> // static_assert
#include <odb/core.hxx>
#include <odb/forward.hxx> // database
@@ -90,9 +92,23 @@ namespace brep
#pragma db map type(dir_path) as(string) \
to((?).string ()) from(brep::dir_path (?))
- #pragma db map type(timestamp) as(uint64_t) \
- to(std::chrono::system_clock::to_time_t (?)) \
- from(std::chrono::system_clock::from_time_t (?))
+ // Ensure that timestamp can be represented in nonoseconds without loss of
+ // accuracy, so the following ODB mapping is adequate.
+ //
+ static_assert(
+ std::ratio_greater_equal<timestamp::period,
+ std::chrono::nanoseconds::period>::value,
+ "The following timestamp ODB mapping is invalid");
+
+ // As it pointed out in butl/timestamp we will overflow in year 2262 but
+ // by that time some larger basic type will be available for mapping.
+ //
+ #pragma db map type(timestamp) as(uint64_t) \
+ to(std::chrono::duration_cast<std::chrono::nanoseconds> ( \
+ (?).time_since_epoch ()).count ()) \
+ from(brep::timestamp ( \
+ std::chrono::duration_cast<brep::timestamp::duration> ( \
+ std::chrono::nanoseconds (?))))
// version
//