Zope DateTime
The DateTime package provides a specific DateTime data type primarily intended for use within Zope applications and APIs. It aims to offer a consistent date/time representation within that ecosystem. Currently at version 6.0, this library is actively maintained by the Zope Foundation, with releases generally tied to Zope's development cycle, though less frequently than core Python modules.
Warnings
- gotcha This `DateTime` library (with a capital 'D') is *not* Python's built-in `datetime` module. The package summary explicitly states, 'Unless you need to communicate with Zope APIs, you're probably better off using Python's built-in datetime module.' Using `DateTime` when the built-in `datetime` is sufficient adds unnecessary dependencies and can lead to confusion.
- breaking Version 6.0 replaced `pkg_resources` namespace packaging with PEP 420 native namespace packaging. This may cause issues in deployment environments or build systems that rely on the older `pkg_resources` mechanism for discovering or handling namespace packages.
- breaking Version 5.5 changed the internal pickle format for DateTime objects to correctly export microseconds as an integer, specifically addressing issues with dates after the year 2038. This means that DateTime objects pickled with versions prior to 5.5 might not be unpickleable or might be unpickled incorrectly when using version 5.5 or later.
- gotcha The default timezone behavior can be inconsistent. If a timezone is not explicitly provided in the constructor (e.g., via a string), the local machine's timezone is used. However, if the date string format matches ISO 8601 ('YYYY-MM-DD') without an explicit timezone, the instance will default to UTC/GMT+0. This can lead to unexpected timezone interpretations.
- deprecated Support for `DateTime.__cmp__` for object comparison has been removed. Direct use of the `cmp()` function or reliance on `__cmp__` will lead to errors.
Install
-
pip install DateTime
Imports
- DateTime
from DateTime import DateTime
Quickstart
from DateTime import DateTime
import os
# Create a DateTime object for the current moment
now = DateTime()
print(f"Current DateTime: {now}")
# Create a DateTime object from a string with a specified timezone
specific_time = DateTime("2025-10-27 14:30:00 US/Eastern")
print(f"Specific DateTime: {specific_time}")
# Access components
print(f"Year: {specific_time.year()}, Month: {specific_time.month()}, Day: {specific_time.day()}")
print(f"Hour: {specific_time.hour()}, Minute: {specific_time.minute()}, Second: {specific_time.second()}")
# Convert to Python's built-in datetime object for interoperability
dt_obj = specific_time.asdatetime()
print(f"As Python datetime: {dt_obj}")