diff --git a/ci/requirements_dev.txt b/ci/requirements_dev.txt index 92ec384..9589545 100644 --- a/ci/requirements_dev.txt +++ b/ci/requirements_dev.txt @@ -10,3 +10,4 @@ mysql-connector-python==8.0.28 ctd==1.1.1 #python-ctd seawater==3.3.4 #geomag cmweis github version... part of package +pytest \ No newline at end of file diff --git a/src/EcoFOCIpy/epic/EPIC_timeconvert.py b/src/EcoFOCIpy/epic/EPIC_timeconvert.py index 42b151d..3d76636 100644 --- a/src/EcoFOCIpy/epic/EPIC_timeconvert.py +++ b/src/EcoFOCIpy/epic/EPIC_timeconvert.py @@ -87,10 +87,10 @@ def EPIC2Datetime( timeword_1, timeword_2): ref_time_dt = datetime.datetime(1968, 5, 23) ref_time_epic = 2440000 - delta_days = [x - ref_time_epic for x in timeword_1] - delta_seconds = [x/1000 for x in timeword_2] + delta_days = timeword_1 - ref_time_epic + delta_seconds = timeword_2/1000 - epic_dt = [ref_time_dt + datetime.timedelta(a,c) for a,c in zip(delta_days,delta_seconds)] + epic_dt = [ref_time_dt + datetime.timedelta(int(a),int(c)) for a,c in zip(delta_days,delta_seconds)] return(epic_dt) @@ -163,31 +163,5 @@ def Datetime2EPIC(epic_dt): def main(): pass -def test_1d(): - testdate = EPIC2Datetime([2440000,],[43200000+3600*1000,]) - print(f"\n{testdate}\n") - for time_format in ['days','hours','seconds']: - time_since_str = time_format + ' since 1900-1-1' - print(f"{testdate}:value \n{time_since_str}:units\n") - -def test_2d(): - testdate = EPIC2Datetime([2440000,2450000],[43200000,0]) - print(f"\n{testdate}\n") - for time_format in ['days','hours','seconds']: - time_since_str = time_format + ' since 1900-1-1' - print(f"{testdate}:value \n{time_since_str}:units\n") - -def test_1d_EPIC(): - testdate = EPIC2Datetime([2440000,],[43200000+3600*1000,]) - print(f'{testdate}') - testdate1 = Datetime2EPIC(testdate) - print(f'{testdate1}') - -def test_2d_EPIC(): - testdate = EPIC2Datetime([2440000,2450000],[43200000,0]) - print(f'{testdate}') - testdate1 = Datetime2EPIC(testdate) - print(f'{testdate1}') - if __name__ == "__main__": main() diff --git a/tests/test_epic.py b/tests/test_epic.py new file mode 100644 index 0000000..4741d56 --- /dev/null +++ b/tests/test_epic.py @@ -0,0 +1,23 @@ +import datetime + +import pytest +from EcoFOCIpy.epic import EPIC_timeconvert as EPIC + + +class TestClassEPICTime: + def test_1d(self): + testdate = EPIC.EPIC2Datetime([2440000,],[43200000+3600*1000,]) + assert testdate == [datetime.datetime(1968, 5, 23, 13, 0)] + + def test_2d(self): + testdate = EPIC.EPIC2Datetime([2440000,2450000],[43200000,0]) + assert testdate == [datetime.datetime(1968, 5, 23, 12, 0), datetime.datetime(1995, 10, 9, 0, 0)] + + def test_1d_EPIC(self): + testdate = EPIC.Datetime2EPIC(EPIC.EPIC2Datetime([2440000,],[43200000+3600*1000,])) + assert testdate == ([2440000], [46800000]) + + def test_2d_EPIC(self): + testdate = EPIC.Datetime2EPIC(EPIC.EPIC2Datetime([2440000,2450000],[43200000,0])) + assert testdate == ([2440000,2450000],[43200000,0]) +