mirror of
https://github.com/samsonjs/spirit-tracker.git
synced 2026-03-25 09:25:51 +00:00
feat: Nicer date
This commit is contained in:
parent
7b7bf44dd3
commit
decb0ad8ef
1 changed files with 8 additions and 6 deletions
|
|
@ -18,8 +18,12 @@ export function esc(s) {
|
||||||
const s = String(iso || "");
|
const s = String(iso || "");
|
||||||
if (!s) return "";
|
if (!s) return "";
|
||||||
|
|
||||||
const d = new Date(s);
|
const d0 = new Date(s);
|
||||||
if (!Number.isFinite(d.getTime())) return "";
|
const t0 = d0.getTime();
|
||||||
|
if (!Number.isFinite(t0)) return "";
|
||||||
|
|
||||||
|
// Round to nearest hour
|
||||||
|
const d = new Date(Math.round(t0 / 3600000) * 3600000);
|
||||||
|
|
||||||
const parts = new Intl.DateTimeFormat("en-US", {
|
const parts = new Intl.DateTimeFormat("en-US", {
|
||||||
timeZone: "America/Vancouver",
|
timeZone: "America/Vancouver",
|
||||||
|
|
@ -44,11 +48,9 @@ export function esc(s) {
|
||||||
else if (p.type === "dayPeriod") dayPeriod = p.value;
|
else if (p.type === "dayPeriod") dayPeriod = p.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ampm = String(dayPeriod || "").toLowerCase(); // "am"/"pm"
|
return `${month} ${day} ${hour}:${minute}${String(dayPeriod || "").toLowerCase()}`;
|
||||||
return `${month} ${day} ${hour}:${minute}${ampm}`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function renderThumbHtml(imgUrl, cls = "thumb") {
|
export function renderThumbHtml(imgUrl, cls = "thumb") {
|
||||||
const img = normImg(imgUrl);
|
const img = normImg(imgUrl);
|
||||||
if (!img) return `<div class="thumbPlaceholder"></div>`;
|
if (!img) return `<div class="thumbPlaceholder"></div>`;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue