core: add ts_to_time() utility function