diff --git a/frontend/app/globals.css b/frontend/app/globals.css index 67f57d2..2448dbc 100644 --- a/frontend/app/globals.css +++ b/frontend/app/globals.css @@ -180,11 +180,11 @@ body { padding: var(--space-lg) var(--space-md) var(--space-md); } -.feed-header p, +/*.feed-header p, .explore-header p { color: var(--color-text-secondary); margin: 0.25rem 0 0; -} +}*/ .post-list { display: flex; flex-direction: column; diff --git a/frontend/app/lib/petAge.ts b/frontend/app/lib/petAge.ts new file mode 100644 index 0000000..32a35b8 --- /dev/null +++ b/frontend/app/lib/petAge.ts @@ -0,0 +1,34 @@ +export function calculatePetAge(birthDate: string) { + const today = new Date(); + const birth = new Date(birthDate); + + let age = today.getFullYear() - birth.getFullYear(); + const hasHadBirthdayThisYear = + today.getMonth() > birth.getMonth() || + (today.getMonth() === birth.getMonth() && + today.getDate() >= birth.getDate()); + + if (!hasHadBirthdayThisYear) { + age -= 1; + } + + return age < 0 ? 0 : age; +} + +export function isBirthdayToday(birthDate: string) { + const today = new Date(); + const birth = new Date(birthDate); + + return ( + today.getDate() === birth.getDate() && + today.getMonth() === birth.getMonth() + ); +} + +export function formatPetAge(birthDate: string) { + const age = calculatePetAge(birthDate); + + if (age === 0) return 'unter 1 Jahr'; + if (age === 1) return '1 Jahr'; + return `${age} Jahre`; +} diff --git a/frontend/app/pets/[id]/page.tsx b/frontend/app/pets/[id]/page.tsx index 1b9bc50..fdb7512 100644 --- a/frontend/app/pets/[id]/page.tsx +++ b/frontend/app/pets/[id]/page.tsx @@ -2,6 +2,9 @@ import { useParams } from 'next/navigation'; import PostCard from '@/app/components/PostCard/PostCard'; +import {calculatePetAge, formatPetAge, isBirthdayToday,} from '@/app/lib/petAge'; + + type Pet = { id: number; @@ -94,9 +97,10 @@ export default function PetDetailPage() {
- Lege ein neues Haustier für dein Profil an. -
+Lege ein neues Tier für dein Profil an.