37 int64_t count()
const {
return _count; }
38 int64_t to_seconds()
const {
return _count/1000000; }
66 check(strptime(date_str.c_str(),
"%Y-%m-%dT%H:%M:%S", &tm),
"date parsing failed");
68 auto tp = std::chrono::system_clock::from_time_t( ::mktime( &tm ) );
69 auto duration = std::chrono::duration_cast<std::chrono::microseconds>( tp.time_since_epoch() );
77 strftime(buf,
sizeof(buf),
"%Y-%m-%dT%H:%M:%S", gmtime ( &rawtime ));
79 return std::string{buf};
89 time_point& operator += (
const microseconds& m) { elapsed+=m;
return *
this; }
90 time_point& operator -= (
const microseconds& m) { elapsed-=m;
return *
this; }
94 microseconds operator - (
const time_point& m)
const {
return microseconds(elapsed.count() - m.elapsed.count()); }
116 :utc_seconds(
uint32_t(t.time_since_epoch().count() / 1000000ll) ){}
146 time_point_sec& operator += ( microseconds m ) { utc_seconds+=m.to_seconds();
return *
this; }
149 time_point_sec& operator -= ( microseconds m ) { utc_seconds-=m.to_seconds();
return *
this; }
155 friend time_point operator - (
const time_point_sec& t,
const microseconds& m ) {
return time_point(t) - m; }
157 friend microseconds operator - (
const time_point& t,
const time_point_sec& m ) {
return time_point(t) - time_point(m); }
187 eosio::check( std::numeric_limits<uint32_t>::max() - slot >= 1,
"block timestamp overflow" );
198 int64_t msec = slot * (int64_t)block_interval_ms;
199 msec += block_timestamp_epoch;
224 static constexpr int32_t block_interval_ms = 500;
225 static constexpr int64_t block_timestamp_epoch = 946684800000ll;
232 void set_time_point(
const time_point& t) {
233 int64_t micro_since_epoch = t.time_since_epoch().count();
234 int64_t msec_since_epoch = micro_since_epoch / 1000;
235 slot =
uint32_t(( msec_since_epoch - block_timestamp_epoch ) / int64_t(block_interval_ms));
238 void set_time_point(
const time_point_sec& t) {
239 int64_t sec_since_epoch = t.sec_since_epoch();
240 slot =
uint32_t((sec_since_epoch * 1000 - block_timestamp_epoch) / block_interval_ms);