Skip to content

Instantly share code, notes, and snippets.

@mscheper
mscheper / datetime_modulo.py
Last active July 29, 2024 15:27 — forked from treyhunner/datetime_modulo.py
Python modulo support for datetime
import datetime as dt
class datetime(dt.datetime):
"""The standard datetime class with the added support for the % and //
operators.
Refer to https://gist.github.com/treyhunner/6218526
"""
def __divmod__(self, delta):
seconds = int((self - dt.datetime.min.replace(tzinfo = self.tzinfo)).total_seconds())