Files
Mitgliederverwaltung/.plans/open/issue-205-date-calculations-duplicated-frontend.md
T
shahondin1624 b29a268b1d Restructure .plans/ into done/ and open/ subdirectories
- Move completed plan files to .plans/done/
- Move 18 open plan files to .plans/open/
- Update .gitignore to exclude .verified_plans temp file
- Verified all 18 open plans still describe unimplemented issues
2026-04-28 20:30:55 +02:00

1.7 KiB

Issue #205: Date Calculations Duplicated in Frontend

Problem

The MemberList.vue component contains duplicate date calculation logic for alter (age) and mitgliedsdauer (membership duration) that also exists in the backend MemberService:

Backend (lib/Service/MemberService.php):

private function calculateMitgliedsdauer(Member $member): string {
    $eintritt = new DateTime($member->getEintritt());
    $end = $member->getAustritt()
        ? new DateTime($member->getAustritt())
        : new DateTime();
    $diff = $eintritt->diff($end);
    // ...
}

Frontend (src/views/MemberList.vue):

function calculateAge(geburtsdatum) {
    const birth = new Date(geburtsdatum)
    const today = new Date()
    let age = today.getFullYear() - birth.getFullYear()
    // ...
}

function calculateMitgliedsdauer(eintritt) {
    const start = new Date(eintritt)
    const today = new Date()
    // ...
}

Impact

  • Inconsistent calculations if date logic changes
  • Maintenance burden (two places to update)
  • Potential for bugs if frontend and backend diverge

Solution

  1. Option A (Recommended): Calculate alter and mitgliedsdauer in the backend and include them in the API response
  2. Option B: Extract to a shared utility in a format both can use (e.g., precompute in migration, or use a build-time code generator)

Tasks

  • Add alter and mitgliedsdauer to Member::jsonSerialize()
  • Update MemberService::buildMemberResponse() to compute these values
  • Remove duplicate calculations from MemberList.vue
  • Verify frontend displays match backend calculations
  • Update any other views using these calculations

Labels

  • refactoring
  • frontend
  • backend
  • priority:medium