Buchungskalender: Preisrechnung und Datumshilfen

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
knsoandClaude Opus 5.5 committed 2026-10-07 13:47:41 +00:00
1 parent 5717a5cdd0
commit 84e7a99f41
3 files changed
+277

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
// Datumshilfen fuer Buchungskalender: reine Funktionen auf Tagesstrings (YYYY-MM-DD), UTC-Arithmetik, keine I/O.
const TAG_RE = /^\d{4}-\d{2}-\d{2}$/
const TAG_MS = 86400000
function zuMs(tag) {
const [j, m, t] = tag.split('-').map(Number)
return Date.UTC(j, m - 1, t)
}
/** Gueltiger Kalendertag im Format YYYY-MM-DD. */
export function istTag(s) {
if (typeof s !== 'string' || !TAG_RE.test(s)) return false
const d = new Date(zuMs(s))
return d.toISOString().slice(0, 10) === s
}
/** Anzahl Naechte zwischen Anreise und Abreise. */
export function naechte(von, bis) {
return Math.round((zuMs(bis) - zuMs(von)) / TAG_MS)
}
/** Tag um n Tage verschoben. */
export function plusTage(tag, n) {
return new Date(zuMs(tag) + n * TAG_MS).toISOString().slice(0, 10)
}
/** Belegte Naechte: von inklusive, bis exklusive. */
export function tageVon(von, bis) {
const n = naechte(von, bis)
const out = []
for (let i = 0; i < n; i++) out.push(plusTage(von, i))
return out
}
/** '2026-11-12' wird '12.11.2026'. */
export function formatTag(tag) {
const [j, m, t] = tag.split('-')
return `${t}.${m}.${j}`
}