Skip to content

Commit 1201a5c

Browse files
authored
* [#171] hardcode timezone abbreviation map and render abbreviations accordingly * [#171] switch to using moment.js to display timezone abbreviations * [#171] display correct local time * remove unneeded console log * [#171] remove margin-right of time to prevent space before comma
1 parent f73deaa commit 1201a5c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

layouts/partials/head.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,23 @@
4444
{{- end }}
4545
{{- end }}
4646

47+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/moment.min.js"></script>
48+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/builds/moment-timezone-with-data.min.js"></script>
49+
50+
<script>
51+
document.addEventListener("DOMContentLoaded", function () {
52+
document.querySelectorAll('.post_date').forEach(el => {
53+
const rawDate = el.dataset.datetime;
54+
if (!rawDate) return;
55+
56+
const userZone = moment.tz.guess();
57+
const m = moment.parseZone(rawDate).tz(userZone);
58+
const time = m.format("ddd MMM D, YYYY [at] h:mm A z")
59+
60+
const text = el.innerHTML;
61+
el.innerHTML = `Event Date: ${time}`;
62+
});
63+
});
64+
</script>
65+
4766
{{- partial "scripts/google/tag-manager" (dict "noscript" false) }}

layouts/partials/post-meta.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
2121
{{ if .Params.event_date }}
2222
{{- if ($scratch.Get "writeSeparator") }}&nbsp;· {{ end }}
2323
<span>{{ partial "sprite" (dict "icon" "calendar") }}</span>
24-
<span class="post_date">
25-
Event date: {{ time.Format "Mon Jan 2, 2006 at 3:04 PM MST" .Params.event_date -}}{{ if .Params.event_location }}, {{.Params.event_location}}{{- end}}
24+
<!-- this in-line style is to prevent a space before the comma separating time and date without effecting other parts of the post -->
25+
<span style="margin-right: 0;" class="post_date" data-datetime="{{ .Params.event_date }}">
26+
Event date: {{ time.Format "Mon Jan 2, 2006 at 3:04 PM " .Params.event_date -}}
27+
</span>
28+
<span>
29+
{{ if .Params.event_location }}, {{.Params.event_location}}{{- end}}
2630
</span>
2731
{{ end }}
2832
{{ if and (.Params.registration) (.Params.event_date) }}

0 commit comments

Comments
 (0)