3

Seems that they are both datatype for storing number of seconds that have elapsed since 1970. So what's the difference between them, when should I use which?

Edit: An example of the "time" datatype I'm referring to can be found here: https://github.com/EOSIO/eos/blob/master/contracts/eosio.system/delegate_bandwidth.cpp#L65

  • time_point_sec is a type in the fc namespace, but what is the "time" datatype to which you refer? Do you mean "time_t" in <ctime>? – James Mart Aug 12 '18 at 17:37
  • @James Mart For example in this contract (github.com/EOSIO/eos/blob/master/contracts/eosio.system/…), it uses a "time" datatype, not sure what's the difference between "time" and "time_point_sec". – mochunhei Aug 13 '18 at 7:26
2
  • time is just a typedef for uint32_t, so it has no time-related functionality or restrictions¹ as long as you don't try to represent milliseconds (which you will need if you try to represent block time, as blocks are created every 500ms,) and it's very light to use inside smart contracts, but it doesn't play nice with other time types in eosio.

  • time_point_sec is one of the eosio native time types--it's a class that implements several methods related to Unix Epoch time, and it's compatible interacting with other time types (e.g. microseconds and time_point.) It is very similar to time_point but it has no support for milliseconds, so it can't be used for EOS's sub-second blocktimes. In the past, it was suggested that it should be removed, but it's still around for now. Dan recommended that the ABI should use time_point, time_point_sec, and block_timestamp instead of time.


¹ Well, it has the restriction that it cannot represent timepoints beyond year 2106 by its nature of only using 32 bits

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.