From 01df80d3585eca7a54f2821582bf103da9605b3d Mon Sep 17 00:00:00 2001 From: alwayscompiling Date: Sat, 30 Jul 2022 21:53:29 -0400 Subject: [PATCH] Correcting time string. --- data/score.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/data/score.py b/data/score.py index 92947ad..cd0c043 100644 --- a/data/score.py +++ b/data/score.py @@ -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))