diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-08-27 20:12:35 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2021-08-27 20:12:35 +0100 |
commit | 998251f23d4ab5143cfc20e763c3d8e1b6188ec0 (patch) | |
tree | 7c2e793a6b9e9fb1c7a6ee2c7232c73e60533d09 /lib | |
parent | Extract and test time2From24bit (diff) | |
download | mygrate-998251f23d4ab5143cfc20e763c3d8e1b6188ec0.tar.bz2 mygrate-998251f23d4ab5143cfc20e763c3d8e1b6188ec0.tar.xz mygrate-998251f23d4ab5143cfc20e763c3d8e1b6188ec0.zip |
Extract datetime2From40bit
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mysql_types.cpp | 23 | ||||
-rw-r--r-- | lib/mysql_types.h | 1 |
2 files changed, 12 insertions, 12 deletions
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<MYSQL_TYPE_DATETIME2>::read(RawDataReader & md, RawDataReader & data) { md.discard(1); - union { - uint64_t i; - std::array<uint8_t, 5> b; - } r {}; - r.b = data.readValue<decltype(r.b)>(); - std::reverse(r.b.begin(), r.b.end()); + return datetime2From40bit(ntoh(data.readValue<uint64_t>(5))); + } + DateTime + datetime2From40bit(uint64_t dtint) + { DateTime dt; - dt.year = boost::numeric_cast<decltype(dt.year)>(bitslice<17>(r.i, 22) / 13); - dt.month = boost::numeric_cast<decltype(dt.month)>(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<decltype(dt.year)>(bitslice<17>(dtint, 46) / 13); + dt.month = boost::numeric_cast<decltype(dt.month)>(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 |