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

Viktorija Zaksiene ryzaja at codeworks.lt
Mon May 5 05:26:44 EDT 2003


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

Modified Files:
	idatetime.py 
Log Message:
Updated interface declarations to the new style.


=== Zope3/src/zope/interface/common/idatetime.py 1.1 => 1.2 ===
--- Zope3/src/zope/interface/common/idatetime.py:1.1	Wed Apr 23 09:37:42 2003
+++ Zope3/src/zope/interface/common/idatetime.py	Mon May  5 04:26:12 2003
@@ -18,12 +18,23 @@
 """
 
 from zope.interface import Interface, Attribute
-from zope.interface.implements import implements
+from zope.interface import classImplements, directlyProvides
 
 from datetime import timedelta, date, datetime, time, tzinfo
 
 
-class ITimeDelta(Interface):
+class ITimeDeltaClass(Interface):
+    """This is the timedelta class interface."""
+
+    min = Attribute("The most negative timedelta object")
+
+    max = Attribute("The most positive timedelta object")
+
+    resolution = Attribute(
+        "The smallest difference between non-equal timedelta objects")
+
+
+class ITimeDelta(ITimeDeltaClass):
     """Represent the difference between two datetime objects.
 
     Supported operators:
@@ -47,18 +58,41 @@
     microseconds = Attribute("Microseconds between 0 and 999999 inclusive")
 
 
-class ITimeDeltaClass(Interface):
-    """This is the timedelta class interface."""
+class IDateClass(Interface):
+    """This is the date class interface."""
 
-    min = Attribute("The most negative timedelta object")
+    min = Attribute("The earliest representable date")
 
-    max = Attribute("The most positive timedelta object")
+    max = Attribute("The latest representable date")
 
     resolution = Attribute(
-        "The smallest difference between non-equal timedelta objects")
+        "The smallest difference between non-equal date objects")
 
+    def today():
+        """Return the current local time.
 
-class IDate(Interface):
+        This is equivalent to date.fromtimestamp(time.time())"""
+
+    def fromtimestamp(timestamp):
+        """Return the local date from a POSIX timestamp (like time.time())
+
+        This may raise ValueError, if the timestamp is out of the range of
+        values supported by the platform C localtime() function. It's common
+        for this to be restricted to years from 1970 through 2038. Note that
+        on non-POSIX systems that include leap seconds in their notion of a
+        timestamp, leap seconds are ignored by fromtimestamp().
+        """
+
+    def fromordinal(ordinal):
+        """Return the date corresponding to the proleptic Gregorian ordinal.
+
+         January 1 of year 1 has ordinal 1. ValueError is raised unless
+         1 <= ordinal <= date.max.toordinal().
+         For any date d, date.fromordinal(d.toordinal()) == d.
+         """
+
+
+class IDate(IDateClass):
     """Represents a date (year, month and day) in an idealized calendar.
 
     Operators:
@@ -164,41 +198,100 @@
         """
 
 
-class IDateClass(Interface):
-    """This is the date class interface."""
+class IDateTimeClass(Interface):
+    """This is the datetime class interface."""
 
-    min = Attribute("The earliest representable date")
+    min = Attribute("The earliest representable datetime")
 
-    max = Attribute("The latest representable date")
+    max = Attribute("The latest representable datetime")
 
     resolution = Attribute(
-        "The smallest difference between non-equal date objects")
+        "The smallest possible difference between non-equal datetime objects")
 
     def today():
-        """Return the current local time.
+        """Return the current local datetime, with tzinfo None.
 
-        This is equivalent to date.fromtimestamp(time.time())"""
+        This is equivalent to datetime.fromtimestamp(time.time()).
+        See also now(), fromtimestamp().
+        """
 
-    def fromtimestamp(timestamp):
-        """Return the local date from a POSIX timestamp (like time.time())
+    def now(tz=None):
+        """Return the current local date and time.
+
+        If optional argument tz is None or not specified, this is like today(),
+        but, if possible, supplies more precision than can be gotten from going
+        through a time.time() timestamp (for example, this may be possible on
+        platforms supplying the C gettimeofday() function).
+
+        Else tz must be an instance of a class tzinfo subclass, and the current
+        date and time are converted to tz's time zone. In this case the result
+        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).
+
+        See also today(), utcnow().
+        """
+
+    def utcnow():
+        """Return the current UTC date and time, with tzinfo None.
+
+        This is like now(), but returns the current UTC date and time, as a
+        naive datetime object. 
+
+        See also now().
+        """
+
+    def fromtimestamp(timestamp, tz=None):
+        """Return the local date and time corresponding to the POSIX timestamp.
+
+        Same as is returned by time.time(). If optional argument tz is None or
+        not specified, the timestamp is converted to the platform's local date
+        and time, and the returned datetime object is naive.
+
+        Else tz must be an instance of a class tzinfo subclass, and the
+        timestamp is converted to tz's time zone. In this case the result is
+        equivalent to
+        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).
+
+        fromtimestamp() may raise ValueError, if the timestamp is out of the
+        range of values supported by the platform C localtime() or gmtime()
+        functions. It's common for this to be restricted to years in 1970
+        through 2038. Note that on non-POSIX systems that include leap seconds
+        in their notion of a timestamp, leap seconds are ignored by
+        fromtimestamp(), and then it's possible to have two timestamps
+        differing by a second that yield identical datetime objects.
+
+        See also utcfromtimestamp().
+        """
+
+    def utcfromtimestamp(timestamp):
+        """Return the UTC datetime from the POSIX timestamp with tzinfo None.
 
         This may raise ValueError, if the timestamp is out of the range of
-        values supported by the platform C localtime() function. It's common
-        for this to be restricted to years from 1970 through 2038. Note that
-        on non-POSIX systems that include leap seconds in their notion of a
-        timestamp, leap seconds are ignored by fromtimestamp().
+        values supported by the platform C gmtime() function. It's common for
+        this to be restricted to years in 1970 through 2038.
+
+        See also fromtimestamp().
         """
 
     def fromordinal(ordinal):
-        """Return the date corresponding to the proleptic Gregorian ordinal.
+        """Return the datetime from the proleptic Gregorian ordinal.
 
-         January 1 of year 1 has ordinal 1. ValueError is raised unless
-         1 <= ordinal <= date.max.toordinal().
-         For any date d, date.fromordinal(d.toordinal()) == d.
-         """
+        January 1 of year 1 has ordinal 1. ValueError is raised unless
+        1 <= ordinal <= datetime.max.toordinal().
+        The hour, minute, second and microsecond of the result are all 0, and
+        tzinfo is None.
+        """
 
+    def combine(date, time):
+        """Return a new datetime object.
+
+        Its date members are equal to the given date object's, and whose time
+        and tzinfo members are equal to the given time object's. For any
+        datetime object d, d == datetime.combine(d.date(), d.timetz()).
+        If date is a datetime object, its time and tzinfo members are ignored.
+        """
 
-class IDateTime(IDate):
+
+class IDateTime(IDate, IDateTimeClass):
     """Object contains all the information from a date object and a time object.
     """
 
@@ -353,100 +446,18 @@
         """
 
 
-class IDateTimeClass(Interface):
-    """This is the datetime class interface."""
+class ITimeClass(Interface):
+    """This is the time class interface."""
 
-    min = Attribute("The earliest representable datetime")
+    min = Attribute("The earliest representable time")
 
-    max = Attribute("The latest representable datetime")
+    max = Attribute("The latest representable time")
 
     resolution = Attribute(
-        "The smallest possible difference between non-equal datetime objects")
-
-    def today():
-        """Return the current local datetime, with tzinfo None.
-
-        This is equivalent to datetime.fromtimestamp(time.time()).
-        See also now(), fromtimestamp().
-        """
-
-    def now(tz=None):
-        """Return the current local date and time.
-
-        If optional argument tz is None or not specified, this is like today(),
-        but, if possible, supplies more precision than can be gotten from going
-        through a time.time() timestamp (for example, this may be possible on
-        platforms supplying the C gettimeofday() function).
-
-        Else tz must be an instance of a class tzinfo subclass, and the current
-        date and time are converted to tz's time zone. In this case the result
-        is equivalent to tz.fromutc(datetime.utcnow().replace(tzinfo=tz)).
-
-        See also today(), utcnow().
-        """
-
-    def utcnow():
-        """Return the current UTC date and time, with tzinfo None.
-
-        This is like now(), but returns the current UTC date and time, as a
-        naive datetime object. 
-
-        See also now().
-        """
-
-    def fromtimestamp(timestamp, tz=None):
-        """Return the local date and time corresponding to the POSIX timestamp.
-
-        Same as is returned by time.time(). If optional argument tz is None or
-        not specified, the timestamp is converted to the platform's local date
-        and time, and the returned datetime object is naive.
-
-        Else tz must be an instance of a class tzinfo subclass, and the
-        timestamp is converted to tz's time zone. In this case the result is
-        equivalent to
-        tz.fromutc(datetime.utcfromtimestamp(timestamp).replace(tzinfo=tz)).
-
-        fromtimestamp() may raise ValueError, if the timestamp is out of the
-        range of values supported by the platform C localtime() or gmtime()
-        functions. It's common for this to be restricted to years in 1970
-        through 2038. Note that on non-POSIX systems that include leap seconds
-        in their notion of a timestamp, leap seconds are ignored by
-        fromtimestamp(), and then it's possible to have two timestamps
-        differing by a second that yield identical datetime objects.
-
-        See also utcfromtimestamp().
-        """
-
-    def utcfromtimestamp(timestamp):
-        """Return the UTC datetime from the POSIX timestamp with tzinfo None.
-
-        This may raise ValueError, if the timestamp is out of the range of
-        values supported by the platform C gmtime() function. It's common for
-        this to be restricted to years in 1970 through 2038.
-
-        See also fromtimestamp().
-        """
-
-    def fromordinal(ordinal):
-        """Return the datetime from the proleptic Gregorian ordinal.
-
-        January 1 of year 1 has ordinal 1. ValueError is raised unless
-        1 <= ordinal <= datetime.max.toordinal().
-        The hour, minute, second and microsecond of the result are all 0, and
-        tzinfo is None.
-        """
-
-    def combine(date, time):
-        """Return a new datetime object.
-
-        Its date members are equal to the given date object's, and whose time
-        and tzinfo members are equal to the given time object's. For any
-        datetime object d, d == datetime.combine(d.date(), d.timetz()).
-        If date is a datetime object, its time and tzinfo members are ignored.
-        """
+        "The smallest possible difference between non-equal time objects")
 
 
-class ITime(Interface):
+class ITime(ITimeClass):
     """Represent time with time zone.
 
     Operators:
@@ -523,21 +534,8 @@
         """
 
 
-class ITimeClass(Interface):
-    """This is the time class interface."""
-
-    min = Attribute("The earliest representable time")
-
-    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.
+class ITZInfo(Interface):
+    """Time zone info class.
     """
 
     def utcoffset(dt):
@@ -567,14 +565,13 @@
         """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)
+classImplements(timedelta, ITimeDelta)
+classImplements(date, IDate)
+classImplements(datetime, IDateTime)
+classImplements(time, ITime)
+classImplements(tzinfo, ITZInfo)
+
+directlyProvides(timedelta, ITimeDeltaClass)
+directlyProvides(date, IDateClass)
+directlyProvides(datetime, IDateTimeClass)
+directlyProvides(time, ITimeClass)




More information about the Zodb-checkins mailing list