missed a couple changes in last commit
This commit is contained in:
1 parent
e7e280bad8
commit
1c29ac0ec5
2 files changed
+20
-17
No files matched your search
+16
-17
@@ -12,32 +12,32 @@ namespace datetime {
|
||||
|
||||
const boost::gregorian::date anchor (1970, boost::gregorian::Jan, 1);
|
||||
const uint64_t anchor_ticks = 621355968000000000;
|
||||
const uint64_t micros_per_day = 86400000000000;
|
||||
const uint64_t micros_per_day = 86400000000;
|
||||
const uint64_t ticks_per_micro = 10;
|
||||
const uint64_t ticks_per_day = micros_per_day * ticks_per_micro;
|
||||
const uint64_t ticks_mask = 0x3FFFFFFFFFFFFFFF;
|
||||
// DateTimeKinds
|
||||
const uint64_t KindUnspecified = 0x0000000000000000;
|
||||
const uint64_t KindUtc = 0x4000000000000000;
|
||||
const uint64_t KindLocal = 0x8000000000000000;
|
||||
|
||||
unsigned long long ptime_to_ll(PTime const &t, uint64_t const kind) {
|
||||
unsigned long long ptime_to_ll(PTime const &t, uint64_t const &kind) {
|
||||
uint64_t days = (t.date() - anchor).days();
|
||||
uint64_t usecs = t.time_of_day().total_microseconds();
|
||||
uint64_t ticks = anchor_ticks + (days * micros_per_day + usecs) * 10;
|
||||
uint64_t ticks = anchor_ticks + usecs * ticks_per_micro + days * ticks_per_day;
|
||||
return (ticks & ticks_mask) | kind;
|
||||
}
|
||||
|
||||
unsigned long long ptime_to_ll(PTime const &t) {
|
||||
return ptime_to_ll(t, KindUnspecified);
|
||||
return ptime_to_ll(t, KindUtc);
|
||||
}
|
||||
|
||||
LLDateTime ll_now ()
|
||||
{
|
||||
return ptime_to_ll (boost::posix_time::microsec_clock::universal_time ());
|
||||
LLDateTime ll_now() {
|
||||
return ptime_to_ll(boost::posix_time::microsec_clock::universal_time(), KindUtc);
|
||||
}
|
||||
|
||||
LLDateTime ll_local_now ()
|
||||
{
|
||||
return ptime_to_ll (boost::posix_time::microsec_clock::local_time ());
|
||||
LLDateTime ll_local_now() {
|
||||
return ptime_to_ll(boost::posix_time::microsec_clock::local_time (), KindLocal);
|
||||
}
|
||||
|
||||
long unix_now() {
|
||||
@@ -124,12 +124,11 @@ PTime make_ptime (int year, int month, int day, int hour, int minute, int second
|
||||
}
|
||||
|
||||
PTime ll_to_ptime (LLDateTime ll) {
|
||||
// drop DateTimeKind (bits 63-64)
|
||||
ll &= ticks_mask;
|
||||
uint64_t usecs = ll % micros_per_day;
|
||||
uint64_t days_after_anchor = (ll - anchor_ticks) / (micros_per_day * 10);
|
||||
return PTime(anchor + boost::gregorian::date_duration(days_after_anchor),
|
||||
boost::posix_time::time_duration(boost::posix_time::microseconds(usecs * 10)));
|
||||
uint64_t ticks_part = ll % (micros_per_day * ticks_per_micro);
|
||||
uint64_t days_part = (ll - anchor_ticks) / ticks_per_day;
|
||||
return PTime(anchor + boost::gregorian::date_duration(days_part),
|
||||
boost::posix_time::time_duration(boost::posix_time::microseconds(ticks_part / ticks_per_micro)));
|
||||
}
|
||||
|
||||
extern "C" BTS_EXPORT int ll_to_cstr (LLDateTime ll, char*buffer, int buffer_sz)
|
||||
@@ -269,13 +268,13 @@ BTS_EXPORT bool is_at_least_days_old (PTime const &time, uint64_t days)
|
||||
BTS_EXPORT LLDateTime ll_from_unix_epoch(long seconds)
|
||||
{
|
||||
PTime result(anchor, boost::posix_time::seconds(seconds));
|
||||
return ptime_to_ll(result);
|
||||
return ptime_to_ll(result, KindUnspecified);
|
||||
}
|
||||
|
||||
BTS_EXPORT LLDateTime ll_from_unix_epoch_ms(long long milliseconds)
|
||||
{
|
||||
PTime result(anchor, boost::posix_time::millisec(milliseconds));
|
||||
return ptime_to_ll(result);
|
||||
return ptime_to_ll(result, KindUnspecified);
|
||||
}
|
||||
|
||||
BTS_EXPORT void ll_to_parts(LLDateTime ll_time, int& year, int& month, int& day, int& hour, int& minute, int& second, int& millisecond)
|
||||
|
||||
Reference in new issue
Block a user