Skip to content

Commit

Permalink
Fix unit test failing around DST. Fixes #4523.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekkaklarck committed Oct 30, 2022
1 parent e1ccafe commit 628b44b
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions utest/utils/test_robottime.py
Expand Up @@ -340,13 +340,17 @@ def test_parse_time_with_now_and_utc(self):
('now - 1 day 100 seconds', -86500),
('now + 1day 10hours 1minute 10secs', 122470),
('NOW - 1D 10H 1MIN 10S', -122470)]:
expected = get_time('epoch') + adjusted
now = int(time.time())
parsed = parse_time(input)
assert_true(expected <= parsed <= expected + 1),
expected = now + adjusted
if time.localtime(now).tm_isdst is not time.localtime(expected).tm_isdst:
dst_diff = time.timezone - time.altzone
expected += dst_diff if time.localtime(now).tm_isdst else -dst_diff
assert_true(expected - parsed < 0.1)
parsed = parse_time(input.upper().replace('NOW', 'UtC'))
zone = time.altzone if time.localtime().tm_isdst else time.timezone
zone = time.altzone if time.localtime(now).tm_isdst else time.timezone
expected += zone
assert_true(expected <= parsed <= expected + 1)
assert_true(expected - parsed < 0.1)

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

0 comments on commit 628b44b

Please sign in to comment.