From 64dc599532c7b90d98c49e68f6c834723cdc349c Mon Sep 17 00:00:00 2001 From: Emma Segal-Grossman Date: Tue, 4 Mar 2025 13:52:06 -0500 Subject: [PATCH] Add basic date & time formatters using navigator language (#404) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adjacent to #400 — while this isn't yet a proper localization pass, at least dates & times will now use the user's browser language/locale settings. When used in Browsertrix, this should ensure dates are formatted more consistently, at least when the user has a locale with a language matching one of the supported languages in Browsertrix set in their browser settings. Also adds tabular numerals in a few places (e.g. lists of dates/times). --- src/embed-receipt.ts | 5 ++++- src/item-info.ts | 5 ++++- src/item.ts | 18 +++++++++++++++--- src/pageentry.ts | 31 ++++++++++++------------------- src/story.ts | 3 ++- src/url-resources.ts | 3 ++- src/utils/dateTimeFormatter.ts | 23 +++++++++++++++++++++++ 7 files changed, 62 insertions(+), 26 deletions(-) create mode 100644 src/utils/dateTimeFormatter.ts diff --git a/src/embed-receipt.ts b/src/embed-receipt.ts index 0c35042..cd87a6c 100644 --- a/src/embed-receipt.ts +++ b/src/embed-receipt.ts @@ -12,6 +12,7 @@ import { tsToDate } from "./pageutils"; import prettyBytes from "pretty-bytes"; import { property } from "lit/decorators.js"; import type { ItemType } from "./types"; +import { dateTimeFormatter } from "./utils/dateTimeFormatter"; // =========================================================================== export class RWPEmbedReceipt extends LitElement { @@ -184,7 +185,9 @@ export class RWPEmbedReceipt extends LitElement { ? `https://crt.sh/?q=${certFingerprint}` : ""; - const dateStr = tsToDate(this.ts).toLocaleString(); + const dateStr = this.ts + ? dateTimeFormatter.format(tsToDate(this.ts) as Date) + : ""; return html`