Skip to content

Commit f3d0afc

Browse files
authored
Use divmod (#736)
1 parent 186252a commit f3d0afc

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

pendulum/_helpers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,8 @@ def local_time(
147147
month -= 1
148148

149149
# Handle hours, minutes, seconds and microseconds
150-
hour = seconds // SECS_PER_HOUR
151-
seconds %= SECS_PER_HOUR
152-
minute = seconds // SECS_PER_MIN
153-
second = seconds % SECS_PER_MIN
150+
hour, seconds = divmod(seconds, SECS_PER_HOUR)
151+
minute, second = divmod(seconds, SECS_PER_MIN)
154152

155153
return year, month, day, hour, minute, second, microseconds
156154

pendulum/duration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,12 +500,9 @@ def __new__(
500500
total = abs(self._total)
501501

502502
self._microseconds = round(total % 1 * 1e6)
503-
self._seconds = int(total) % SECONDS_PER_DAY
504-
505-
days = int(total) // SECONDS_PER_DAY
503+
days, self._seconds = divmod(int(total), SECONDS_PER_DAY)
506504
self._days = abs(days + years * 365 + months * 30)
507-
self._remaining_days = days % 7
508-
self._weeks = days // 7
505+
self._weeks, self._remaining_days = divmod(days, 7)
509506
self._months = abs(months)
510507
self._years = abs(years)
511508

0 commit comments

Comments
 (0)