You can do this directly on the constructor: class datetime.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo ]]]]]) , tzinfo is datetime.tzinfo dervided object.
tzinfo is an abstract base class, meaning that this class should not be created directly. You need to get a specific subclass and (at least) supply implementations of the standard tzinfo methods needed to use the datetime methods that you use. The datetime module does not provide any specific subclasses of tzinfo.
What you need to override is the utcoffset(self, dt) method.
Local time offset from UTC, in minutes east of UTC. If local time is west of UTC, this should be negative. Please note that this must be a full offset from UTC; for example, if the tzinfo object represents both temporary and DST settings, utcoffset () should return its amount. If the UTC offset is unknown, return None. Otherwise, the return value should be a timedelta object with an integer number of minutes in the range from -1439 to 1439 inclusive (1440 = 24 * 60, the offset should be less than one day). Most utcoffset () implementations are likely to look like one of the following:
return CONSTANT # fixed-offset class
return CONSTANT + self.dst(dt) # daylight-aware class
If utcoffset () does not return None, dst () should also not return None.
The default utcoffset () implementation raises a NotImplementedError.
voyager
source share