Correcting time string.

This commit is contained in:
alwayscompiling
2022-07-30 21:53:29 -04:00
parent 06248cfe6c
commit 01df80d358
+5 -4
View File
@@ -1,6 +1,7 @@
"""File for Score classes"""
from typing import Optional
import time
class Score:
@@ -35,8 +36,9 @@ class Score:
class ScoreTime(Score):
"""Class for a time based score."""
def __init__(self, user: str, score: float) -> None:
def __init__(self, user: str, score: Optional[float] = -1) -> None:
super().__init__(user)
# store time score as seconds.
self._score: float = score
@property
@@ -51,6 +53,5 @@ class ScoreTime(Score):
def get_str(self) -> str:
"""Gets score's value as a string. Returns in time format."""
minutes: int = self._score / 60
seconds: float = self._score % 60
return f"{minutes}:{seconds}"
milliseconds = round((self.score - int(self.score)) * 10)
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(self.score))