Skip to content
Snippets Groups Projects
Commit 20260bf5 authored by Bruce Flynn's avatar Bruce Flynn
Browse files

fix timecode date conversion

parent 5f94b782
No related branches found
No related tags found
No related merge requests found
.eggs
.cache
build
dist
env
......
......@@ -16,15 +16,16 @@ def unixtime(dt):
return (UNIX_EPOCH - dt).total_seconds()
def cds_to_timestamp(days, millis, micros, epoch):
def cds_to_timestamp(days, millis, microseconds, epoch):
"""
CDS to unix timestamp seconds.
"""
return epoch + (86400 * days) + (millis / 1000.) + (micros / 1000000.)
return epoch + (86400 * days) + (millis / 1000.) + (microseconds / 1000000.)
def cds_stamp(days, millis, micros, epoch=JPSS_EPOCH):
def cds_stamp(days, millis, microseconds, epoch=JPSS_EPOCH):
"""
CCSDS Day Segmented timecode to UTC datetime.
"""
return JPSS_EPOCH + timedelta(days=days, microseconds=1000 * millis + micros)
return epoch + timedelta(days=days,
seconds=millis / 1000.0 + (microseconds / 1000000.))
......@@ -15,6 +15,12 @@ setup(
install_requires=[
'h5py',
],
extras_require={
'testing': [
'pytest',
'pytest-cov'
]
},
entry_points="""
[console_scripts]
edosl0split = edosl0util.cli.split:main
......
from datetime import datetime, timedelta
from edosl0util import timecode
def test_unixtime():
assert timecode.unixtime(timecode.UNIX_EPOCH) == 0
def test_cds_to_timestamp():
epoch = 0
secs = timecode.cds_to_timestamp(0, 0, 0, epoch)
assert secs == 0
secs = timecode.cds_to_timestamp(0, 0, 999, epoch)
assert secs == 0.000999
secs = timecode.cds_to_timestamp(1, 1, 999, epoch)
assert secs == 86400.001999
def test_cds_stamp():
epoch = timecode.UNIX_EPOCH
assert timecode.cds_stamp(0, 0, 0, epoch) == timecode.UNIX_EPOCH
assert timecode.cds_stamp(0, 0, 999, epoch) == datetime(1970, 1, 1, 0, 0, 0, 999)
assert timecode.cds_stamp(1, 1, 999, epoch) == datetime(1970, 1, 2, 0, 0, 0, 1999)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment