From 25933a55455b2a0927769b29d06e3b2779e3efb6 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 16 Dec 2015 18:18:22 +0200 Subject: Bugfix: accuracy loss in ODB mapping for butl:timestamp --- brep/package | 24 ++++++++++++++++++++---- 1 file 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 +#include #include -#include // ostream +#include // ostream +#include // static_assert #include #include // 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::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 ( \ + (?).time_since_epoch ()).count ()) \ + from(brep::timestamp ( \ + std::chrono::duration_cast ( \ + std::chrono::nanoseconds (?)))) // version // -- cgit v1.1