DevTools: Moseszeit-Umrechnung korrigiert (Unix UTC + Jahr+3 Versatz)
This commit is contained in:
@@ -478,10 +478,31 @@ function ElektroRechner({ mobile }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ─────────────────────────────────────────────────────────────── Datetime ──
|
// ─────────────────────────────────────────────────────────────── Datetime ──
|
||||||
const MOSES_EPOCH = new Date('1970-01-01T00:00:00Z'); // Moseszeit = Unix time (Sekunden)
|
// Moseszeit: Unix-Timestamp (Sekunden), aber Jahreszahl wird um +3 Jahre versetzt angezeigt.
|
||||||
|
// Beispiel: 1685560872 → Unix=2023-05-31 19:21:12 UTC → Moses-Anzeige=2026-05-31 19:21:12
|
||||||
|
// Umkehrung: Moses-Jahr -3 → Unix-Jahr → Timestamp berechnen.
|
||||||
|
const MOSES_YEAR_OFFSET = 3;
|
||||||
|
|
||||||
function pad2(n){ return String(n).padStart(2,'0'); }
|
function pad2(n){ return String(n).padStart(2,'0'); }
|
||||||
|
|
||||||
|
// Aus Unix-Timestamp (ms) ein Anzeige-Objekt für Moseszeit bauen (UTC + Jahr+3)
|
||||||
|
function mosesDisplayFromUnixMs(ms) {
|
||||||
|
const d = new Date(ms);
|
||||||
|
const y = d.getUTCFullYear() + MOSES_YEAR_OFFSET;
|
||||||
|
const mo= pad2(d.getUTCMonth()+1);
|
||||||
|
const day=pad2(d.getUTCDate());
|
||||||
|
const h = pad2(d.getUTCHours());
|
||||||
|
const mi= pad2(d.getUTCMinutes());
|
||||||
|
const s = pad2(d.getUTCSeconds());
|
||||||
|
return { de: `${day}.${mo}.${y} ${h}:${mi}:${s}`, iso: `${y}-${mo}-${day}T${h}:${mi}:${s}` };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aus Moses-Sekunden → Unix-Timestamp in ms (einfach *1000, Jahr-Versatz ist nur Anzeige)
|
||||||
|
function mosesToUnixMs(mosesTs) {
|
||||||
|
return mosesTs * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Aus lokalem datetime-local Input (local time) ein Date-Objekt
|
||||||
function toLocalISO(d){
|
function toLocalISO(d){
|
||||||
return `${d.getFullYear()}-${pad2(d.getMonth()+1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
return `${d.getFullYear()}-${pad2(d.getMonth()+1)}-${pad2(d.getDate())}T${pad2(d.getHours())}:${pad2(d.getMinutes())}:${pad2(d.getSeconds())}`;
|
||||||
}
|
}
|
||||||
@@ -510,25 +531,38 @@ function DatetimeRechner({ mobile }) {
|
|||||||
function convFromUnix(val) {
|
function convFromUnix(val) {
|
||||||
const n = parseInt(val);
|
const n = parseInt(val);
|
||||||
if (isNaN(n)) { setConvResult(null); return; }
|
if (isNaN(n)) { setConvResult(null); return; }
|
||||||
const d = new Date(n * 1000);
|
const unixMs = mosesToUnixMs(n);
|
||||||
|
const d = new Date(unixMs);
|
||||||
|
const moses = mosesDisplayFromUnixMs(unixMs);
|
||||||
|
const dLocal = new Date(n * 1000); // for weekday (UTC)
|
||||||
setConvResult({
|
setConvResult({
|
||||||
de: formatDE(d),
|
de: moses.de,
|
||||||
local: toLocalISO(d),
|
local: moses.iso,
|
||||||
unix: String(n),
|
unix: String(n),
|
||||||
wday: WEEKDAYS[d.getDay()],
|
wday: WEEKDAYS[d.getUTCDay()],
|
||||||
kw: getKW(d),
|
kw: getKW(d),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function convFromLocal(val) {
|
function convFromLocal(val) {
|
||||||
|
// val is in format YYYY-MM-DDTHH:MM:SS from datetime-local (local browser time)
|
||||||
|
// For Moses: treat it as UTC (since Moses timestamps are UTC-based + year offset)
|
||||||
if (!val) { setConvResult(null); return; }
|
if (!val) { setConvResult(null); return; }
|
||||||
const d = new Date(val);
|
// Parse the value: year shown is Moses year, so subtract 3 for real UTC year
|
||||||
|
const [datePart, timePart] = val.split('T');
|
||||||
|
if (!datePart || !timePart) { setConvResult(null); return; }
|
||||||
|
const [y, mo, day] = datePart.split('-').map(Number);
|
||||||
|
const [h, mi, s] = timePart.split(':').map(Number);
|
||||||
|
const realYear = y - MOSES_YEAR_OFFSET;
|
||||||
|
const d = new Date(Date.UTC(realYear, mo-1, day, h, mi, s||0));
|
||||||
if (isNaN(d)) { setConvResult(null); return; }
|
if (isNaN(d)) { setConvResult(null); return; }
|
||||||
|
const unixSec = Math.floor(d.getTime() / 1000);
|
||||||
|
const moses = mosesDisplayFromUnixMs(d.getTime());
|
||||||
setConvResult({
|
setConvResult({
|
||||||
de: formatDE(d),
|
de: moses.de,
|
||||||
local: toLocalISO(d),
|
local: val,
|
||||||
unix: String(Math.floor(d.getTime()/1000)),
|
unix: String(unixSec),
|
||||||
wday: WEEKDAYS[d.getDay()],
|
wday: WEEKDAYS[d.getUTCDay()],
|
||||||
kw: getKW(d),
|
kw: getKW(d),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -620,7 +654,13 @@ function DatetimeRechner({ mobile }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button style={{...S.btn('#4ecdc4',false), fontSize:11, padding:'6px 14px', marginBottom:16}}
|
<button style={{...S.btn('#4ecdc4',false), fontSize:11, padding:'6px 14px', marginBottom:16}}
|
||||||
onClick={()=>{ const d=new Date(); const v=String(Math.floor(d.getTime()/1000)); setConv({unix:v,local:toLocalISO(d),de:''}); convFromUnix(v); }}>
|
onClick={()=>{
|
||||||
|
const d = new Date();
|
||||||
|
const unixSec = Math.floor(d.getTime()/1000);
|
||||||
|
const moses = mosesDisplayFromUnixMs(d.getTime());
|
||||||
|
setConv({unix:String(unixSec), local:moses.iso, de:''});
|
||||||
|
convFromUnix(String(unixSec));
|
||||||
|
}}>
|
||||||
Jetzt verwenden
|
Jetzt verwenden
|
||||||
</button>
|
</button>
|
||||||
{convResult && (
|
{convResult && (
|
||||||
@@ -642,6 +682,7 @@ function DatetimeRechner({ mobile }) {
|
|||||||
<div style={{color:'rgba(255,255,255,0.45)',fontFamily:'monospace',fontSize:9,marginBottom:6}}>BEISPIEL</div>
|
<div style={{color:'rgba(255,255,255,0.45)',fontFamily:'monospace',fontSize:9,marginBottom:6}}>BEISPIEL</div>
|
||||||
<div style={{color:'rgba(255,255,255,0.6)',fontFamily:'monospace',fontSize:11}}>
|
<div style={{color:'rgba(255,255,255,0.6)',fontFamily:'monospace',fontSize:11}}>
|
||||||
Moseszeit <code style={{color:'#4ecdc4'}}>1685554093</code> = <code style={{color:'#4ecdc4'}}>31.05.2026 17:28:13</code>
|
Moseszeit <code style={{color:'#4ecdc4'}}>1685554093</code> = <code style={{color:'#4ecdc4'}}>31.05.2026 17:28:13</code>
|
||||||
|
<span style={{color:'rgba(255,255,255,0.4)',fontSize:10,marginLeft:8}}>(UTC, Jahr+3 Versatz)</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user