This class represents a time zone with a fixed offset in hours
and minutes east of UTC. It is a concrete class implementing
the abstract class datetime.tzinfo, so it
must implement concrete methods utcoffset(),
tzname(), and dst().
# - - - - - c l a s s F i x e d Z o n e
DELTA_ZERO = datetime.timedelta(0)
DELTA_HOUR = datetime.timedelta(hours=1)
class FixedZone(datetime.tzinfo):
"""Represents a time zone with a fixed offset east of UTC.
Exports:
FixedZone ( hours, minutes, name ):
[ (hours is a signed offset in hours as an int) and
(minutes is a signed offset in minutes as an int) ->
return a new FixedZone instance representing
those offsets east of UTC ]
State/Invariants:
.__offset:
[ a datetime.timedelta representing self's offset
east of UTC ]
.__name:
[ as passed to the constructor's name argument ]
"""
This class is an adaptation of the FixedOffset
class shown in the examples section of the
reference material for datetime.tzinfo.
The constructor combines the hours and minutes arguments into a datetime.timedelta instance and stores them in the
instance.
def __init__ ( self, hh, mm, name ):
"""Constructor for FixedZone.
"""
self.__offset = datetime.timedelta ( hours=hh, minutes=mm )
self.__name = name
The .utcoffset() method returns the offset east
of UTC.
def utcoffset(self, dt):
"""Return self's offset east of UTC.
"""
return self.__offset
The .tzname() method returns the zone's name.
def tzname(self, dt):
"""Return self's name.
"""
return self.__name
The .dst() method always returns DELTA_ZERO, since a fixed time zone by definition
never has daylight time.
def dst(self, dt):
"""Return self's daylight time offset.
"""
return DELTA_ZERO