mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-05 03:02:56 +00:00
dev day #75
This commit is contained in:
@@ -73,7 +73,7 @@ const PlayerDetailPage: React.FC = () => {
|
||||
<Text><b>Národnost:</b> {translateNationality(data.nationality)}</Text>
|
||||
)}
|
||||
{data.date_of_birth && (
|
||||
<Text><b>Datum narození:</b> {new Date(data.date_of_birth).toLocaleDateString('cs-CZ')}</Text>
|
||||
<Text><b>Datum narození:</b> {new Date(data.date_of_birth).toLocaleDateString('cs-CZ')} — {calculateAge(data.date_of_birth)} let</Text>
|
||||
)}
|
||||
{(data.height || data.weight) && (
|
||||
<Text>
|
||||
@@ -105,4 +105,18 @@ const PlayerDetailPage: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
function calculateAge(iso: string): number | null {
|
||||
try {
|
||||
const d = new Date(iso);
|
||||
if (isNaN(d.getTime())) return null;
|
||||
const today = new Date();
|
||||
let age = today.getFullYear() - d.getFullYear();
|
||||
const m = today.getMonth() - d.getMonth();
|
||||
if (m < 0 || (m === 0 && today.getDate() < d.getDate())) age--;
|
||||
return age;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export default PlayerDetailPage;
|
||||
|
||||
Reference in New Issue
Block a user