Skip to content

Commit

Permalink
Improve time formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
jake158 committed May 11, 2024
1 parent a730817 commit 58fbbe9
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/logic/richpresence.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,18 @@ def disconnect(self):
self.connected = True
return False

def format_time(self, seconds_studied, round_hours_to=1):
def format_time(self, seconds_studied, float_hours=True):
total_seconds = seconds_studied
total_hours = seconds_studied / 3600
if total_hours < 1:
return f"{total_seconds // 60} minute{'s' if total_seconds // 60 != 1 else ''}"
else:
return f"{round(total_hours, round_hours_to) if total_hours % 1 != 0 else int(total_hours)} hours"
formatted_hours = round(total_hours, 1) if float_hours and total_hours % 1 != 0 else int(total_hours)
return f"{formatted_hours} hour{'s' if formatted_hours != 1 else ''}"

@_handle_exceptions
def idling_state(self, seconds_studied=0):
self.update(state=f"Total time studied: {self.format_time(self.total_seconds_studied + seconds_studied, None)}",
self.update(state=f"Total time studied: {self.format_time(self.total_seconds_studied + seconds_studied, False)}",
details="Idling",
start=self.launch_time,
large_image="graytomato",
Expand Down

0 comments on commit 58fbbe9

Please sign in to comment.