diff --git a/config/dpkg/changelog b/config/dpkg/changelog index 2fb4aa9..4818d17 100644 --- a/config/dpkg/changelog +++ b/config/dpkg/changelog @@ -1,5 +1,5 @@ -dfdatetime (20221218-1) unstable; urgency=low +dfdatetime (20230225-1) unstable; urgency=low * Auto-generated - -- Log2Timeline maintainers Sun, 18 Dec 2022 13:12:18 +0100 + -- Log2Timeline maintainers Sat, 25 Feb 2023 08:38:51 +0100 diff --git a/dfdatetime/__init__.py b/dfdatetime/__init__.py index d293435..a3d7e70 100644 --- a/dfdatetime/__init__.py +++ b/dfdatetime/__init__.py @@ -25,4 +25,4 @@ from dfdatetime import webkit_time -__version__ = '20221218' +__version__ = '20230225' diff --git a/dfdatetime/interface.py b/dfdatetime/interface.py index 9d181f3..e2287eb 100644 --- a/dfdatetime/interface.py +++ b/dfdatetime/interface.py @@ -969,21 +969,30 @@ def GetDateWithTimeOfDay(self): """ return self._GetDateWithTimeOfDay() - # TODO: remove this method when there is no more need for it in plaso. + # TODO: remove this method when there is no more need for it in Plaso. def GetPlasoTimestamp(self): """Retrieves a timestamp that is compatible with Plaso. Returns: int: a POSIX timestamp in microseconds or None if no timestamp is available. + + Raises: + ValueError: if the timestamp cannot be determined. """ normalized_timestamp = self._GetNormalizedTimestamp() if normalized_timestamp is None: return None normalized_timestamp *= definitions.MICROSECONDS_PER_SECOND - normalized_timestamp = normalized_timestamp.quantize( - 1, rounding=decimal.ROUND_HALF_UP) + + try: + normalized_timestamp = normalized_timestamp.quantize( + 1, rounding=decimal.ROUND_HALF_UP) + except decimal.InvalidOperation as exception: + raise ValueError( + f'Unable to round normalized timestamp with error: {exception!s}') + return int(normalized_timestamp) def GetTimeOfDay(self): diff --git a/tests/cocoa_time.py b/tests/cocoa_time.py index b7d7caa..9098f63 100644 --- a/tests/cocoa_time.py +++ b/tests/cocoa_time.py @@ -134,7 +134,7 @@ def testGetDateWithTimeOfDay(self): self.assertEqual( date_with_time_of_day_tuple, (None, None, None, None, None, None)) - # TODO: remove this method when there is no more need for it in plaso. + # TODO: remove this method when there is no more need for it in Plaso. def testGetPlasoTimestamp(self): """Tests the GetPlasoTimestamp function.""" cocoa_time_object = cocoa_time.CocoaTime(timestamp=395011845.0) diff --git a/tests/delphi_date_time.py b/tests/delphi_date_time.py index a096bff..5929718 100644 --- a/tests/delphi_date_time.py +++ b/tests/delphi_date_time.py @@ -177,6 +177,26 @@ def testGetDateWithTimeOfDay(self): self.assertEqual( date_with_time_of_day_tuple, (None, None, None, None, None, None)) + # TODO: remove this method when there is no more need for it in Plaso. + def testGetPlasoTimestamp(self): + """Tests the GetPlasoTimestamp function.""" + delphi_date_time_object = delphi_date_time.DelphiDateTime( + timestamp=41443.8263953) + + micro_posix_timestamp = delphi_date_time_object.GetPlasoTimestamp() + self.assertEqual(micro_posix_timestamp, 1371585000553920) + + delphi_date_time_object = delphi_date_time.DelphiDateTime() + + micro_posix_timestamp = delphi_date_time_object.GetPlasoTimestamp() + self.assertIsNone(micro_posix_timestamp) + + delphi_date_time_object = delphi_date_time.DelphiDateTime( + timestamp=8.0e+174) + + with self.assertRaises(ValueError): + delphi_date_time_object.GetPlasoTimestamp() + def testGetTimeOfDay(self): """Tests the GetTimeOfDay function.""" delphi_date_time_object = delphi_date_time.DelphiDateTime(