Created
May 5, 2020 16:01
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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