Repository navigation
Changes to use math.floor instead of type cast to int - #322
Merged
joachimmetz merged 2 commits intoOct 26, 2026
Merged
Conversation
_GetTimeValues truncated the number of seconds towards zero, so for a negative normalized timestamp with a fraction of second, such as PosixTimeInMilliseconds(-500), GetDateWithTimeOfDay returned 1970-01-01 00:00:00 instead of 1969-12-31 23:59:59. The same applied to CocoaTime.CopyToDateTimeString, which combined the truncated seconds with the floored fraction of second (timestamp % 1), so -0.25 was formatted as 2001-01-01 00:00:00.750000 instead of 2000-12-31 23:59:59.750000. The number of seconds is now rounded down.
DelphiDateTime and OLEAutomationDate also truncated the number of seconds towards zero before determining the date and time values, while the fraction of second is floored with % 1, so DelphiDateTime(-0.000001) was formatted as 1899-12-30 00:00:00.913600 instead of 1899-12-29 23:59:59.913600. The number of seconds is now rounded down.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #322 +/- ##
=======================================
Coverage 98.89% 98.90%
=======================================
Files 24 24
Lines 2451 2455 +4
=======================================
+ Hits 2424 2428 +4
Misses 27 27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
_GetTimeValuesusesint(), which truncates towards zero. For a negative timestamp with a fraction of a second,GetDate()/GetTimeOfDay()/GetDateWithTimeOfDay()are therefore one second late. For example:PosixTimeInMilliseconds(timestamp=-500).GetDateWithTimeOfDay()returns(1970, 1, 1, 0, 0, 0)instead of(1969, 12, 31, 23, 59, 59).Filetime(timestamp=1)(1601-01-01 00:00:00.0000001) is reported as 00:00:01.CocoaTime,DelphiDateTimeandOLEAutomationDatealso callint()on the number of seconds inCopyToDateTimeString, but take the fraction of second with% 1, which floors:CocoaTime(timestamp=-0.25)gives2001-01-01 00:00:00.750000instead of2000-12-31 23:59:59.750000.DelphiDateTime(timestamp=-0.000001)andOLEAutomationDate(timestamp=-0.000001)give1899-12-30 00:00:00.913600instead of1899-12-29 23:59:59.913600.The number of seconds is now rounded down with
math.floorin all four places.Tests
tests/interface.py,tests/posix_time.py,tests/cocoa_time.py,tests/delphi_date_time.pyandtests/ole_automation_date.py. On main, 5 tests fail (cocoa_time, delphi_date_time, interface, ole_automation_date, posix_time); with this change they pass.python run_tests.py: 328 tests OK.Follow-up to #320: the expected Delphi/OLE dates depend on it.