aboutsummaryrefslogtreecommitdiff
path: root/asset-sources/fietsboek.ts
diff options
context:
space:
mode:
Diffstat (limited to 'asset-sources/fietsboek.ts')
-rw-r--r--asset-sources/fietsboek.ts26
1 files changed, 18 insertions, 8 deletions
diff --git a/asset-sources/fietsboek.ts b/asset-sources/fietsboek.ts
index 66caa4f..bcce661 100644
--- a/asset-sources/fietsboek.ts
+++ b/asset-sources/fietsboek.ts
@@ -540,6 +540,23 @@ function loadProfileStats() {
/* Used via in-page scripts, so make eslint happy */
loadProfileStats;
+/**
+ * Formats the given timestamp to the user's locale.
+ *
+ * @param timestamp - The timestamp in milliseconds since the epoch.
+ * @return The formatted string.
+ */
+function formatTimestamp(timestamp: number): string {
+ const date = new Date(timestamp);
+ // TypeScript complains about this, but according to MDN it is fine, at
+ // least in "somewhat modern" browsers
+ const intl = new Intl.DateTimeFormat(LOCALE, {
+ dateStyle: "medium",
+ timeStyle: "medium",
+ } as any);
+ return intl.format(date);
+}
+
document.addEventListener('DOMContentLoaded', function() {
window.fietsboekImageIndex = 0;
@@ -567,13 +584,6 @@ document.addEventListener('DOMContentLoaded', function() {
/* Format all datetimes to the local timezone */
document.querySelectorAll(".fietsboek-local-datetime").forEach((obj) => {
const timestamp = parseFloat(obj.attributes.getNamedItem("data-utc-timestamp")!.value);
- const date = new Date(timestamp * 1000);
- // TypeScript complains about this, but according to MDN it is fine, at
- // least in "somewhat modern" browsers
- const intl = new Intl.DateTimeFormat(LOCALE, {
- dateStyle: "medium",
- timeStyle: "medium",
- } as any);
- obj.innerHTML = intl.format(date);
+ obj.innerHTML = formatTimestamp(timestamp * 1000);
});
});