icalendar.timezone.tzp module#
- class icalendar.timezone.tzp.TZP(provider='zoneinfo')[source]#
Bases:
objectThis is the timezone provider proxy.
If you would like to have another timezone implementation, you can create a new one and pass it to this proxy. All of icalendar will then use this timezone implementation.
Create a new timezone implementation proxy.
- cache_timezone_component(timezone_component)[source]#
Cache the timezone that is created from a timezone component if it is not already known.
This can influence the result from timezone(): Once cached, the custom timezone is returned from timezone().
- clean_timezone_id(tzid)[source]#
Return a clean version of the timezone id.
Timezone ids can be a bit unclean, starting with a / for example. Internally, we should use this to identify timezones.
- Return type:
- create_timezone(timezone_component)[source]#
Create a timezone from a timezone component.
This component will not be cached.
- localize(dt, tz)[source]#
Localize a datetime or time to a timezone.
- Overloads:
self, dt (datetime.datetime), tz (datetime.tzinfo | str | None) → datetime.datetime
self, dt (datetime.time), tz (datetime.tzinfo | str | None) → datetime.time
- Returns:
A localized
datetime.datetimewhen adatetime.datetimeis given.A localized
datetime.timewhen adatetime.timeis given.
- localize_utc(dt)[source]#
Return the datetime in UTC.
If the datetime has no timezone, set UTC as its timezone.
- timezone(tz_id)[source]#
Return a timezone with an ID or
Noneif we can't find it.tz_idmay be a plain Olson name (Europe/Berlin), a Windows timezone name, or a "globally unique" identifier (RFC 5545 Section 3.2.19) such as/freeassociation.sourceforge.net/Europe/Berlin. We try the candidate IDs from_lookup_ids()in order, checking the cache before the provider for each one, and cache the first match under the primary ID so the next lookup is fast.A lookup that is resolved by guessing the trailing Olson identifier emits
GloballyUniqueTZIDGuessedon every call, including when the result is served from the cache.- Return type:
datetime.tzinfo | None