Skip to content

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