tz.py 701 B

123456789101112131415161718192021222324
  1. from datetime import tzinfo, timedelta
  2. class TomlTz(tzinfo):
  3. def __init__(self, toml_offset):
  4. if toml_offset == "Z":
  5. self._raw_offset = "+00:00"
  6. else:
  7. self._raw_offset = toml_offset
  8. self._sign = -1 if self._raw_offset[0] == '-' else 1
  9. self._hours = int(self._raw_offset[1:3])
  10. self._minutes = int(self._raw_offset[4:6])
  11. def __deepcopy__(self, memo):
  12. return self.__class__(self._raw_offset)
  13. def tzname(self, dt):
  14. return "UTC" + self._raw_offset
  15. def utcoffset(self, dt):
  16. return self._sign * timedelta(hours=self._hours, minutes=self._minutes)
  17. def dst(self, dt):
  18. return timedelta(0)