Correcting time string.
This commit is contained in:
+5
-4
@@ -1,6 +1,7 @@
|
|||||||
"""File for Score classes"""
|
"""File for Score classes"""
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
class Score:
|
class Score:
|
||||||
@@ -35,8 +36,9 @@ class Score:
|
|||||||
class ScoreTime(Score):
|
class ScoreTime(Score):
|
||||||
"""Class for a time based 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)
|
super().__init__(user)
|
||||||
|
# store time score as seconds.
|
||||||
self._score: float = score
|
self._score: float = score
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -51,6 +53,5 @@ class ScoreTime(Score):
|
|||||||
|
|
||||||
def get_str(self) -> str:
|
def get_str(self) -> str:
|
||||||
"""Gets score's value as a string. Returns in time format."""
|
"""Gets score's value as a string. Returns in time format."""
|
||||||
minutes: int = self._score / 60
|
milliseconds = round((self.score - int(self.score)) * 10)
|
||||||
seconds: float = self._score % 60
|
return time.strftime(f"%-M:%S.{milliseconds}", time.gmtime(self.score))
|
||||||
return f"{minutes}:{seconds}"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user