(Zope の日時型 (DateTime))

Description

Using Zope DateTime class in Plone programming

はじめに

Some Plone dates are stored as Zope DateTime objects. This is different from standard Python datetime (notice the letter casing). Zope DateTime predates Python datetime which was added in Python 2.4. Zope DateTime is old code, so do rites necessary for your religion before programming with it.

ノート

Using Python datetime is recommended if possible. Zope DateTime should be dealt in legacy systems only as Python datetime is much more documented and widely used.

Converting between DateTime and datetime

Since two different datetime object types are used, you need to often convert between them.

Please see

DateTime to datetime:

from Products.ATContentTypes.utils import DT2dt

python_dt = DT2dt(zope_dt)

DateTime problems and pitfalls

This will fail silenty and you get a wrong date:

dt = DateTime("02.07.2010") # Parses like US date 02/07/2010

Please see

Parsing both US and European dates

Example:

# Lazy ass way to parse both formats
# 2010/31/12
# 31.12.2010
try:
    if "." in rendDate:
        # European
        end = DateTime(rendDate, datefmt='international')
    else:
        # US
        end = DateTime(rendDate)

目次

前のトピックへ

(コンテクストヘルパー)

次のトピックへ

(メール送信)

このページ