Compare commits
31 Commits
7c31ee3327
...
v1.3.0
| Author | SHA1 | Date | |
|---|---|---|---|
| 120b61a423 | |||
| 074f0600af | |||
| e4f9407827 | |||
| fde5ce7dc1 | |||
| 20df10b333 | |||
| c906511bfc | |||
| 745e5920ad | |||
| 90e0a98914 | |||
| cba4b73798 | |||
| 0d567472a9 | |||
| 9f6b2ece52 | |||
| e3911157e9 | |||
| 0589288dfe | |||
| 8ead7687e5 | |||
| 0e1e9b6699 | |||
| 3c008c5bce | |||
| 1582c28b28 | |||
| bcd934f5b1 | |||
| 4c9acd20c7 | |||
| 520fb98d96 | |||
| 800184d2be | |||
| 82c314f85c | |||
| 2fba532ec7 | |||
| 9177578aaf | |||
| 94c4a0af51 | |||
| ec60d53767 | |||
| ad81d7ace7 | |||
| badd542bd7 | |||
| cd16b7ea28 | |||
| afbdefa549 | |||
| f1e192c5d4 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,5 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
js/version.js
|
|
||||||
data/*.db
|
data/*.db
|
||||||
data/*.db-shm
|
data/*.db-shm
|
||||||
data/*.db-wal
|
data/*.db-wal
|
||||||
|
|||||||
57
css/app.css
57
css/app.css
@@ -25,6 +25,10 @@
|
|||||||
--mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
|
--mono: 'JetBrains Mono', 'IBM Plex Mono', monospace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
html {
|
||||||
|
zoom: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
html, body {
|
html, body {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background: var(--bg);
|
background: var(--bg);
|
||||||
@@ -374,16 +378,25 @@ select:focus { border-color: var(--accent); }
|
|||||||
}
|
}
|
||||||
|
|
||||||
.detail-sub {
|
.detail-sub {
|
||||||
font-size: 12px;
|
font-size: 13px;
|
||||||
color: var(--text3);
|
margin-top: 8px;
|
||||||
margin-top: 6px;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 16px;
|
align-items: center;
|
||||||
|
gap: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.detail-sub span { display: flex; gap: 4px; }
|
.detail-sub > span {
|
||||||
.detail-sub .lbl { color: var(--text3); }
|
display: flex;
|
||||||
.detail-sub .val { color: var(--text2); }
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
.detail-sub > span + span {
|
||||||
|
margin-left: 12px;
|
||||||
|
padding-left: 12px;
|
||||||
|
border-left: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
.detail-sub .lbl { color: var(--text3); font-size: 11px; }
|
||||||
|
.detail-sub .val { color: var(--text); }
|
||||||
|
|
||||||
.detail-actions { display: flex; gap: 8px; }
|
.detail-actions { display: flex; gap: 8px; }
|
||||||
|
|
||||||
@@ -630,26 +643,25 @@ select:focus { border-color: var(--accent); }
|
|||||||
|
|
||||||
/* ── HISTORY TIMELINE ── */
|
/* ── HISTORY TIMELINE ── */
|
||||||
.tl-item {
|
.tl-item {
|
||||||
display: grid;
|
display: flex;
|
||||||
grid-template-columns: 160px 140px 1fr;
|
align-items: center;
|
||||||
gap: 0 12px;
|
justify-content: space-between;
|
||||||
padding: 7px 0;
|
gap: 24px;
|
||||||
|
padding: 9px 0;
|
||||||
border-bottom: 1px solid var(--border);
|
border-bottom: 1px solid var(--border);
|
||||||
font-size: 12px;
|
|
||||||
align-items: baseline;
|
|
||||||
}
|
}
|
||||||
.tl-item:last-child { border-bottom: none; }
|
.tl-item:last-child { border-bottom: none; }
|
||||||
.tl-time { color: var(--text3); font-size: 11px; white-space: nowrap; }
|
.tl-event { display: flex; align-items: center; gap: 7px; font-size: 13px; min-width: 0; }
|
||||||
.tl-field { color: var(--text2); }
|
.tl-label { color: var(--text2); }
|
||||||
.tl-change { display: flex; align-items: baseline; gap: 6px; }
|
.tl-sep { color: var(--text3); user-select: none; }
|
||||||
.tl-old { color: var(--text3); text-decoration: line-through; }
|
.tl-old { color: var(--text3); text-decoration: line-through; font-size: 12px; }
|
||||||
.tl-arrow { color: var(--text3); }
|
.tl-arrow { color: var(--text3); font-size: 11px; }
|
||||||
.tl-new { color: var(--text); }
|
.tl-new { color: var(--text); font-weight: 500; }
|
||||||
|
.tl-time { color: var(--text3); font-size: 11px; white-space: nowrap; flex-shrink: 0; }
|
||||||
.tl-deployed { color: var(--accent); }
|
.tl-deployed { color: var(--accent); }
|
||||||
.tl-testing { color: var(--amber); }
|
.tl-testing { color: var(--amber); }
|
||||||
.tl-degraded { color: var(--red); }
|
.tl-degraded { color: var(--red); }
|
||||||
.tl-created .tl-field { color: var(--accent); }
|
.tl-created .tl-event { color: var(--accent); font-weight: 500; }
|
||||||
.tl-created .tl-change { color: var(--text3); }
|
|
||||||
.tl-empty { color: var(--text3); font-size: 12px; padding: 8px 0; }
|
.tl-empty { color: var(--text3); font-size: 12px; padding: 8px 0; }
|
||||||
|
|
||||||
/* ── SETTINGS MODAL ── */
|
/* ── SETTINGS MODAL ── */
|
||||||
@@ -665,6 +677,9 @@ select:focus { border-color: var(--accent); }
|
|||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
.settings-desc { font-size: 12px; color: var(--text2); margin: 0 0 14px; line-height: 1.6; }
|
.settings-desc { font-size: 12px; color: var(--text2); margin: 0 0 14px; line-height: 1.6; }
|
||||||
|
.settings-row { display: flex; align-items: center; gap: 12px; }
|
||||||
|
.settings-label { font-size: 13px; color: var(--text2); white-space: nowrap; min-width: 80px; }
|
||||||
|
.settings-select { flex: 1; }
|
||||||
.import-row { display: flex; gap: 10px; align-items: center; }
|
.import-row { display: flex; gap: 10px; align-items: center; }
|
||||||
.import-file-input { flex: 1; }
|
.import-file-input { flex: 1; }
|
||||||
|
|
||||||
|
|||||||
@@ -180,6 +180,13 @@
|
|||||||
<button class="modal-close" onclick="closeSettingsModal()">✕</button>
|
<button class="modal-close" onclick="closeSettingsModal()">✕</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
<div class="settings-section">
|
||||||
|
<div class="settings-section-title">Display</div>
|
||||||
|
<div class="settings-row">
|
||||||
|
<label class="settings-label" for="tz-select">Timezone</label>
|
||||||
|
<select id="tz-select" class="form-input settings-select"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="settings-section">
|
<div class="settings-section">
|
||||||
<div class="settings-section-title">Export</div>
|
<div class="settings-section-title">Export</div>
|
||||||
<p class="settings-desc">Download all instance data as a JSON backup file.</p>
|
<p class="settings-desc">Download all instance data as a JSON backup file.</p>
|
||||||
|
|||||||
95
js/ui.js
95
js/ui.js
@@ -3,6 +3,34 @@ let editingVmid = null;
|
|||||||
let currentVmid = null;
|
let currentVmid = null;
|
||||||
let toastTimer = null;
|
let toastTimer = null;
|
||||||
|
|
||||||
|
// ── Timezone ──────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
const TIMEZONES = [
|
||||||
|
{ label: 'UTC', tz: 'UTC' },
|
||||||
|
{ label: 'Hawaii (HST)', tz: 'Pacific/Honolulu' },
|
||||||
|
{ label: 'Alaska (AKT)', tz: 'America/Anchorage' },
|
||||||
|
{ label: 'Pacific (PT)', tz: 'America/Los_Angeles' },
|
||||||
|
{ label: 'Mountain (MT)', tz: 'America/Denver' },
|
||||||
|
{ label: 'Central (CT)', tz: 'America/Chicago' },
|
||||||
|
{ label: 'Eastern (ET)', tz: 'America/New_York' },
|
||||||
|
{ label: 'Atlantic (AT)', tz: 'America/Halifax' },
|
||||||
|
{ label: 'London (GMT/BST)', tz: 'Europe/London' },
|
||||||
|
{ label: 'Paris / Berlin (CET)', tz: 'Europe/Paris' },
|
||||||
|
{ label: 'Helsinki (EET)', tz: 'Europe/Helsinki' },
|
||||||
|
{ label: 'Istanbul (TRT)', tz: 'Europe/Istanbul' },
|
||||||
|
{ label: 'Dubai (GST)', tz: 'Asia/Dubai' },
|
||||||
|
{ label: 'India (IST)', tz: 'Asia/Kolkata' },
|
||||||
|
{ label: 'Singapore (SGT)', tz: 'Asia/Singapore' },
|
||||||
|
{ label: 'China (CST)', tz: 'Asia/Shanghai' },
|
||||||
|
{ label: 'Japan / Korea (JST/KST)', tz: 'Asia/Tokyo' },
|
||||||
|
{ label: 'Sydney (AEST)', tz: 'Australia/Sydney' },
|
||||||
|
{ label: 'Auckland (NZST)', tz: 'Pacific/Auckland' },
|
||||||
|
];
|
||||||
|
|
||||||
|
function getTimezone() {
|
||||||
|
return localStorage.getItem('catalyst_tz') || 'UTC';
|
||||||
|
}
|
||||||
|
|
||||||
// ── Helpers ───────────────────────────────────────────────────────────────────
|
// ── Helpers ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function esc(str) {
|
function esc(str) {
|
||||||
@@ -11,17 +39,25 @@ function esc(str) {
|
|||||||
return d.innerHTML;
|
return d.innerHTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQLite datetime('now') → 'YYYY-MM-DD HH:MM:SS' (UTC, no timezone marker).
|
||||||
|
// Appending 'Z' tells JS to parse it as UTC rather than local time.
|
||||||
|
function parseUtc(d) {
|
||||||
|
if (typeof d !== 'string') return new Date(d);
|
||||||
|
const hasZone = d.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(d);
|
||||||
|
return new Date(hasZone ? d : d.replace(' ', 'T') + 'Z');
|
||||||
|
}
|
||||||
|
|
||||||
function fmtDate(d) {
|
function fmtDate(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '—';
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
|
return parseUtc(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: getTimezone() });
|
||||||
} catch (e) { return d; }
|
} catch (e) { return d; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function fmtDateFull(d) {
|
function fmtDateFull(d) {
|
||||||
if (!d) return '—';
|
if (!d) return '—';
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' });
|
return parseUtc(d).toLocaleString('en-US', { year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZone: getTimezone(), timeZoneName: 'short' });
|
||||||
} catch (e) { return d; }
|
} catch (e) { return d; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,6 +137,21 @@ async function filterInstances() {
|
|||||||
|
|
||||||
const BOOL_FIELDS = ['atlas','argus','semaphore','patchmon','tailscale','andromeda','hardware_acceleration'];
|
const BOOL_FIELDS = ['atlas','argus','semaphore','patchmon','tailscale','andromeda','hardware_acceleration'];
|
||||||
|
|
||||||
|
const FIELD_LABELS = {
|
||||||
|
name: 'name',
|
||||||
|
state: 'state',
|
||||||
|
stack: 'stack',
|
||||||
|
vmid: 'vmid',
|
||||||
|
tailscale_ip: 'tailscale ip',
|
||||||
|
atlas: 'atlas',
|
||||||
|
argus: 'argus',
|
||||||
|
semaphore: 'semaphore',
|
||||||
|
patchmon: 'patchmon',
|
||||||
|
tailscale: 'tailscale',
|
||||||
|
andromeda: 'andromeda',
|
||||||
|
hardware_acceleration: 'hw acceleration',
|
||||||
|
};
|
||||||
|
|
||||||
function stateClass(field, val) {
|
function stateClass(field, val) {
|
||||||
if (field !== 'state') return '';
|
if (field !== 'state') return '';
|
||||||
return { deployed: 'tl-deployed', testing: 'tl-testing', degraded: 'tl-degraded' }[val] ?? '';
|
return { deployed: 'tl-deployed', testing: 'tl-testing', degraded: 'tl-degraded' }[val] ?? '';
|
||||||
@@ -113,9 +164,10 @@ function fmtHistVal(field, val) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function renderDetailPage(vmid) {
|
async function renderDetailPage(vmid) {
|
||||||
const [inst, history] = await Promise.all([getInstance(vmid), getInstanceHistory(vmid)]);
|
const [inst, history, all] = await Promise.all([getInstance(vmid), getInstanceHistory(vmid), getInstances()]);
|
||||||
if (!inst) { navigate('dashboard'); return; }
|
if (!inst) { navigate('dashboard'); return; }
|
||||||
currentVmid = vmid;
|
currentVmid = vmid;
|
||||||
|
document.getElementById('nav-count').textContent = `${all.length} instance${all.length !== 1 ? 's' : ''}`;
|
||||||
|
|
||||||
document.getElementById('detail-vmid-crumb').textContent = vmid;
|
document.getElementById('detail-vmid-crumb').textContent = vmid;
|
||||||
document.getElementById('detail-name').textContent = inst.name;
|
document.getElementById('detail-name').textContent = inst.name;
|
||||||
@@ -126,7 +178,7 @@ async function renderDetailPage(vmid) {
|
|||||||
document.getElementById('detail-identity').innerHTML = `
|
document.getElementById('detail-identity').innerHTML = `
|
||||||
<div class="kv-row"><span class="kv-key">name</span><span class="kv-val highlight">${esc(inst.name)}</span></div>
|
<div class="kv-row"><span class="kv-key">name</span><span class="kv-val highlight">${esc(inst.name)}</span></div>
|
||||||
<div class="kv-row"><span class="kv-key">state</span><span class="kv-val"><span class="badge ${esc(inst.state)}">${esc(inst.state)}</span></span></div>
|
<div class="kv-row"><span class="kv-key">state</span><span class="kv-val"><span class="badge ${esc(inst.state)}">${esc(inst.state)}</span></span></div>
|
||||||
<div class="kv-row"><span class="kv-key">stack</span><span class="kv-val highlight">${esc(inst.stack) || '—'}</span></div>
|
<div class="kv-row"><span class="kv-key">stack</span><span class="kv-val"><span class="badge ${esc(inst.stack)}">${esc(inst.stack) || '—'}</span></span></div>
|
||||||
<div class="kv-row"><span class="kv-key">vmid</span><span class="kv-val highlight">${inst.vmid}</span></div>
|
<div class="kv-row"><span class="kv-key">vmid</span><span class="kv-val highlight">${inst.vmid}</span></div>
|
||||||
<div class="kv-row"><span class="kv-key">internal id</span><span class="kv-val">${inst.id}</span></div>
|
<div class="kv-row"><span class="kv-key">internal id</span><span class="kv-val">${inst.id}</span></div>
|
||||||
`;
|
`;
|
||||||
@@ -150,19 +202,23 @@ async function renderDetailPage(vmid) {
|
|||||||
? history.map(e => {
|
? history.map(e => {
|
||||||
if (e.field === 'created') return `
|
if (e.field === 'created') return `
|
||||||
<div class="tl-item tl-created">
|
<div class="tl-item tl-created">
|
||||||
|
<span class="tl-event">instance created</span>
|
||||||
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
||||||
<span class="tl-field">created</span>
|
|
||||||
<span class="tl-change">—</span>
|
|
||||||
</div>`;
|
</div>`;
|
||||||
|
const label = FIELD_LABELS[e.field] ?? esc(e.field);
|
||||||
|
const newCls = (e.field === 'state' || e.field === 'stack')
|
||||||
|
? `badge ${esc(e.new_value)}`
|
||||||
|
: `tl-new ${stateClass(e.field, e.new_value)}`;
|
||||||
return `
|
return `
|
||||||
<div class="tl-item">
|
<div class="tl-item">
|
||||||
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
<div class="tl-event">
|
||||||
<span class="tl-field">${esc(e.field)}</span>
|
<span class="tl-label">${label}</span>
|
||||||
<span class="tl-change">
|
<span class="tl-sep">·</span>
|
||||||
<span class="tl-old">${fmtHistVal(e.field, e.old_value)}</span>
|
<span class="tl-old">${fmtHistVal(e.field, e.old_value)}</span>
|
||||||
<span class="tl-arrow">→</span>
|
<span class="tl-arrow">→</span>
|
||||||
<span class="tl-new ${stateClass(e.field, e.new_value)}">${fmtHistVal(e.field, e.new_value)}</span>
|
<span class="${newCls}">${fmtHistVal(e.field, e.new_value)}</span>
|
||||||
</span>
|
</div>
|
||||||
|
<span class="tl-time">${fmtDateFull(e.changed_at)}</span>
|
||||||
</div>`;
|
</div>`;
|
||||||
}).join('')
|
}).join('')
|
||||||
: '<div class="tl-empty">no history yet</div>';
|
: '<div class="tl-empty">no history yet</div>';
|
||||||
@@ -289,6 +345,16 @@ function showToast(msg, type = 'success') {
|
|||||||
// ── Settings Modal ────────────────────────────────────────────────────────────
|
// ── Settings Modal ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function openSettingsModal() {
|
function openSettingsModal() {
|
||||||
|
const sel = document.getElementById('tz-select');
|
||||||
|
if (!sel.options.length) {
|
||||||
|
for (const { label, tz } of TIMEZONES) {
|
||||||
|
const opt = document.createElement('option');
|
||||||
|
opt.value = tz;
|
||||||
|
opt.textContent = label;
|
||||||
|
sel.appendChild(opt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sel.value = getTimezone();
|
||||||
document.getElementById('settings-modal').classList.add('open');
|
document.getElementById('settings-modal').classList.add('open');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -353,3 +419,10 @@ document.getElementById('confirm-overlay').addEventListener('click', e => {
|
|||||||
document.getElementById('settings-modal').addEventListener('click', e => {
|
document.getElementById('settings-modal').addEventListener('click', e => {
|
||||||
if (e.target === document.getElementById('settings-modal')) closeSettingsModal();
|
if (e.target === document.getElementById('settings-modal')) closeSettingsModal();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
document.getElementById('tz-select').addEventListener('change', e => {
|
||||||
|
localStorage.setItem('catalyst_tz', e.target.value);
|
||||||
|
const m = window.location.pathname.match(/^\/instance\/(\d+)/);
|
||||||
|
if (m) renderDetailPage(parseInt(m[1], 10));
|
||||||
|
else renderDashboard();
|
||||||
|
});
|
||||||
|
|||||||
1
js/version.js
Normal file
1
js/version.js
Normal file
@@ -0,0 +1 @@
|
|||||||
|
const VERSION = "1.3.0";
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "catalyst",
|
"name": "catalyst",
|
||||||
"version": "1.2.2",
|
"version": "1.3.0",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node server/server.js",
|
"start": "node server/server.js",
|
||||||
|
|||||||
@@ -58,16 +58,22 @@ describe('esc', () => {
|
|||||||
|
|
||||||
// ── fmtDate() ─────────────────────────────────────────────────────────────────
|
// ── fmtDate() ─────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function fmtDate(d) {
|
function parseUtc(d) {
|
||||||
|
if (typeof d !== 'string') return new Date(d)
|
||||||
|
const hasZone = d.endsWith('Z') || /[+-]\d{2}:\d{2}$/.test(d)
|
||||||
|
return new Date(hasZone ? d : d.replace(' ', 'T') + 'Z')
|
||||||
|
}
|
||||||
|
|
||||||
|
function fmtDate(d, tz = 'UTC') {
|
||||||
if (!d) return '—'
|
if (!d) return '—'
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' })
|
return parseUtc(d).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric', timeZone: tz })
|
||||||
} catch (e) { return d }
|
} catch (e) { return d }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('fmtDate', () => {
|
describe('fmtDate', () => {
|
||||||
it('formats a valid ISO date string', () => {
|
it('formats a valid ISO date string', () => {
|
||||||
const result = fmtDate('2024-03-15T00:00:00')
|
const result = fmtDate('2024-03-15T12:00:00Z')
|
||||||
expect(result).toMatch(/Mar/)
|
expect(result).toMatch(/Mar/)
|
||||||
expect(result).toMatch(/15/)
|
expect(result).toMatch(/15/)
|
||||||
expect(result).toMatch(/2024/)
|
expect(result).toMatch(/2024/)
|
||||||
@@ -88,24 +94,42 @@ describe('fmtDate', () => {
|
|||||||
|
|
||||||
// ── fmtDateFull() ─────────────────────────────────────────────────────────────
|
// ── fmtDateFull() ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
function fmtDateFull(d) {
|
function fmtDateFull(d, tz = 'UTC') {
|
||||||
if (!d) return '—'
|
if (!d) return '—'
|
||||||
try {
|
try {
|
||||||
return new Date(d).toLocaleString('en-US', {
|
return parseUtc(d).toLocaleString('en-US', {
|
||||||
year: 'numeric', month: 'short', day: 'numeric',
|
year: 'numeric', month: 'short', day: 'numeric',
|
||||||
hour: '2-digit', minute: '2-digit',
|
hour: '2-digit', minute: '2-digit',
|
||||||
|
timeZone: tz, timeZoneName: 'short',
|
||||||
})
|
})
|
||||||
} catch (e) { return d }
|
} catch (e) { return d }
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('fmtDateFull', () => {
|
describe('fmtDateFull', () => {
|
||||||
it('includes date and time components', () => {
|
it('includes date and time components', () => {
|
||||||
const result = fmtDateFull('2024-03-15T14:30:00')
|
const result = fmtDateFull('2024-03-15T14:30:00Z')
|
||||||
expect(result).toMatch(/Mar/)
|
expect(result).toMatch(/Mar/)
|
||||||
expect(result).toMatch(/2024/)
|
expect(result).toMatch(/2024/)
|
||||||
expect(result).toMatch(/\d{1,2}:\d{2}/)
|
expect(result).toMatch(/\d{1,2}:\d{2}/)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('includes the timezone abbreviation', () => {
|
||||||
|
expect(fmtDateFull('2024-03-15T14:30:00Z', 'UTC')).toMatch(/UTC/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('converts to the given timezone', () => {
|
||||||
|
// 2024-03-15 18:30 UTC = 2024-03-15 14:30 EDT (UTC-4 in March)
|
||||||
|
const result = fmtDateFull('2024-03-15T18:30:00Z', 'America/New_York')
|
||||||
|
expect(result).toMatch(/2:30/)
|
||||||
|
expect(result).toMatch(/EDT/)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('treats SQLite-format timestamps (space, no Z) as UTC', () => {
|
||||||
|
// SQLite datetime('now') → 'YYYY-MM-DD HH:MM:SS', no timezone marker.
|
||||||
|
// Must parse identically to the same moment expressed as ISO UTC.
|
||||||
|
expect(fmtDateFull('2024-03-15 18:30:00', 'UTC')).toBe(fmtDateFull('2024-03-15T18:30:00Z', 'UTC'))
|
||||||
|
})
|
||||||
|
|
||||||
it('returns — for null', () => {
|
it('returns — for null', () => {
|
||||||
expect(fmtDateFull(null)).toBe('—')
|
expect(fmtDateFull(null)).toBe('—')
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user