From ef44c19e8a84140ec972cb20cf91631bb5e4d851 Mon Sep 17 00:00:00 2001 From: Nolan Lawson Date: Sun, 13 Jan 2019 15:56:39 -0800 Subject: [PATCH] feat: date title shows absolute date (#890) fixes #759 --- src/routes/_components/status/Status.html | 7 +++- .../_components/status/StatusDetails.html | 17 ++++---- .../status/StatusRelativeDate.html | 4 +- src/routes/_utils/formatters.js | 42 +++++++------------ 4 files changed, 30 insertions(+), 40 deletions(-) diff --git a/src/routes/_components/status/Status.html b/src/routes/_components/status/Status.html index c3fe662..803a8b4 100644 --- a/src/routes/_components/status/Status.html +++ b/src/routes/_components/status/Status.html @@ -126,6 +126,7 @@ import { htmlToPlainText } from '../../_utils/htmlToPlainText' import { measureText } from '../../_utils/measureText' import { LONG_POST_LENGTH, LONG_POST_TEXT } from '../../_static/statuses' + import { absoluteDateFormatter } from '../../_utils/formatters' const INPUT_TAGS = new Set(['a', 'button', 'input', 'textarea']) const isUserInputElement = node => INPUT_TAGS.has(node.localName) @@ -241,6 +242,7 @@ return getAccountAccessibleName(originalAccount, $omitEmojiInDisplayNames) }, createdAtDate: ({ originalStatus }) => originalStatus.created_at, + absoluteFormattedDate: ({ createdAtDate }) => absoluteDateFormatter.format(new Date(createdAtDate)), timeagoFormattedDate: ({ createdAtDate }) => formatTimeagoDate(createdAtDate), reblog: ({ status }) => status.reblog, ariaLabel: ({ originalAccount, account, plainTextContent, timeagoFormattedDate, spoilerText, @@ -267,7 +269,7 @@ account, accountId, uuid, isStatusInNotification, isStatusInOwnThread, originalAccount, originalAccountId, spoilerShown, visibility, replyShown, replyVisibility, spoilerText, originalStatus, originalStatusId, inReplyToId, - createdAtDate, timeagoFormattedDate, shortcutScope }) => ({ + createdAtDate, timeagoFormattedDate, shortcutScope, absoluteFormattedDate }) => ({ notification, notificationId, status, @@ -290,7 +292,8 @@ inReplyToId, createdAtDate, timeagoFormattedDate, - shortcutScope + shortcutScope, + absoluteFormattedDate }) } } diff --git a/src/routes/_components/status/StatusDetails.html b/src/routes/_components/status/StatusDetails.html index 07ac7e3..f837e3c 100644 --- a/src/routes/_components/status/StatusDetails.html +++ b/src/routes/_components/status/StatusDetails.html @@ -2,9 +2,11 @@ - + {#if applicationName} {#if applicationWebsite} @@ -132,7 +134,7 @@ \ No newline at end of file + diff --git a/src/routes/_components/status/StatusRelativeDate.html b/src/routes/_components/status/StatusRelativeDate.html index 1eb5af9..2f5f9ca 100644 --- a/src/routes/_components/status/StatusRelativeDate.html +++ b/src/routes/_components/status/StatusRelativeDate.html @@ -2,7 +2,7 @@ href="/statuses/{originalStatusId}" focus-key={focusKey} > - @@ -34,4 +34,4 @@ focusKey: ({ uuid }) => `status-relative-date-${uuid}` } } - \ No newline at end of file + diff --git a/src/routes/_utils/formatters.js b/src/routes/_utils/formatters.js index a8956d8..61e9b96 100644 --- a/src/routes/_utils/formatters.js +++ b/src/routes/_utils/formatters.js @@ -1,29 +1,15 @@ -let dateFormatter +export const absoluteDateFormatter = new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'long', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' +}) -export function getDateFormatter () { - if (!dateFormatter) { - dateFormatter = new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'long', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }) - } - return dateFormatter -} - -let shortDateFormatter - -export function getShortDateFormatter () { - if (!shortDateFormatter) { - shortDateFormatter = new Intl.DateTimeFormat('en-US', { - year: 'numeric', - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }) - } - return shortDateFormatter -} +export const shortAbsoluteDateFormatter = new Intl.DateTimeFormat('en-US', { + year: 'numeric', + month: 'short', + day: 'numeric', + hour: '2-digit', + minute: '2-digit' +})