1string(TIMESTAMP timestamp "[%Y-%m-%d %H:%M:%S] %s" UTC)
2
3string(TIMESTAMP unix_time "%s")
4
5string(TIMESTAMP year "%Y" UTC)
6string(TIMESTAMP days "%j" UTC)
7
8# Doing proper date calculations here to verify unix timestamps
9# could be error prone.
10# At the very least use some safe lower and upper bounds to
11# see if we are somewhere in the right region.
12
13math(EXPR years_since_epoch "${year} - 1970")
14math(EXPR lower_bound "((${years_since_epoch} * 365) + ${days} - 1) * 86400")
15math(EXPR upper_bound "((${years_since_epoch} * 366) + ${days}) * 86400")
16
17
18if(unix_time GREATER_EQUAL lower_bound AND unix_time LESS upper_bound)
19  message("~${unix_time}~")
20else()
21  message(FATAL_ERROR "${timestamp} unix time not in expected range [${lower_bound}, ${upper_bound})")
22endif()
23