How to display the unix timestamp in a transaction filter?

+1 vote
I can't find any way to convert the last block time unixtimestamp into a ISO formated date, the compiler ignores the Date() function
asked Jul 6, 2021 by anonymous

1 Answer

0 votes

Yes, this will be a bit of a challenge. We disabled Date() in smart filters because this provides a route to non-determinism, via checking the current date.

So as far as I can tell, you'd need to use a lower-level algorithm to make the conversion, and this can get really quite complex because of the weird logic of leap years over 100-year and 400-year cycles. See for example: http://howardhinnant.github.io/date_algorithms.html

As a reasonable compromise, I would suggest taking a shortcut by considering only those years for which your blockchain will be running. If for example it's just the 21st century, the math gets simpler. But you'll still need to code up the logic for there being a leap year every 4 years, then determining the month based on a table of (month) -> (day of year when month starts). After that it gets simpler, since it's just a matter of division and modulos.

answered Jul 7, 2021 by MultiChain
...