diff --git a/frontend/src/tools/devtools.jsx b/frontend/src/tools/devtools.jsx index 5832534..515b5b6 100644 --- a/frontend/src/tools/devtools.jsx +++ b/frontend/src/tools/devtools.jsx @@ -585,69 +585,49 @@ function DatetimeRechner({ mobile }) { // ── Tab 2: Geburtstag ── const [bday, setBday] = useState(''); - const [bdayTime, setBdayTime] = useState(''); const [bdayResult, setBdayResult] = useState(null); - function calcBday(date, time) { - const dateVal = date ?? bday; - const timeVal = time ?? bdayTime; - setBday(dateVal); - setBdayTime(timeVal); - if (!dateVal) { setBdayResult(null); return; } - // Build birth datetime: if time given use it, else midnight - const birthStr = timeVal ? `${dateVal}T${timeVal}:00` : `${dateVal}T00:00:00`; - const birth = new Date(birthStr); + function calcBday(val) { + setBday(val); + if (!val) { setBdayResult(null); return; } + const birth = new Date(val); if (isNaN(birth)) { setBdayResult(null); return; } - const hasTime = !!timeVal; const today = new Date(); - - // Age in years let ageY = today.getFullYear() - birth.getFullYear(); let ageM = today.getMonth() - birth.getMonth(); let ageD = today.getDate() - birth.getDate(); if (ageD < 0) { ageM--; const prev = new Date(today.getFullYear(), today.getMonth(), 0); ageD += prev.getDate(); } if (ageM < 0) { ageY--; ageM += 12; } - // Hours and minutes since last birthday (only if time entered) - let ageH = null, ageMi = null; - if (hasTime) { - ageH = today.getHours() - birth.getHours(); - ageMi = today.getMinutes() - birth.getMinutes(); - if (ageMi < 0) { ageH--; ageMi += 60; } - if (ageH < 0) { ageD--; ageH += 24; - if (ageD < 0) { ageM--; const prev = new Date(today.getFullYear(), today.getMonth(), 0); ageD += prev.getDate(); - if (ageM < 0) { ageY--; ageM += 12; } } } - } - - // Next birthday - const nextBday = new Date(today.getFullYear(), birth.getMonth(), birth.getDate(), - hasTime ? birth.getHours() : 0, hasTime ? birth.getMinutes() : 0, 0); + const nextBday = new Date(today.getFullYear(), birth.getMonth(), birth.getDate()); if (nextBday <= today) nextBday.setFullYear(today.getFullYear()+1); const diffMs = nextBday - today; const diffD = (diffMs / 86400000).toFixed(1); - const totalMs = today - birth; - const totalD = (totalMs / 86400000).toFixed(1); + const totalD = ((today - birth) / 86400000).toFixed(1); - // Age string - let ageStr = `${ageY} Jahre, ${ageM} Monate, ${ageD} Tage`; - if (hasTime && ageH !== null) ageStr += `, ${ageH} Std. ${pad2(ageMi)} Min.`; - - setBdayResult({ ageStr, diffD, totalD, + setBdayResult({ + ageStr: `${ageY} Jahre, ${ageM} Monate, ${ageD} Tage`, + diffD, totalD, wday: WEEKDAYS[birth.getDay()], - geburtstag: `${pad2(birth.getDate())}.${pad2(birth.getMonth()+1)}.${birth.getFullYear()}${hasTime?' '+timeVal:''}`, + geburtstag: `${pad2(birth.getDate())}.${pad2(birth.getMonth()+1)}.${birth.getFullYear()}`, nextDate: `${pad2(nextBday.getDate())}.${pad2(nextBday.getMonth()+1)}.${nextBday.getFullYear()} (${WEEKDAYS[nextBday.getDay()]})`, }); } // ── Tab 3: Zeitdifferenz ── const [dtA, setDtA] = useState(''); + const [dtATime, setDtATime] = useState(''); const [dtB, setDtB] = useState(''); + const [dtBTime, setDtBTime] = useState(''); const [diffResult, setDiffResult] = useState(null); - function calcDiff(a, b) { + function calcDiff(a, aTime, b, bTime) { if (!a || !b) { setDiffResult(null); return; } - const dA = new Date(a), dB = new Date(b); + const strA = aTime ? `${a}T${aTime}:00` : `${a}T00:00:00`; + const strB = bTime ? `${b}T${bTime}:00` : `${b}T00:00:00`; + const dA = new Date(strA), dB = new Date(strB); if (isNaN(dA)||isNaN(dB)) { setDiffResult(null); return; } + const hasTime = !!(aTime || bTime); const ms = Math.abs(dB - dA); const s = (ms / 1000).toFixed(1); const m = (ms / 60000).toFixed(1); @@ -656,7 +636,7 @@ function DatetimeRechner({ mobile }) { const weeks = (ms / (86400000*7)).toFixed(2); const dA2 = new Date(Math.min(dA,dB)), dB2 = new Date(Math.max(dA,dB)); const months = Math.abs(dB2.getMonth()-dA2.getMonth() + (dB2.getFullYear()-dA2.getFullYear())*12); - setDiffResult({ ms, s, m, h, d, weeks, months }); + setDiffResult({ ms, s, m, h, d, weeks, months, hasTime }); } const inp = { ...S.inp, fontSize:13, padding:'7px 9px', width:'100%', boxSizing:'border-box' }; @@ -731,16 +711,11 @@ function DatetimeRechner({ mobile }) {