From 8a3efe2d3708a91182873c649717c8b46f316e95 Mon Sep 17 00:00:00 2001 From: Vaidik Kapoor Date: Sat, 8 Apr 2023 15:10:52 +0530 Subject: [PATCH] stop converting time to utc for FileLock. fixes #71 --- sherlock/lock.py | 6 +++--- tests/integration/test_lock.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sherlock/lock.py b/sherlock/lock.py index c8f8556..f145dde 100644 --- a/sherlock/lock.py +++ b/sherlock/lock.py @@ -1157,17 +1157,17 @@ def _key_name(self): return key def _now(self) -> datetime.datetime: - return datetime.datetime.now(tz=datetime.timezone.utc) + return datetime.datetime.now() def _expiry_time(self) -> str: - expiry_time = datetime.datetime.max.astimezone(datetime.timezone.utc) + expiry_time = datetime.datetime.max if self.expire is not None: expiry_time = self._now() + datetime.timedelta(seconds=self.expire) return expiry_time.isoformat() def _has_expired(self, data: dict, now: datetime.datetime) -> bool: expiry_time = datetime.datetime.fromisoformat(data["expiry_time"]) - return now > expiry_time.astimezone(tz=datetime.timezone.utc) + return now > expiry_time def _acquire(self) -> bool: owner = str(uuid.uuid4()) diff --git a/tests/integration/test_lock.py b/tests/integration/test_lock.py index 0a7b633..5d75ee9 100644 --- a/tests/integration/test_lock.py +++ b/tests/integration/test_lock.py @@ -710,7 +710,7 @@ def test_acquire_check_expire_is_not_set(self): file = self._load_file(self.lock_name) self.assertEqual( file["expiry_time"], - datetime.datetime.max.astimezone(datetime.timezone.utc).isoformat(), + datetime.datetime.max.isoformat(), ) self.assertTrue(lock.locked())