From 998251f23d4ab5143cfc20e763c3d8e1b6188ec0 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 27 Aug 2021 20:12:35 +0100 Subject: Extract datetime2From40bit --- lib/mysql_types.cpp | 23 +++++++++++------------ lib/mysql_types.h | 1 + 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'lib') diff --git a/lib/mysql_types.cpp b/lib/mysql_types.cpp index 40614ef..ae1ee62 100644 --- a/lib/mysql_types.cpp +++ b/lib/mysql_types.cpp @@ -215,20 +215,19 @@ namespace MyGrate::MySQL { Type::read(RawDataReader & md, RawDataReader & data) { md.discard(1); - union { - uint64_t i; - std::array b; - } r {}; - r.b = data.readValue(); - std::reverse(r.b.begin(), r.b.end()); + return datetime2From40bit(ntoh(data.readValue(5))); + } + DateTime + datetime2From40bit(uint64_t dtint) + { DateTime dt; - dt.year = boost::numeric_cast(bitslice<17>(r.i, 22) / 13); - dt.month = boost::numeric_cast(bitslice<17>(r.i, 22) % 13); - dt.day = bitslice<5>(r.i, 17); - dt.hour = bitslice<5>(r.i, 12); - dt.minute = bitslice<6>(r.i, 6); - dt.second = bitslice<6>(r.i, 0); + dt.year = boost::numeric_cast(bitslice<17>(dtint, 46) / 13); + dt.month = boost::numeric_cast(bitslice<17>(dtint, 46) % 13); + dt.day = bitslice<5>(dtint, 41); + dt.hour = bitslice<5>(dtint, 36); + dt.minute = bitslice<6>(dtint, 30); + dt.second = bitslice<6>(dtint, 24); return dt; } } diff --git a/lib/mysql_types.h b/lib/mysql_types.h index d49cd2f..737cff7 100644 --- a/lib/mysql_types.h +++ b/lib/mysql_types.h @@ -85,6 +85,7 @@ namespace MyGrate { #undef DEFINE_TYPE Time time2From24bit(uint32_t tint); + DateTime datetime2From40bit(uint64_t dtint); struct ReplicationPosition { #ifndef __cpp_aggregate_paren_init -- cgit v1.2.3