icalendar.prop.dt.datetime module#
DATE-TIME property type from RFC 5545.
- class icalendar.prop.dt.datetime.vDatetime(dt, /, params=None)[source]#
Bases:
TimeBaseDate-Time
- Value Name:
DATE-TIME
- Purpose:
This value type is used to identify values that specify a precise calendar date and time of day. The format is based on the ISO.8601.2004 complete representation.
- Format Definition:
This value type is defined by the following notation:
date-time = date "T" time date = date-value date-value = date-fullyear date-month date-mday date-fullyear = 4DIGIT date-month = 2DIGIT ;01-12 date-mday = 2DIGIT ;01-28, 01-29, 01-30, 01-31 ;based on month/year time = time-hour time-minute time-second [time-utc] time-hour = 2DIGIT ;00-23 time-minute = 2DIGIT ;00-59 time-second = 2DIGIT ;00-60 time-utc = "Z"The following is the representation of the date-time format.
YYYYMMDDTHHMMSS
- Description:
vDatetime is timezone aware and uses a timezone library. When a vDatetime object is created from an ical string, you can pass a valid timezone identifier. When a vDatetime object is created from a Python
datetimeobject, it uses the tzinfo component, if present. Otherwise a timezone-naive object is created. Be aware that there are certain limitations with timezone naive DATE-TIME components in the icalendar standard.
Example
The following represents March 2, 2021 at 10:15 AM with local time:
>>> from icalendar import vDatetime >>> datetime = vDatetime.from_ical("20210302T101500") >>> datetime.tzname() >>> datetime.year 2021 >>> datetime.minute 15
The following represents March 2, 2021 at 10:15 AM in New York:
>>> datetime = vDatetime.from_ical("20210302T101500", 'America/New_York') >>> datetime.tzname() 'EST'
The following represents March 2, 2021 at 10:15 AM in Berlin:
>>> from zoneinfo import ZoneInfo >>> timezone = ZoneInfo("Europe/Berlin") >>> vDatetime.from_ical("20210302T101500", timezone) datetime.datetime(2021, 3, 2, 10, 15, tzinfo=ZoneInfo(key='Europe/Berlin'))
- static from_ical(ical, timezone=None)[source]#
Create a datetime from the RFC string.
- Parameters:
ical (str | bytes) – Required. The iCalendar DATE-TIME value to parse.
timezone (str | datetime.tzinfo | None) – The time zone name or object used to localize the result. If
None, a trailingZselects UTC and other values remain floating.
- Raises:
ICalParsingError – If the value is not a valid DATE-TIME.
- classmethod from_jcal(jcal_property)[source]#
Parse jCal from RFC 7265.
- Parameters:
jcal_property (
list) – The jCal property to parse.- Raises:
JCalParsingError – If the provided jCal is invalid.
- Return type:
- classmethod from_xcal(xml)[source]#
Parse xCal according to RFC 6321.
- Parameters:
parser – Required. The xCal to parse or a parser.
params – Required. The parameters of the xCal element.
- Raises:
XCalParsingError – If the provided xCal is invalid.
- Return type:
VProp
- classmethod from_xcal_element(element)[source]#
Parse an xCal date-time element according to RFC 6321.
- Parameters:
element (
ElementAdapter) – Required. The xCal element to parse.- Return type:
- Returns:
The datetime object, possibly with a UTC timezone.
- Raises:
XCalParsingError – If the provided xCal is invalid.
- property ical_value: datetime#
The datetime value of this property.
- Returns:
The datetime of the property. If its
tzinfowas set, then it's timezone-aware, else it's naive and set toNone.
Examples
The following represents a datetime where
tzinfois set toNone:>>> from datetime import datetime, timezone >>> from icalendar import vDatetime >>> naive = vDatetime(datetime(2025, 11, 10, 16, 52)) >>> naive.ical_value datetime.datetime(2025, 11, 10, 16, 52) >>> print(naive.ical_value.tzinfo) None
The following represents a datetime where
tzinfois set totimezone.utc:>>> aware = vDatetime(datetime(2025, 11, 10, 16, 52, tzinfo=timezone.utc)) >>> aware.ical_value datetime.datetime(2025, 11, 10, 16, 52, tzinfo=datetime.timezone.utc) >>> print(aware.ical_value.tzinfo) UTC
- params: Parameters#
- classmethod parse_jcal_value(jcal)[source]#
Parse a jCal string to a
datetime.datetime.- Raises:
JCalParsingError – If it can't parse a date-time value.
- Return type: