sherlock icon indicating copy to clipboard operation
sherlock copied to clipboard

`FileLock._expiry_time` crash on a different timezone than UTC

Open bcebere opened this issue 1 year ago • 2 comments

Hello,

Thank you for the awesome library.

I am encountering an issue with the FileLock when trying to use it in a timezone different than UTC.

The _expiry_time call throws the exception: ValueError: year 10000 is out of range

when computing datetime.datetime.max.astimezone(datetime.timezone.utc)

As far as I understand, internally, datetime does this:

timestamp() method actually converts your datetime in local timezone. If your timezone is UTC+x (not UTC-x); i.e. your timezone is ahead of UTC time; Then it will add more time in your datetime object (datetime.datetime.max), which will cross the time beyond the year 9999. 

But this is a weird behavior in datetime. Anyway, is it possible to have a way to use sherlock on timezones different than UTC(UTC + x)?

I can work on this, if it looks like a valid problem. One possible fix is to use

expiry_time = datetime.datetime.max.replace(tzinfo=datetime.timezone.utc).astimezone(datetime.timezone.utc)

Python 3.10.9 OS: LinuxMint 21.1

bcebere avatar Apr 04 '23 09:04 bcebere

Hi @bcebere

Glad to hear that you find sherlock useful.

I can confirm this issue as I am able to reproduce this for a UTC+ timezone. Be back shortly with a fix.

vaidik avatar Apr 09 '23 08:04 vaidik

Is there a plan for when this might be merged? This is blocking my use of the library entirely.

james-tisato avatar Aug 08 '23 22:08 james-tisato