Skip to content

Commit

Permalink
Changes to check for maximum supported DelphiDateTime #168 (#252)
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz authored Feb 25, 2023
1 parent 6154b76 commit 3b02605
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions dfdatetime/delphi_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,13 @@ def CopyToDateTimeString(self):
number_of_days, hours, minutes, seconds = self._GetTimeValues(
int(number_of_seconds))

# The maximum date supported by TDateTime values is limited to:
# 9999-12-31 23:59:59.999 (approximate 2958465 days since epoch).
# The minimum date is unknown hence assuming it is limited to:
# 0001-01-01 00:00:00.000 (approximate -693593 days since epoch).
if number_of_days < -693593 or number_of_days > 2958465:
return None

year, month, day_of_month = self._GetDateValuesWithEpoch(
number_of_days, self._EPOCH)

Expand Down
5 changes: 5 additions & 0 deletions tests/delphi_date_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ def testCopyToDateTimeStringISO8601(self):
date_time_string = delphi_date_time_object.CopyToDateTimeStringISO8601()
self.assertEqual(date_time_string, '2013-06-18T19:50:00.553919+00:00')

delphi_date_time_object = delphi_date_time.DelphiDateTime(
timestamp=8.0e+174)
date_time_string = delphi_date_time_object.CopyToDateTimeStringISO8601()
self.assertIsNone(date_time_string)

def testGetDate(self):
"""Tests the GetDate function."""
delphi_date_time_object = delphi_date_time.DelphiDateTime(
Expand Down

0 comments on commit 3b02605

Please sign in to comment.