calendar: страница с 4 видами, личными событиями и источниками из системы

This commit is contained in:
dev
2026-11-24 11:45:52 +03:00
parent 371e28501f
commit bcd3738694
13 changed files with 1759 additions and 47 deletions
+50
View File
@@ -119,6 +119,56 @@ function isoAddDays(iso, n) {
return d.toISOString().slice(0, 10);
}
function dtTzOffsetMinutes(instant) {
try {
const d = new Date(instant);
const parts = new Intl.DateTimeFormat('en-CA', {
timeZone: DateTime.tz, year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false
}).formatToParts(d);
const get = name => Number(parts.find(p => p.type === name)?.value || 0);
const asUtc = new Date(Date.UTC(get('year'), get('month') - 1, get('day'), get('hour'), get('minute'), get('second')));
return -Math.round((d.getTime() - asUtc.getTime()) / 60000);
} catch { return 0; }
}
function dtToLocalInput(iso) {
if (!iso) return '';
try {
const d = new Date(iso);
const parts = new Intl.DateTimeFormat('en-CA', {
timeZone: DateTime.tz, year: 'numeric', month: '2-digit', day: '2-digit',
hour: '2-digit', minute: '2-digit', hour12: false
}).formatToParts(d);
const get = name => parts.find(p => p.type === name)?.value || '';
return `${get('year')}-${get('month')}-${get('day')}T${get('hour')}:${get('minute')}`;
} catch { return ''; }
}
function dtInputToIso(localDt) {
if (!localDt) return null;
try {
const [datePart, timePart] = String(localDt).split('T');
const [y, mo, d] = datePart.split('-').map(Number);
const [h, mi] = timePart.split(':').map(Number);
const ref = new Date(Date.UTC(y, mo - 1, d, h, mi, 0, 0));
const off = dtTzOffsetMinutes(ref);
return new Date(ref.getTime() - off * 60000).toISOString();
} catch { return null; }
}
function fmtMonthYearIso(iso) {
const p = dtIsoMatch(iso);
if (!p) return '';
try {
return new Intl.DateTimeFormat('ru-RU', { timeZone: DateTime.tz, month: 'long', year: 'numeric' })
.format(new Date(Date.UTC(Number(p.y), Number(p.m) - 1, 1, 12)));
} catch {
const months = ['января', 'февраля', 'марта', 'апреля', 'мая', 'июня', 'июля', 'августа', 'сентября', 'октября', 'ноября', 'декабря'];
return `${months[Number(p.m) - 1] || ''} ${p.y}`;
}
}
function dtApply(s) {
if (!s || typeof s !== 'object') return;
if (dtValidTz(s.timezone)) DateTime.tz = s.timezone;