Add method to format time period for tournament description

apikeys
Razmig Sarkissian 4 months ago
parent 2670369a2b
commit 2a7736c044
  1. 18
      tournaments/models/tournament.py

@ -1150,7 +1150,8 @@ class Tournament(BaseModel):
options.append(f"Clôture des inscriptions le {date}") options.append(f"Clôture des inscriptions le {date}")
# Période de désinscription # 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) options.append(self.get_selection_status_localized)
@ -1193,6 +1194,21 @@ class Tournament(BaseModel):
return options 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): def get_selection_status_localized(self):
if self.team_sorting == TeamSortingType.RANK: if self.team_sorting == TeamSortingType.RANK:
return "La sélection se fait par le poids de l'équipe" return "La sélection se fait par le poids de l'équipe"

Loading…
Cancel
Save