mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
Datetime增加hex()返回兼容oracle的Datetime格式存储
This commit is contained in:
parent
6f91ab960c
commit
437b33327d
@ -115,7 +115,7 @@ std::string Datetime::repr() const {
|
|||||||
minute(), second(), millisecond(), microsecond());
|
minute(), second(), millisecond(), microsecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long long Datetime::number() const noexcept {
|
uint64_t Datetime::number() const noexcept {
|
||||||
try {
|
try {
|
||||||
HKU_IF_RETURN(m_data.date() == bd::date(bd::pos_infin), Null<unsigned long long>());
|
HKU_IF_RETURN(m_data.date() == bd::date(bd::pos_infin), Null<unsigned long long>());
|
||||||
return (unsigned long long)year() * 100000000LL + (unsigned long long)month() * 1000000LL +
|
return (unsigned long long)year() * 100000000LL + (unsigned long long)month() * 1000000LL +
|
||||||
@ -129,6 +129,20 @@ unsigned long long Datetime::number() const noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t Datetime::hex() const noexcept {
|
||||||
|
uint64_t ret = uint64_t(second());
|
||||||
|
ret |= (uint64_t(minute()) << 8);
|
||||||
|
ret |= (uint64_t(hour()) << 16);
|
||||||
|
ret |= (uint64_t(day()) << 24);
|
||||||
|
ret |= (uint64_t(month()) << 32);
|
||||||
|
uint64_t y = uint64_t(year());
|
||||||
|
uint64_t high_y = y / 100;
|
||||||
|
uint64_t low_y = y - high_y * 100;
|
||||||
|
ret |= (low_y << 40);
|
||||||
|
ret |= (high_y << 48);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
long Datetime::year() const {
|
long Datetime::year() const {
|
||||||
HKU_CHECK_THROW(!isNull(), std::logic_error, "This is Null Datetime!");
|
HKU_CHECK_THROW(!isNull(), std::logic_error, "This is Null Datetime!");
|
||||||
return m_data.date().year();
|
return m_data.date().year();
|
||||||
|
@ -121,10 +121,17 @@ public:
|
|||||||
Datetime operator-(TimeDelta d) const;
|
Datetime operator-(TimeDelta d) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 返回如YYYYMMDDhhmm格式的数字,方便比较操作,
|
* 返回如YYYYMMDDhhmm格式的数字,方便比较操作
|
||||||
* Null<Datetime>()对应的 number 为 Null<unsigned long long>
|
* Null<Datetime>()对应的 number 为 Null<unsigned long long>
|
||||||
|
* @note 精度到分钟
|
||||||
*/
|
*/
|
||||||
unsigned long long number() const noexcept;
|
uint64_t number() const noexcept;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 转化为 oracle datetime 方式的数字,后 7 个字节分别表示世纪、世纪中的年、月、日、时、分、秒
|
||||||
|
* @note 精度到秒
|
||||||
|
*/
|
||||||
|
uint64_t hex() const noexcept;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 转化为字符串,供打印阅读,格式:
|
* 转化为字符串,供打印阅读,格式:
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <hikyuu/datetime/Datetime.h>
|
#include <hikyuu/datetime/Datetime.h>
|
||||||
#include <hikyuu/utilities/Null.h>
|
#include <hikyuu/utilities/Null.h>
|
||||||
|
#include <hikyuu/Log.h>
|
||||||
|
|
||||||
using namespace hku;
|
using namespace hku;
|
||||||
|
|
||||||
@ -121,6 +122,10 @@ TEST_CASE("test_Datetime") {
|
|||||||
Datetime m(y);
|
Datetime m(y);
|
||||||
CHECK(m == d);
|
CHECK(m == d);
|
||||||
|
|
||||||
|
/** @arg 兼容oracle datetime表示法 */
|
||||||
|
d = Datetime(2021, 4, 25, 23, 16, 27);
|
||||||
|
CHECK_EQ(d.hex(), 0x1415041917101bULL);
|
||||||
|
|
||||||
/** @arg Null<Datetime>()转化为number */
|
/** @arg Null<Datetime>()转化为number */
|
||||||
x = Null<unsigned long long>();
|
x = Null<unsigned long long>();
|
||||||
d = Null<Datetime>();
|
d = Null<Datetime>();
|
||||||
|
Loading…
Reference in New Issue
Block a user