class DateTimeTimeZone
A class representing a date, time, and time zone combination for a specific point in time, compatible with Office 365 API structures.
/tf/active/vicechatdev/SPFCsync/venv/lib64/python3.11/site-packages/office365/outlook/calendar/dateTimeTimeZone.py
6 - 32
simple
Purpose
DateTimeTimeZone is a data transfer object (DTO) that encapsulates date, time, and timezone information in a format compatible with Office 365/Microsoft Graph APIs. It inherits from ClientValue, making it serializable for API communication. The class provides functionality to create instances from Python datetime objects and represents temporal data in ISO 8601 format with timezone information.
Source Code
class DateTimeTimeZone(ClientValue):
"""Describes the date, time, and time zone of a point in time."""
def __init__(self, datetime=None, timezone=None):
"""
:param str timezone: Represents a time zone, for example, "Pacific Standard Time".
:param str datetime: A single point of time in a combined date and time representation ({date}T{time};
for example, 2017-08-29T04:00:00.0000000).
"""
super(DateTimeTimeZone, self).__init__()
self.dateTime = datetime
self.timeZone = timezone
def __repr__(self):
return "{0}, {1}".format(self.dateTime, self.timeZone)
@staticmethod
def parse(dt):
"""
Parses from datetime
:type dt: datetime.datetime
"""
local_dt = dt.replace(tzinfo=pytz.utc)
return DateTimeTimeZone(
datetime=local_dt.isoformat(), timezone=local_dt.strftime("%Z")
)
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
bases |
ClientValue | - |
Parameter Details
datetime: A string representing a single point of time in combined date and time format following ISO 8601 standard (e.g., '2017-08-29T04:00:00.0000000'). This parameter is optional and defaults to None if not provided.
timezone: A string representing the time zone name (e.g., 'Pacific Standard Time', 'UTC'). This parameter is optional and defaults to None if not provided. The timezone should be a human-readable timezone identifier.
Return Value
The constructor returns a DateTimeTimeZone instance with dateTime and timeZone attributes set. The parse() static method returns a new DateTimeTimeZone instance created from a Python datetime.datetime object, with the datetime converted to ISO format and timezone extracted as a string abbreviation.
Class Interface
Methods
__init__(self, datetime=None, timezone=None)
Purpose: Initializes a DateTimeTimeZone instance with optional datetime and timezone strings
Parameters:
datetime: Optional string in ISO 8601 format representing the date and time (e.g., '2017-08-29T04:00:00.0000000')timezone: Optional string representing the timezone name (e.g., 'Pacific Standard Time', 'UTC')
Returns: None (constructor)
__repr__(self) -> str
Purpose: Returns a string representation of the DateTimeTimeZone object for debugging and display
Returns: A formatted string containing the datetime and timezone separated by a comma (e.g., '2017-08-29T04:00:00.0000000, Pacific Standard Time')
parse(dt: datetime.datetime) -> DateTimeTimeZone
static
Purpose: Static method that creates a DateTimeTimeZone instance from a Python datetime object, converting it to UTC and ISO 8601 format
Parameters:
dt: A Python datetime.datetime object to be converted into a DateTimeTimeZone instance
Returns: A new DateTimeTimeZone instance with the datetime converted to ISO 8601 format in UTC timezone and timezone set to the UTC abbreviation
Attributes
| Name | Type | Description | Scope |
|---|---|---|---|
dateTime |
str or None | Stores the date and time as a string in ISO 8601 format (e.g., '2017-08-29T04:00:00.0000000'). Set during initialization or by the parse() method. | instance |
timeZone |
str or None | Stores the timezone name or abbreviation as a string (e.g., 'Pacific Standard Time', 'UTC'). Set during initialization or by the parse() method. | instance |
Dependencies
pytzoffice365
Required Imports
import pytz
from office365.runtime.client_value import ClientValue
Usage Example
from datetime import datetime
import pytz
from office365.runtime.client_value import ClientValue
# Method 1: Direct instantiation with strings
dt_tz = DateTimeTimeZone(
datetime='2017-08-29T04:00:00.0000000',
timezone='Pacific Standard Time'
)
print(dt_tz) # Output: 2017-08-29T04:00:00.0000000, Pacific Standard Time
# Method 2: Parse from Python datetime object
py_datetime = datetime(2023, 12, 25, 10, 30, 0)
dt_tz_parsed = DateTimeTimeZone.parse(py_datetime)
print(dt_tz_parsed) # Output: 2023-12-25T10:30:00+00:00, UTC
# Access attributes
print(dt_tz_parsed.dateTime) # '2023-12-25T10:30:00+00:00'
print(dt_tz_parsed.timeZone) # 'UTC'
Best Practices
- Use the static parse() method when converting from Python datetime objects to ensure proper ISO 8601 formatting and timezone handling
- The parse() method automatically converts datetime to UTC timezone using pytz.utc, so be aware of timezone conversions
- When instantiating directly, ensure the datetime string follows ISO 8601 format ({date}T{time}) for compatibility with Office 365 APIs
- The __repr__ method provides a human-readable string representation useful for debugging and logging
- This class is immutable after instantiation - attributes are set in __init__ and not modified by any methods
- The class inherits from ClientValue, which likely provides serialization capabilities for Office 365 API communication
- Timezone strings should be recognizable timezone names or abbreviations (e.g., 'UTC', 'PST', 'Pacific Standard Time')
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
class TimeZoneBase 74.1% similar
-
class TimeZoneInformation 72.4% similar
-
class CustomTimeZone 69.7% similar
-
class TimeZoneInformation_v1 69.0% similar
-
class TimeZone 68.2% similar