diff --git a/AUTHORS.rst b/AUTHORS.rst index 62e4962..28cd64e 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -21,3 +21,4 @@ Patches and Suggestions - `Hannes Ljungberg `_ - `staticdev `_ - `Marcin Sulikowski `_ +- `Ashish Patil `_ diff --git a/freezegun/api.py b/freezegun/api.py index 2917fa1..7de7746 100644 --- a/freezegun/api.py +++ b/freezegun/api.py @@ -493,6 +493,11 @@ def __init__(self, time_to_freeze, start): def __call__(self): return self.time_to_freeze + (real_datetime.now() - self.start) + def move_to(self, target_datetime): + """Moves frozen date to the given ``target_datetime``""" + self.start = real_datetime.now() + self.time_to_freeze = _parse_time_to_freeze(target_datetime) + class FrozenDateTimeFactory: diff --git a/tests/test_ticking.py b/tests/test_ticking.py index e29ce07..434a6e7 100644 --- a/tests/test_ticking.py +++ b/tests/test_ticking.py @@ -63,6 +63,14 @@ def test_ticking_time(): assert time.time() > 1326585599.0 +@utils.cpython_only +def test_ticking_move_to(): + with freeze_time("Jan 14th, 2012, 23:59:59", tick=True) as ft: + ft.move_to("Jan 15th, 2012, 00:59:59.999999") + time.sleep(0.001) # Deal with potential clock resolution problems + assert datetime.datetime.now().replace(second=0, microsecond=0) == datetime.datetime(2012, 1, 15, 1, 0, 0) + + @utils.cpython_only_mark @pytest.mark.parametrize("func_name", ("monotonic", "monotonic_ns", "perf_counter", "perf_counter_ns"),