Merge pull request 'feat: timezone setting — display timestamps in selected local timezone' (#24) from feat/timezone-settings into dev
All checks were successful
CI / test (push) Successful in 12s
CI / build-dev (push) Successful in 19s

Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
2026-03-28 14:56:01 -04:00
4 changed files with 71 additions and 4 deletions

View File

@@ -665,6 +665,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; }

View File

@@ -180,6 +180,13 @@
<button class="modal-close" onclick="closeSettingsModal()">&#x2715;</button> <button class="modal-close" onclick="closeSettingsModal()">&#x2715;</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>

View File

@@ -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) {
@@ -14,14 +42,14 @@ function esc(str) {
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 new Date(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 new Date(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; }
} }
@@ -289,6 +317,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 +391,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();
});

View File

@@ -88,24 +88,36 @@ 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 new Date(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('returns — for null', () => { it('returns — for null', () => {
expect(fmtDateFull(null)).toBe('—') expect(fmtDateFull(null)).toBe('—')
}) })