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'))
- property VALUE: str#
The VALUE parameter or the default.
- Purpose:
VALUE explicitly specify the value type format for a property value.
- Description:
This parameter specifies the value type and format of the property value. The property values MUST be of a single value type. For example, a "RDATE" property cannot have a combination of DATE-TIME and TIME value types.
If the property's value is the default value type, then this parameter need not be specified. However, if the property's default value type is overridden by some other allowable value type, then this parameter MUST be specified.
Applications MUST preserve the value data for
x-nameandiana-tokenvalues that they don't recognize without attempting to interpret or parse the value data.
- Returns:
The VALUE parameter or the default.
Examples
The VALUE defaults to the name of the property. Note that it is case-insensitive but always uppercase.
>>> from icalendar import vBoolean >>> b = vBoolean(True) >>> b.VALUE 'BOOLEAN'
Setting the VALUE parameter of a typed property usually does not make sense. For convenience, using this property, the value will be converted to an uppercase string. If you have some custom property, you might use it like this:
>>> from icalendar import vUnknown, Event >>> v = vUnknown("Some property text.") >>> v.VALUE = "x-type" # lower case >>> v.VALUE 'X-TYPE' >>> event = Event() >>> event.add("x-prop", v) >>> print(event.to_ical()) BEGIN:VEVENT X-PROP;VALUE=X-TYPE:Some property text. END:VEVENT
- 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:
- 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: