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

Fix astimezone() and naive datetime #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

normcyr
Copy link

@normcyr normcyr commented Oct 27, 2019

Issue

The current module only works for Python >= 3.6. You cannot call astimezone() on naive datetimes prior to Python 3.6.

`ValueError: astimezone() cannot be applied to a naive datetime`

Solution

Install pytz and tzlocal

pip install pytz tzlocal`

Get local timezone

import pytz
from tzlocal import get_localzone
tz = get_localzone()

Return datetime.now() with proper timezone

return tz.localize(datetime.now()).isoformat('T')

The current module only works for Python >= 3.6. You cannot call astimezone() on naive datetimes prior to Python 3.6. This fixes the issue for Python <= 3.5
@normcyr
Copy link
Author

normcyr commented Oct 27, 2019

The other workaround is obviously to require Python >= 3.6 for the module to work. I don't think this is practical.

On Debian at least, this would need user to be on Buster, or have manually installed Python >= 3.6.

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

Successfully merging this pull request may close these issues.

1 participant