icalendar.cal.timezone module#

RFC 5545 components for timezone information.

class icalendar.cal.timezone.Timezone(*args, **kwargs)[source]#

Bases: Component

A "VTIMEZONE" calendar component is a grouping of component properties that defines a time zone. It is used to describe the way in which a time zone changes its offset from UTC over time.

Examples

Get the example Timezone.

>>> from icalendar import Timezone
>>> timezone = Timezone.example()
>>> print(timezone["TZID"])
custom_Pacific/Fiji
>>> len(timezone.subcomponents)
5
DEFAULT_FIRST_DATE = datetime.date(1970, 1, 1)#
DEFAULT_LAST_DATE = datetime.date(2038, 1, 1)#
canonical_order = ('TZID',)#
property daylight: list[TimezoneDaylight]#

The DAYLIGHT subcomponents as a list.

These are for the daylight saving time.

classmethod example(name='pacific_fiji')[source]#

Return the timezone example with the given name.

Example

>>> from icalendar import Timezone
>>> timezone = Timezone.example()
>>> print(timezone["TZID"])
custom_Pacific/Fiji
Return type:

Timezone

classmethod from_tzid(tzid, tzp=TZP('zoneinfo'), first_date=datetime.date(1970, 1, 1), last_date=datetime.date(2038, 1, 1))[source]#

Create a VTIMEZONE from a tzid, such as "Europe/Berlin".

Parameters:
  • tzid (str) – The ID of the timezone.

  • tzp (TZP) – The timezone provider.

  • first_date (date) – A date that is earlier than anything that happens in the calendar.

  • last_date (date) – A date that is later than anything that happens in the calendar.

Return type:

Timezone

Returns:

A VTIMEZONE component for the given tzid.

Raises:

ValueError – If the tzid is unknown.

Example

>>> from icalendar import Timezone
>>> tz = Timezone.from_tzid("Europe/Berlin")
>>> print(tz.to_ical()[:36])
BEGIN:VTIMEZONE
TZID:Europe/Berlin

Note

This can take some time. Please cache the results.

classmethod from_tzinfo(timezone, tzid=None, first_date=datetime.date(1970, 1, 1), last_date=datetime.date(2038, 1, 1))[source]#

Return a VTIMEZONE component from a timezone object.

Calculate offsets from a pytz, zoneinfo, or other timezone object.

Parameters:
  • timezone (tzinfo) – Required. The timezone object used to calculate transitions.

  • first_date (date) – The starting date for the transition search.

  • last_date (date) – The ending date for the transition search.

  • tzid (str | None) – The timezone identifier. If None, derive it from timezone.

Returns:

The VTIMEZONE component for timezone.

Return type:

Timezone

Raises:

ValueError – If tzid is None and cannot be derived from timezone.

Note

This can take some time. Please cache the results.

get_transitions()[source]#

Return a tuple of (transition_times, transition_info)

  • transition_times = [datetime, …]

  • transition_info = [(TZOFFSETTO, dts_offset, tzname)]

Return type:

tuple[list[datetime], list[tuple[timedelta, timedelta, str]]]

name: ClassVar[str | None] = 'VTIMEZONE'#

The name of the component.

This is defined in each component class.

Example

>>> from icalendar import Calendar
>>> cal = Calendar.new()
>>> cal.name
'VCALENDAR'
required: ClassVar[tuple[()]] = ('TZID',)#

These properties are required.

singletons: ClassVar[tuple[()]] = ('TZID', 'LAST-MODIFIED', 'TZURL')#

These properties must appear only once.

property standard: list[TimezoneStandard]#

The STANDARD subcomponents as a list.

subcomponents: list[TimezoneStandard | TimezoneDaylight]#

All subcomponents of this component.

to_tz(tzp=TZP('zoneinfo'), lookup_tzid=True)[source]#

Convert this VTIMEZONE component to a timezone object.

Parameters:
  • tzp (TZP) – Timezone provider to use.

  • lookup_tzid (bool) – Whether to use the TZID property to look up existing timezone definitions with tzp. If True, the existing timezone is used if it exists; otherwise a new timezone is created. If False, a new timezone is always created.

Returns:

A timezone object, either looked up from tzp or newly created from this component.

property tz_name: str#

Return the name of the timezone component.

Please note that the names of the timezone are different from this name and may change with winter/summer time.

class icalendar.cal.timezone.TimezoneDaylight(*args, **kwargs)[source]#

Bases: Component

The "DAYLIGHT" sub-component of "VTIMEZONE" defines the daylight saving time offset from UTC for a time zone. It represents a time zone's daylight saving time, typically used during summer months in locations that observe Daylight Saving Time.

property DTSTART: datetime | None#

The DTSTART property.

The mandatory "DTSTART" property gives the effective onset date

and local time for the time zone sub-component definition. "DTSTART" in this usage MUST be specified as a date with a local time value.

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

property TZOFFSETFROM: timedelta | None#

The TZOFFSETFROM property.

The mandatory "TZOFFSETFROM" property gives the UTC offset that is

in use when the onset of this time zone observance begins. "TZOFFSETFROM" is combined with "DTSTART" to define the effective onset for the time zone sub-component definition. For example, the following represents the time at which the observance of Standard Time took effect in Fall 1967 for New York City:

DTSTART:19671029T020000 TZOFFSETFROM:-0400

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

property TZOFFSETTO: timedelta | None#

The TZOFFSETTO property.

The mandatory "TZOFFSETTO" property gives the UTC offset for the

time zone sub-component (Standard Time or Daylight Saving Time) when this observance is in use.

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

multiple: ClassVar[tuple[()]] = ('COMMENT', 'RDATE', 'TZNAME', 'RRULE', 'EXDATE')#

These properties may occur more than once.

name: ClassVar[str | None] = 'DAYLIGHT'#

The name of the component.

This is defined in each component class.

Example

>>> from icalendar import Calendar
>>> cal = Calendar.new()
>>> cal.name
'VCALENDAR'
required: ClassVar[tuple[()]] = ('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM')#

These properties are required.

singletons: ClassVar[tuple[()]] = ('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM')#

These properties must appear only once.

class icalendar.cal.timezone.TimezoneStandard(*args, **kwargs)[source]#

Bases: Component

The "STANDARD" sub-component of "VTIMEZONE" defines the standard time offset from UTC for a time zone. It represents a time zone's standard time, typically used during winter months in locations that observe Daylight Saving Time.

property DTSTART: datetime | None#

The DTSTART property.

The mandatory "DTSTART" property gives the effective onset date

and local time for the time zone sub-component definition. "DTSTART" in this usage MUST be specified as a date with a local time value.

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

property TZOFFSETFROM: timedelta | None#

The TZOFFSETFROM property.

The mandatory "TZOFFSETFROM" property gives the UTC offset that is

in use when the onset of this time zone observance begins. "TZOFFSETFROM" is combined with "DTSTART" to define the effective onset for the time zone sub-component definition. For example, the following represents the time at which the observance of Standard Time took effect in Fall 1967 for New York City:

DTSTART:19671029T020000 TZOFFSETFROM:-0400

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

property TZOFFSETTO: timedelta | None#

The TZOFFSETTO property.

The mandatory "TZOFFSETTO" property gives the UTC offset for the

time zone sub-component (Standard Time or Daylight Saving Time) when this observance is in use.

To delete the value, either use del or set it to None.

Raises:

InvalidCalendar – if the attribute has invalid values.

multiple: ClassVar[tuple[()]] = ('COMMENT', 'RDATE', 'TZNAME', 'RRULE', 'EXDATE')#

These properties may occur more than once.

name: ClassVar[str | None] = 'STANDARD'#

The name of the component.

This is defined in each component class.

Example

>>> from icalendar import Calendar
>>> cal = Calendar.new()
>>> cal.name
'VCALENDAR'
required: ClassVar[tuple[()]] = ('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM')#

These properties are required.

singletons: ClassVar[tuple[()]] = ('DTSTART', 'TZOFFSETTO', 'TZOFFSETFROM')#

These properties must appear only once.