Skip to content

Commit

Permalink
stop converting time to utc for FileLock. fixes py-sherlock#71
Browse files Browse the repository at this point in the history
  • Loading branch information
vaidik committed Apr 8, 2023
1 parent 245ece9 commit 8a3efe2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions sherlock/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 8a3efe2

Please sign in to comment.