You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
2.7 KiB
144 lines
2.7 KiB
from functools import cached_property
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
class Doba(float):
|
|
DEN: float = 24
|
|
TYDEN: float = DEN * 7
|
|
|
|
@cached_property
|
|
def den(self) -> int:
|
|
return int(self // 24) + 1
|
|
|
|
@cached_property
|
|
def cas(self) -> float:
|
|
return self % 24
|
|
|
|
@cached_property
|
|
def je_noc(self) -> bool:
|
|
return self.cas < settings.DEN[0] or self.cas > settings.DEN[1]
|
|
|
|
@cached_property
|
|
def den_v_tydnu(self) -> int:
|
|
return (self.den - settings.PRVNI_PONDELI) % 7 + 1
|
|
|
|
@cached_property
|
|
def den_mesice(self) -> int:
|
|
return (self.den - settings.PRVNI_NOV) % 28
|
|
|
|
@property
|
|
def je_nov(self):
|
|
return self.den_mesice == 0
|
|
|
|
@property
|
|
def je_uplnek(self):
|
|
return self.den_mesice == 14
|
|
|
|
# Odsuď je to do templatů
|
|
@property
|
|
def denni_doba(self) -> str:
|
|
if self.je_noc:
|
|
if self.den_mesice == 0:
|
|
return "🌑"
|
|
elif self.den_mesice <= 6:
|
|
return "🌒"
|
|
elif self.den_mesice == 7:
|
|
return "🌓"
|
|
elif self.den_mesice <= 13:
|
|
return "🌔"
|
|
elif self.den_mesice == 14:
|
|
return "🌕"
|
|
elif self.den_mesice <= 20:
|
|
return "🌖"
|
|
elif self.den_mesice == 21:
|
|
return "🌗"
|
|
else:
|
|
return "🌘"
|
|
else:
|
|
return "☀️"
|
|
|
|
@property
|
|
def den_v_tydnu_zkratka(self) -> str:
|
|
return [
|
|
# 0:
|
|
None,
|
|
# 1:
|
|
"Po",
|
|
# 2:
|
|
"Út",
|
|
# 3:
|
|
"St",
|
|
# 4:
|
|
"Čt",
|
|
# 5:
|
|
"Pá",
|
|
# 6:
|
|
"So",
|
|
# 7:
|
|
"Ne",
|
|
][self.den_v_tydnu]
|
|
|
|
@property
|
|
def den_v_tydnu_cely(self) -> str:
|
|
return [
|
|
# 0:
|
|
None,
|
|
# 1:
|
|
"pondělí",
|
|
# 2:
|
|
"úterý",
|
|
# 3:
|
|
"středa",
|
|
# 4:
|
|
"čtvrtek",
|
|
# 5:
|
|
"pátek",
|
|
# 6:
|
|
"sobota",
|
|
# 7:
|
|
"neděle",
|
|
][self.den_v_tydnu]
|
|
|
|
@property
|
|
def hodina(self) -> int:
|
|
return int(self.cas)
|
|
|
|
@property
|
|
def minuta(self) -> int:
|
|
return int(self.cas % 1 * 60)
|
|
|
|
@property
|
|
def hodiny_minuty(self) -> str:
|
|
return f"{self.hodina}:{self.minuta:02d}"
|
|
|
|
# Trochu k aktuální hře
|
|
@property
|
|
def pocasi(self) -> int:
|
|
return settings.POCASI[self.den % len(settings.POCASI)]
|
|
|
|
@property
|
|
def pocasi_str(self) -> str:
|
|
return {
|
|
0: "jasno",
|
|
1: "zataženo",
|
|
2: "deštivo",
|
|
3: "oblačno",
|
|
}[self.pocasi]
|
|
|
|
@property
|
|
def pocasi_text(self) -> str:
|
|
dni = [Doba(self + i*Doba.DEN) for i in range(7)]
|
|
return (
|
|
f"Jo a dnes má být celou dobu {dni[0].pocasi_str}. "
|
|
f"Zítra pak {dni[1].pocasi_str}. "
|
|
f"Pozítří nás čeká {dni[2].pocasi_str}. "
|
|
f"Pak nás čeká {dni[3].den_v_tydnu_cely}, a to bude pořád {dni[3].pocasi_str}. "
|
|
f"Další den můžeme očekávat {dni[4].pocasi_str}. "
|
|
f"Pak {dni[5].pocasi_str}. "
|
|
f"Nakonec {dni[6].pocasi_str}. "
|
|
f"A {dni[6].den_v_tydnu_cely} přinese {dni[6].pocasi_str}."
|
|
)
|
|
|
|
def __add__(self, other):
|
|
return Doba(super().__add__(other))
|
|
|