Skip to content

Commit

Permalink
fix: Improve clarity using timedelta.
Browse files Browse the repository at this point in the history
Signed-off-by: Karthik Bekal Pattathana <[email protected]>
  • Loading branch information
karthikbekalp committed Feb 27, 2025
1 parent 64bae54 commit 7284299
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/deadline/client/ui/widgets/job_timeouts_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,22 @@ def set_enabled(self, enabled: bool):
self.hours_box.setEnabled(enabled)
self.minutes_box.setEnabled(enabled)

def set_timeout(self, seconds: int):
def set_timeout(self, total_seconds: int) -> None:
"""
Sets the timeout value by converting seconds into days, hours, and minutes.
Args:
seconds: Total number of seconds to be distributed across time fields
total_seconds: Total number of seconds to be distributed across time fields
"""
days = seconds // int(timedelta(days=1).total_seconds())
hours = (seconds % int(timedelta(days=1).total_seconds())) // int(
timedelta(hours=1).total_seconds()
)
minutes = (seconds % int(timedelta(hours=1).total_seconds())) // int(
timedelta(minutes=1).total_seconds()
)
td = timedelta(seconds=total_seconds)

days = td.days
# td.seconds stores the seconds if it is less than a day,
# that is, from 0 to 86399. Otherwise, if the number of seconds
# is greater than 86399, timedelta converts this number to days.
hours = td.seconds // (60 * 60)
minutes = (td.seconds // 60) % 60

self.days_box.setValue(days)
self.hours_box.setValue(hours)
self.minutes_box.setValue(minutes)
Expand All @@ -130,10 +132,12 @@ def get_timeout_seconds(self) -> int:
Returns:
int: Total number of seconds represented by the current time values
"""
return (
self.days_box.value() * int(timedelta(days=1).total_seconds())
+ self.hours_box.value() * int(timedelta(hours=1).total_seconds())
+ self.minutes_box.value() * int(timedelta(minutes=1).total_seconds())
return int(
timedelta(
days=self.days_box.value(),
hours=self.hours_box.value(),
minutes=self.minutes_box.value(),
).total_seconds()
)

def update_suffix(self):
Expand Down

0 comments on commit 7284299

Please sign in to comment.