in curator/helpers/date_ops.py [0:0]
def fix_epoch(epoch):
"""
Fix value of ``epoch`` to be the count since the epoch in seconds only, which
should be 10 or fewer digits long.
:param epoch: An epoch timestamp, in epoch + milliseconds, or microsecond, or even
nanoseconds.
:type epoch: int
:returns: An epoch timestamp in seconds only, based on ``epoch``
:rtype: int
"""
try:
# No decimals allowed
epoch = int(epoch)
except Exception as err:
raise ValueError(
f'Bad epoch value. Unable to convert {epoch} to int. {err}'
) from err
# If we're still using this script past January, 2038, we have bigger
# problems than my hacky math here...
if len(str(epoch)) <= 10:
# Epoch is fine, no changes
pass
elif len(str(epoch)) > 10 and len(str(epoch)) <= 13:
epoch = int(epoch / 1000)
else:
orders_of_magnitude = len(str(epoch)) - 10
powers_of_ten = 10**orders_of_magnitude
epoch = int(epoch / powers_of_ten)
return epoch