Skip to content

Commit

Permalink
Support dt.timedelta when nested
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed Sep 19, 2023
1 parent 6febe06 commit b8aa4ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/time_machine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ def extract_timestamp_tzname(
dest = dest.replace(tzinfo=dt.timezone.utc)
timestamp = dest.timestamp()
elif isinstance(dest, dt.timedelta):
if coordinates_stack:
raise TypeError(
"timedelta destination is not supported when already time travelling."
)
timestamp = time() + dest.total_seconds()
elif isinstance(dest, dt.date):
timestamp = dt.datetime.combine(
Expand Down
10 changes: 3 additions & 7 deletions tests/test_time_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,14 +476,10 @@ def test_destination_negative_delta():
assert now - 3600 <= time.time() <= now - 3599


@time_machine.travel(0)
def test_destination_delta_raises():
with pytest.raises(TypeError) as excinfo:
time_machine.travel(dt.timedelta(seconds=3600))

assert excinfo.value.args == (
"Timedelta destination is not supported when already time travelling.",
)
with time_machine.travel(EPOCH):
with time_machine.travel(dt.timedelta(seconds=10)):
assert time.time() == EPOCH + 10.0


def test_traveller_object():
Expand Down

0 comments on commit b8aa4ea

Please sign in to comment.