Skip to content

Instantly share code, notes, and snippets.

@tomwhoiscontrary
Created May 5, 2020 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomwhoiscontrary/b965daac47fb6bd85df03aff4c911b1d to your computer and use it in GitHub Desktop.
Save tomwhoiscontrary/b965daac47fb6bd85df03aff4c911b1d to your computer and use it in GitHub Desktop.
A minimal but i believe correct implementation of Python's tzinfo for constant offsets - there is absolutely no excuse for this not being in the standard library!
class constant_tzinfo(datetime.tzinfo):
def __init__(self, offset_mins): self.offset_mins = offset_mins
def utcoffset(self, dt): return datetime.timedelta(minutes=self.offset_mins)
def dst(self, dt): return None
def tzname(self, dt): return '%+03d:%02d' % (int(self.offset_mins / 60.0), abs(self.offset_mins) % 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment