Next / Previous / Contents / TCC Help System / NM Tech homepage

9.11. class FixedZone: Fixed-offset time zone

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().

sidereal.py
# - - - - -   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.

sidereal.py
    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.

sidereal.py
    def utcoffset(self, dt):
        """Return self's offset east of UTC.
        """
        return  self.__offset

The .tzname() method returns the zone's name.

sidereal.py
    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.

sidereal.py
    def  dst(self, dt):
        """Return self's daylight time offset.
        """
        return  DELTA_ZERO