Skip to content

Commit

Permalink
Fix time problems on Windows 10
Browse files Browse the repository at this point in the history
Due to Windows 10[1], Robot Interfaces did produce timestamps that were
before epoch and thus failed when Robot tried to convert them into
results.

Now, if we try to put a timestamp that is before epoch, it is just reset
to epoch.

Also, RF3 interface did not have parity with the RF4 interface -- now it
does

[1] https://stackoverflow.com/a/58203399
  • Loading branch information
Tattoo committed Oct 18, 2023
1 parent 49a4ba6 commit f1c9b29
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/oxygen/oxygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def output_file(self, path):
result.visit(OxygenVisitor(self.run_time_data))
result.save()


class OxygenLibrary(OxygenCore):
'''Oxygen is a tool to consolidate different test tools' reports together
as a single Robot Framework log and report. ``oxygen.OxygenLibrary``
Expand Down
5 changes: 5 additions & 0 deletions src/oxygen/robot3_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ def ms_to_timestamp(self, milliseconds):
time_object = datetime.fromtimestamp(int(milliseconds / 1000)) - tz_delta
milliseconds_delta = timedelta(milliseconds=(milliseconds % 1000))
time_object = (time_object + milliseconds_delta)
if time_object.year < 1970:
time_object = datetime.fromtimestamp(0)
# fromtimestamp() loses milliseconds, add them back
milliseconds_delta = timedelta(milliseconds=(milliseconds % 1000))
time_object = (time_object + milliseconds_delta)

time_format = self.get_time_format()

Expand Down
3 changes: 3 additions & 0 deletions src/oxygen/robot4_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ def ms_to_timestamp(self, milliseconds):
tz_delta = self.get_timezone_delta()

time_object = datetime.fromtimestamp(int(milliseconds / 1000)) - tz_delta
if time_object.year < 1970:
time_object = datetime.fromtimestamp(0)
# fromtimestamp() loses milliseconds, add them back
milliseconds_delta = timedelta(milliseconds=(milliseconds % 1000))
time_object = (time_object + milliseconds_delta)

Expand Down
11 changes: 11 additions & 0 deletions tests/utest/robot_interface/test_time_conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@ def test_should_be_associative(self):
timestamp = self.interface.result.ms_to_timestamp(milliseconds)
assert timestamp == '20180807 07:01:24.300000'

def _validate_timestamp(self, result):
timestamp = result.ms_to_timestamp(-10)
self.assertEqual(timestamp, '19700101 02:00:00.990000')

def test_ms_before_epoch_are_reset_to_epoch(self):
from oxygen.robot4_interface import RobotResultInterface as RF4ResultIface
self._validate_timestamp(RF4ResultIface())

from oxygen.robot3_interface import RobotResultInterface as RF3ResultIface
self._validate_timestamp(RF3ResultIface())


class TestTimestampToMs(TestCase):
def setUp(self):
Expand Down

0 comments on commit f1c9b29

Please sign in to comment.