-
Notifications
You must be signed in to change notification settings - Fork 15
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
use tzinfo instead of str to identify the TimeZone in ZonedDateTime #65
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 |
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_provider Interesting 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 |
Lots to think about. My impression is that most issues are solved by:
|
The ZonedDateTime class uses a
str
to identify the timezone. Please consider using the standard tzinfo class instead. Usingtzinfo
allows 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
zoneinfo
has bugs in obscure edge cases. (pytz
has even more bugs, as well as the year 2038 problem). My libraries don't.The text was updated successfully, but these errors were encountered: