diff --git a/package-lock.json b/package-lock.json index 8b00ff0781..b98d8c6b5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,8 +25,6 @@ "blurhash": "2.0.4", "browser-encrypt-attachment": "0.3.0", "classnames": "2.3.2", - "dateformat": "5.0.3", - "dayjs": "1.11.10", "domhandler": "5.0.3", "emojibase": "6.1.0", "emojibase-data": "7.0.1", @@ -4558,19 +4556,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/dateformat": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-5.0.3.tgz", - "integrity": "sha512-Kvr6HmPXUMerlLcLF+Pwq3K7apHpYmGDVqrxcDasBg86UcKeTSNWbEzU8bwdXnxnR44FtMhJAxI4Bov6Y/KUfA==", - "engines": { - "node": ">=12.20" - } - }, - "node_modules/dayjs": { - "version": "1.11.10", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", - "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==" - }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/package.json b/package.json index d06b960195..caadfb2f95 100644 --- a/package.json +++ b/package.json @@ -36,8 +36,6 @@ "blurhash": "2.0.4", "browser-encrypt-attachment": "0.3.0", "classnames": "2.3.2", - "dateformat": "5.0.3", - "dayjs": "1.11.10", "domhandler": "5.0.3", "emojibase": "6.1.0", "emojibase-data": "7.0.1", diff --git a/src/app/components/message/Time.tsx b/src/app/components/message/Time.tsx index a5126015f4..e0bdf9a947 100644 --- a/src/app/components/message/Time.tsx +++ b/src/app/components/message/Time.tsx @@ -1,27 +1,36 @@ import React, { ComponentProps } from 'react'; import { Text, as } from 'folds'; -import { timeDayMonYear, timeHourMinute, today, yesterday } from '../../utils/time'; +import { DateTime } from '../../utils/time'; export type TimeProps = { compact?: boolean; ts: number; + dateTime: DateTime; }; export const Time = as<'span', TimeProps & ComponentProps>( - ({ compact, ts, ...props }, ref) => { + ({ compact, ts, dateTime, ...props }, ref) => { + const date = new Date(ts); + const { isToday, isYesterday, relativeTerm } = dateTime.relative(date); let time = ''; - if (compact) { - time = timeHourMinute(ts); - } else if (today(ts)) { - time = timeHourMinute(ts); - } else if (yesterday(ts)) { - time = `Yesterday ${timeHourMinute(ts)}`; + if (compact || isToday) { + time = dateTime.time(date); + } else if (isYesterday) { + time = `${relativeTerm}, ${dateTime.time(date)}`; } else { - time = `${timeDayMonYear(ts)} ${timeHourMinute(ts)}`; + time = `${dateTime.dateTime(date)}`; } return ( - + {time} ); diff --git a/src/app/components/room-intro/RoomIntro.tsx b/src/app/components/room-intro/RoomIntro.tsx index 0fed123d35..9048e57314 100644 --- a/src/app/components/room-intro/RoomIntro.tsx +++ b/src/app/components/room-intro/RoomIntro.tsx @@ -8,7 +8,7 @@ import { getMemberDisplayName, getStateEvent } from '../../utils/room'; import { useMatrixClient } from '../../hooks/useMatrixClient'; import { getMxIdLocalPart } from '../../utils/matrix'; import { AsyncStatus, useAsyncCallback } from '../../hooks/useAsyncCallback'; -import { timeDayMonthYear, timeHourMinute } from '../../utils/time'; +import { DateTime } from '../../utils/time'; import { useRoomNavigate } from '../../hooks/useRoomNavigate'; import { RoomAvatar } from '../room-avatar'; import { nameInitials } from '../../utils/common'; @@ -17,9 +17,10 @@ import { mDirectAtom } from '../../state/mDirectList'; export type RoomIntroProps = { room: Room; + dateTime: DateTime; }; -export const RoomIntro = as<'div', RoomIntroProps>(({ room, ...props }, ref) => { +export const RoomIntro = as<'div', RoomIntroProps>(({ room, dateTime, ...props }, ref) => { const mx = useMatrixClient(); const { navigateRoom } = useRoomNavigate(); const mDirects = useAtomValue(mDirectAtom); @@ -65,7 +66,7 @@ export const RoomIntro = as<'div', RoomIntroProps>(({ room, ...props }, ref) => {'Created by '} @{creatorName} - {` on ${timeDayMonthYear(ts)} ${timeHourMinute(ts)}`} + {` on ${dateTime.full(ts)}`} )} diff --git a/src/app/features/message-search/MessageSearch.tsx b/src/app/features/message-search/MessageSearch.tsx index 5793ed9116..82d0a654cf 100644 --- a/src/app/features/message-search/MessageSearch.tsx +++ b/src/app/features/message-search/MessageSearch.tsx @@ -23,6 +23,7 @@ import { SearchResultGroup } from './SearchResultGroup'; import { SearchInput } from './SearchInput'; import { SearchFilters } from './SearchFilters'; import { VirtualTile } from '../../components/virtualizer'; +import { useDateTime } from '../../utils/time'; const useSearchPathSearchParams = (searchParams: URLSearchParams): _SearchPathSearchParams => useMemo( @@ -53,6 +54,7 @@ export function MessageSearch({ const mx = useMatrixClient(); const mDirects = useAtomValue(mDirectAtom); const allRooms = useRooms(mx, allRoomsAtom, mDirects); + const dateTime = useDateTime(); const [mediaAutoLoad] = useSetting(settingsAtom, 'mediaAutoLoad'); const [urlPreview] = useSetting(settingsAtom, 'urlPreview'); const searchInputRef = useRef(null); @@ -294,6 +296,7 @@ export function MessageSearch({ room={groupRoom} highlights={highlights} items={group.items} + dateTime={dateTime} mediaAutoLoad={mediaAutoLoad} urlPreview={urlPreview} onOpen={navigateRoom} diff --git a/src/app/features/message-search/SearchResultGroup.tsx b/src/app/features/message-search/SearchResultGroup.tsx index 6f84f62101..973a6b709d 100644 --- a/src/app/features/message-search/SearchResultGroup.tsx +++ b/src/app/features/message-search/SearchResultGroup.tsx @@ -33,11 +33,13 @@ import { ResultItem } from './useMessageSearch'; import { SequenceCard } from '../../components/sequence-card'; import { useRoomNavigate } from '../../hooks/useRoomNavigate'; import { UserAvatar } from '../../components/user-avatar'; +import { DateTime } from '../../utils/time'; type SearchResultGroupProps = { room: Room; highlights: string[]; items: ResultItem[]; + dateTime: DateTime; mediaAutoLoad?: boolean; urlPreview?: boolean; onOpen: (roomId: string, eventId: string) => void; @@ -46,6 +48,7 @@ export function SearchResultGroup({ room, highlights, items, + dateTime, mediaAutoLoad, urlPreview, onOpen, @@ -228,7 +231,7 @@ export function SearchResultGroup({ {displayName} -