Replies: 4 comments
-
|
Interesting! You'll agree though that the 'customized tzinfo class' use case is niche. My general approach to these kind of issues are to allow them if the API doesn't become too complex for the 'average' user. What immediately comes to mind is to allow
Thes are pretty big downsides IMHO, as established identifiers are key for interoperability. Another potential solution is to provide a
Pardon my ignorance, but: shouldn't these be fixed there then? Are these bugs with the Python library, or the actual IANA tz db? Alternatively, isn't it possible to modify the |
Beta Was this translation helpful? Give feedback.
-
|
I'll address your questions about the I think the least desirable solution is a I agree that using a non-IANA timezone identifier may be niche, but I think the need or desire to use a different timezone library may be more common than you might think:
Proposed Solution Here is my solution that I think is compatible with your current constraints on (Sorry for any dumb syntax errors below, I haven't done much Python coding in several years...) import zoneinfo
from typing_extensions import Protocol
[...]
class TzProvider(Protocol):
def gettz(name: str) -> tzinfo:
...
class ZoneInfoProvider(TzProvider):
def gettz(name: str) -> tzinfo:
return zoneinfo.ZoneInfo(name)Then at the _tz_provider = ZoneInfoProvider()
def set_tz_provider(provider: TzProvider) -> None:
_tz_provider = provider
def get_tz_provider() -> TzProvider:
"""Probably useful only for testing purposes"""
return _tz_providerInteresting Consequences I realize that a pluggable A pluggable One interesting consequence is that this solution is that it allows from whenever import ZonedDateTime
from whenever import TzProvider
from whenever import set_tz_provider
class PosixProvider(TzProvider):
def gettz(name: str):
# ...
posix_provider = PosixProvider()
set_tz_provider(posix_provider)
tz = ZonedDateTime(tz="NZST-12NZDT,M9.5.0,M4.1.0/3")Implications for Pickling I don't actually understand the requirements of Python pickling, so I don't know what is required of the |
Beta Was this translation helpful? Give feedback.
-
|
Lots to think about. My impression is that most issues are solved by:
|
Beta Was this translation helpful? Give feedback.
-
|
This came up again in #223. Two updates to this thread.
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
The ZonedDateTime class uses a
strto identify the timezone. Please consider using the standard tzinfo class instead. Usingtzinfoallows alternative timezone libraries to be used instead of the one baked intowhatever(presumably zoneinfo).I have my own timezone Python library. It provides 2 different implementations of
tzinfo. Both are drop-in replacements forzoneinfo,pytz, or any other Python timezone libraries. Given the current implementation ofZonedDateTime, I cannot use my own timezone library withwhatever.Why do I want to use my own? Because
zoneinfohas bugs in obscure edge cases. (pytzhas even more bugs, as well as the year 2038 problem). My libraries don't.Beta Was this translation helpful? Give feedback.
All reactions