Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileLock._expiry_time crash on a different timezone than UTC #71

Open
bcebere opened this issue Apr 4, 2023 · 2 comments
Open

FileLock._expiry_time crash on a different timezone than UTC #71

bcebere opened this issue Apr 4, 2023 · 2 comments

Comments

@bcebere
Copy link

bcebere commented Apr 4, 2023

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 bcebere changed the title _expiry_time crash on a different timezone than UTC FileLock._expiry_time crash on a different timezone than UTC Apr 4, 2023
vaidik added a commit to vaidik/sherlock that referenced this issue Apr 8, 2023
@vaidik
Copy link
Collaborator

vaidik commented Apr 9, 2023

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.

@james-tisato
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants