diff --git a/tournaments/models/tournament.py b/tournaments/models/tournament.py index 11b22a1..e37ddb9 100644 --- a/tournaments/models/tournament.py +++ b/tournaments/models/tournament.py @@ -1150,7 +1150,8 @@ class Tournament(BaseModel): options.append(f"Clôture des inscriptions le {date}") # Période de désinscription - options.append(f"Désinscription possible jusqu'à {self.unregister_delta_in_hours}h avant le tournoi") + formatted_period = self.format_time_period(self.unregister_delta_in_hours) + options.append(f"Désinscription possible jusqu'à {formatted_period} avant le tournoi") options.append(self.get_selection_status_localized) @@ -1193,6 +1194,21 @@ class Tournament(BaseModel): return options + def format_time_period(self, hours): + """ + Format time period in hours to a more readable format. + Examples: + - 24 hours -> "24h" + - 48 hours -> "2 jours" + - 168 hours -> "7 jours" + - 25 hours -> "25h" + """ + if hours % 24 == 0 and hours > 24: + days = hours // 24 + return f"{days} jours" + else: + return f"{hours}h" + def get_selection_status_localized(self): if self.team_sorting == TeamSortingType.RANK: return "La sélection se fait par le poids de l'équipe"