Skip to content

Commit

Permalink
Merge pull request #1296 from rsteneteg/master
Browse files Browse the repository at this point in the history
allow old epoch timestamps with 11-13 digits as epoch + milliseconds
  • Loading branch information
untergeek committed Oct 30, 2018
2 parents 646d36a + a6b3d02 commit 0a650c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ Contributors:
* Sönke Liebau (soenkeliebau)
* Timothy Schroder (tschroeder-zendesk)
* Jared Carey (jpcarey)
* Juraj Seffer (jurajseffer)
* Juraj Seffer (jurajseffer)
* Roger Steneteg (rsteneteg)
15 changes: 7 additions & 8 deletions curator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,19 +235,18 @@ def fix_epoch(epoch):
even nanoseconds.
:rtype: int
"""
# No decimals allowed
epoch = int(epoch)
try:
# No decimals allowed
epoch = int(epoch)
except Exception as ex:
raise ValueError('Invalid epoch received, unable to convert {} to int'.format(epoch))

# If we're still using this script past January, 2038, we have bigger
# problems than my hacky math here...
if len(str(epoch)) <= 10:
return epoch
elif len(str(epoch)) == 13:
elif len(str(epoch)) > 10 and len(str(epoch)) <= 13:
return int(epoch/1000)
elif len(str(epoch)) > 10 and len(str(epoch)) < 13:
raise ValueError(
'Unusually formatted epoch timestamp. '
'Should be 10, 13, or more digits'
)
else:
orders_of_magnitude = len(str(epoch)) - 10
powers_of_ten = 10**orders_of_magnitude
Expand Down
6 changes: 4 additions & 2 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,18 @@ def test_non_escaped(self):
class TestFixEpoch(TestCase):
def test_fix_epoch(self):
for long_epoch, epoch in [
(1459287636, 1459287636),
(14592876369, 14592876),
(145928763699, 145928763),
(1459287636999, 1459287636),
(1459287636000000, 1459287636),
(145928763600000000, 1459287636),
(145928763600000001, 1459287636),
(1459287636123456789, 1459287636),
(1459287636999, 1459287636),
]:
self.assertEqual(epoch, curator.fix_epoch(long_epoch))
def test_fix_epoch_raise(self):
self.assertRaises(ValueError, curator.fix_epoch, 12345678901)
self.assertRaises(ValueError, curator.fix_epoch, None)

class TestGetPointOfReference(TestCase):
def test_get_point_of_reference(self):
Expand Down

0 comments on commit 0a650c6

Please sign in to comment.