Skip to content

Commit 4290b54

Browse files
committed
Added feature to timetools
1 parent 14ba659 commit 4290b54

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

servercom/timetools.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,14 @@ def since_last(self, timeunit: int) -> 'Time':
107107
self.seconds % timeunit,
108108
absolute=False
109109
)
110+
111+
def floor(self, timeunit: int) -> 'Time':
112+
"""Returns a Time object representing the beginning of the most recent
113+
<MINUTE|HOUR|DAY|WEEK|YEAR>"""
114+
return Time(
115+
self.seconds - self.seconds % timeunit,
116+
absolute=False
117+
)
110118

111119
def __add__(self, other: 'Time') -> 'Time':
112120
if not isinstance(other, Time):
@@ -151,8 +159,8 @@ def __div__(self, other) -> 'Time':
151159
)
152160

153161
def __floordiv__(self, other: int) -> int:
154-
if not isinstance(other, int) or self.absolute:
155-
raise TypeError("Floor division is only to be used as Time // TimeUnit (int) to find the number of a unit that fits in a given relative time/time delta")
162+
#if not isinstance(other, int) or self.absolute:
163+
# raise TypeError("Floor division is only to be used as Time // TimeUnit (int) to find the number of a unit that fits in a given relative time/time delta")
156164
return self.seconds // other
157165

158166
def __mod__(self, other: 'Time') -> 'Time':

0 commit comments

Comments
 (0)