diff --git a/dfdatetime/serializer.py b/dfdatetime/serializer.py index 26f8d5f..94a1e3a 100644 --- a/dfdatetime/serializer.py +++ b/dfdatetime/serializer.py @@ -121,6 +121,7 @@ def ConvertJSONToDateTimeValues(cls, json_dict): "TimeElements", "TimeElementsInMilliseconds", "TimeElementsInMicroseconds", + "TimeElementsInNanoseconds", ): is_delta = json_dict.get("is_delta") if is_delta is not None: diff --git a/tests/serializer.py b/tests/serializer.py index 5025cd4..f14861f 100644 --- a/tests/serializer.py +++ b/tests/serializer.py @@ -222,6 +222,21 @@ def testConvertDateTimeValuesToJSON(self): ) self.assertEqual(json_dict, expected_json_dict) + time_elements_object = time_elements.TimeElementsInNanoseconds( + time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429876543) + ) + + expected_json_dict = { + "__class_name__": "TimeElementsInNanoseconds", + "__type__": "DateTimeValues", + "time_elements_tuple": (2010, 8, 12, 20, 6, 31, 429876543), + } + + json_dict = serializer.Serializer.ConvertDateTimeValuesToJSON( + time_elements_object + ) + self.assertEqual(json_dict, expected_json_dict) + def testConvertJSONToDateTimeValues(self): """Test ConvertJSONToDateTimeValues function.""" json_dict = { @@ -382,6 +397,19 @@ def testConvertJSONToDateTimeValues(self): date_time_object = serializer.Serializer.ConvertJSONToDateTimeValues(json_dict) self.assertEqual(date_time_object, expected_date_time_object) + json_dict = { + "__class_name__": "TimeElementsInNanoseconds", + "__type__": "DateTimeValues", + "time_elements_tuple": (2010, 8, 12, 20, 6, 31, 429876543), + } + + expected_date_time_object = time_elements.TimeElementsInNanoseconds( + time_elements_tuple=(2010, 8, 12, 20, 6, 31, 429876543) + ) + + date_time_object = serializer.Serializer.ConvertJSONToDateTimeValues(json_dict) + self.assertEqual(date_time_object, expected_date_time_object) + # Test if is_delta is removed. json_dict = { "__class_name__": "PosixTime",