syncova-ticket/server/time.js
Weapie 9c561cb574
All checks were successful
Tests und Docker-Image / Tests und Frontend-Build (push) Successful in 2m8s
Tests und Docker-Image / Leeres Produktionsimage bauen und veröffentlichen (push) Successful in 4m28s
Add Syncova Ticket with tested Gitea image publishing and persistent Compose deployment
2026-11-03 17:04:00 +01:00

31 lines
1.1 KiB
JavaScript

// Resolve a wall-clock timestamp in an IANA zone, rejecting DST gaps.
export function scheduledTime(value, zone) {
if (!zone || typeof value !== 'string') throw Error('Termin und Zeitzone fehlen')
const fmt = new Intl.DateTimeFormat('sv-SE', {
timeZone: zone,
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
hourCycle: 'h23',
})
if (/[zZ]$|[+-]\d{2}:\d{2}$/.test(value)) {
const d = new Date(value)
if (!Number.isFinite(+d)) throw Error('Ungültiger Termin')
return d.toISOString()
}
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/.test(value)) throw Error('Ungültiger Termin')
const target = value.length === 16 ? value + ':00' : value
const utc = Date.parse(target + 'Z')
let guess = utc
for (let i = 0; i < 4; i++) {
const wall = fmt.format(new Date(guess)).replace(' ', 'T')
const delta = utc - Date.parse(wall + 'Z')
if (!delta) return new Date(guess).toISOString()
guess += delta
}
throw Error('Die Uhrzeit existiert in dieser Zeitzone nicht (Sommerzeitwechsel).')
}