Source code for ibllib.tests.test_time

import unittest
import ibllib.time
import datetime
import pandas as pd


[docs] class TestUtils(unittest.TestCase):
[docs] def test_isostr2date(self): # test the full string a = ibllib.time.isostr2date('2018-03-01T12:34:56.99999') self.assertTrue(a == datetime.datetime(2018, 3, 1, 12, 34, 56, 999990)) # test UTC offset # a = ibllib.time.isostr2date('2018-03-01T12:34:56+02:00') # FAILS! # if ms is rounded, test without the F field b = ibllib.time.isostr2date('2018-03-01T12:34:56') self.assertTrue(b == datetime.datetime(2018, 3, 1, 12, 34, 56)) # test a mixed list input c = ['2018-03-01T12:34:56.99999', '2018-03-01T12:34:56'] d = ibllib.time.isostr2date(c) self.assertTrue((d[0] == a) and (d[1] == b)) # test with pandas series e = ibllib.time.isostr2date(pd.Series(c)) self.assertTrue((e[0] == a) and (e[1] == b))
[docs] def test_date2isostr(self): expected = '2018-08-14T00:00:00' day = datetime.date(2018, 8, 14) self.assertEqual(expected, ibllib.time.date2isostr(day)) dt = datetime.datetime(2018, 8, 14) self.assertEqual(expected, ibllib.time.date2isostr(dt))
if __name__ == "__main__": unittest.main(exit=False, verbosity=2)