-
-
Notifications
You must be signed in to change notification settings - Fork 412
Closed
Description
- [ x ] I am on the latest Pendulum version.
- Tested on both latest stable and the 3.0.0a1 release
- [ x ] I have searched the issues of this repo and believe that this is not a duplicate.
- OS version and name: Docker image alpine:3.18,
apk add python3 py3-pip && pip install pendulum - Pendulum version: Tested with both 2.1.2 and 3.0.0a1
Issue
On the alpine image, pendulum cannot find the local timezone. Thus import pendulum; pendulum.now() gives the exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.11/site-packages/pendulum/__init__.py", line 206, in now
return DateTime.now(tz)
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/pendulum/datetime.py", line 137, in now
dt = datetime.datetime.now(local_timezone())
^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/pendulum/tz/__init__.py", line 66, in local_timezone
return get_local_timezone()
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 33, in get_local_timezone
tz = _get_system_timezone()
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 61, in _get_system_timezone
return _get_unix_timezone()
^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/site-packages/pendulum/tz/local_timezone.py", line 244, in _get_unix_timezone
raise RuntimeError("Unable to find any timezone configuration")
RuntimeError: Unable to find any timezone configuration
Curiously, this stdlib approach works totally fine: from datetime import UTC, datetime; datetime.now(UTC).astimezone().tzinfo (gives UTC, as expected).
I saw that there was a fairly recent change to have pendulum timezone depend on stdlib. Perhaps that should be expanded to use the above approach to obtaining tzinfo as well - most likely more reliable?
tedmiston
Metadata
Metadata
Assignees
Labels
No labels