[Zodb-checkins] CVS: Zope3/src/zope/interface/common - idatetime.py:1.1

Viktorija Zaksiene ryzaja at codeworks.lt
Wed Apr 23 10:37:44 EDT 2003


Update of /cvs-repository/Zope3/src/zope/interface/common
In directory cvs.zope.org:/tmp/cvs-serv29842

Added Files:
	idatetime.py 
Log Message:
Added interfaces for date/time classes according python2.3 documentation.


=== Added File Zope3/src/zope/interface/common/idatetime.py === (480/580 lines abridged)
##############################################################################
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
"""Datetime interfaces.

This module is called idatetime because if it were called datetime the import
of the real datetime would fail.

$Id: idatetime.py,v 1.1 2003/04/23 13:37:42 ryzaja Exp $
"""

from zope.interface import Interface, Attribute
from zope.interface.implements import implements

from datetime import timedelta, date, datetime, time, tzinfo


class ITimeDelta(Interface):
    """Represent the difference between two datetime objects.

    Supported operators:

    - add, subtract timedelta
    - unary plus, minus, abs
    - compare to timedelta
    - multiply, divide by int/long

    In addition, datetime supports subtraction of two datetime objects
    returning a timedelta, and addition or subtraction of a datetime
    and a timedelta giving a datetime.

    Representation: (days, seconds, microseconds).
    """

    days = Attribute("Days between -999999999 and 999999999 inclusive")

    seconds = Attribute("Seconds between 0 and 86399 inclusive")

    microseconds = Attribute("Microseconds between 0 and 999999 inclusive")


class ITimeDeltaClass(Interface):

[-=- -=- -=- 480 lines omitted -=- -=- -=-]

    max = Attribute("The latest representable time")

    resolution = Attribute(
        "The smallest possible difference between non-equal time objects")


class ITZInfoClass(Interface):
    """Abstract base class for time zone info classes.

    Subclasses must override the name(), utcoffset() and dst() methods.
    """

    def utcoffset(dt):
        """Return offset of local time from UTC, in minutes east of UTC.

        If local time is west of UTC, this should be negative.
        Note that this is intended to be the total offset from UTC;
        for example, if a tzinfo object represents both time zone and DST
        adjustments, utcoffset() should return their sum. If the UTC offset
        isn't known, return None. Else the value returned must be a timedelta
        object specifying a whole number of minutes in the range -1439 to 1439
        inclusive (1440 = 24*60; the magnitude of the offset must be less
        than one day).
        """

    def dst(dt):
        """Return the daylight saving time (DST) adjustment, in minutes east
        of UTC, or None if DST information isn't known.
        """

    def tzname(dt):
        """Return the time zone name corresponding to the datetime object as
        a string.
        """

    def fromutc(dt):
        """Return an equivalent datetime in self's local time."""


# XXX Later we would like to apply new zope.interface methods here.
implements(timedelta, ITimeDelta)
implements(date, IDate)
implements(datetime, IDateTime)
implements(time, ITime)

implements(timedelta, ITimeDeltaClass)
implements(date, IDateClass)
implements(datetime, IDateTimeClass)
implements(time, ITimeClass)
implements(tzinfo, ITZInfoClass)




More information about the Zodb-checkins mailing list