Skip to content

Commit

Permalink
Fix get_time util if input is 0.
Browse files Browse the repository at this point in the history
This also fixes `Get Time` keyword using that util. Fixes #4438.
  • Loading branch information
pekkaklarck committed Sep 21, 2022
1 parent 1bcc03a commit f482185
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/robot/utils/robottime.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def get_time(format='timestamp', time_=None):
- Otherwise (and by default) the time is returned as a timestamp string in
format '2006-02-24 15:08:31'
"""
time_ = int(time_ or time.time())
time_ = int(time.time() if time_ is None else time_)
format = format.lower()
# 1) Return time in seconds since epoc
if 'epoch' in format:
Expand Down
5 changes: 4 additions & 1 deletion utest/utils/test_robottime.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,10 @@ def test_parse_time_with_now_and_utc(self):
parsed = parse_time(input.upper().replace('NOW', 'UtC'))
zone = time.altzone if time.localtime().tm_isdst else time.timezone
expected += zone
assert_true(expected <= parsed <= expected + 1),
assert_true(expected <= parsed <= expected + 1)

def test_get_time_with_zero(self):
assert_equal(get_time('epoch', 0), 0)

def test_parse_modified_time_with_invalid_times(self):
for value, msg in [("-100", "Epoch time must be positive (got -100)."),
Expand Down

0 comments on commit f482185

Please sign in to comment.