From 1295c1c9b73b7de0b96e048d944665db5a2387b6 Mon Sep 17 00:00:00 2001 From: Gimle Larpes Date: Fri, 30 May 2025 20:56:05 +0200 Subject: [PATCH] Add incomplete dateFormatString setting --- src/app/atoms/time/Time.jsx | 5 +- src/app/components/message/Time.tsx | 5 +- .../features/message-search/MessageSearch.tsx | 2 + .../message-search/SearchResultGroup.tsx | 8 +- src/app/features/room/RoomTimeline.tsx | 10 +++ src/app/features/room/message/Message.tsx | 3 + .../room/room-pin-menu/RoomPinMenu.tsx | 7 +- .../features/settings/devices/DeviceTile.tsx | 4 +- src/app/features/settings/general/General.tsx | 76 ++++++++++++++++++- src/app/hooks/useDateFormat.ts | 30 ++++++++ src/app/pages/client/inbox/Invites.tsx | 52 +++++++++++-- src/app/pages/client/inbox/Notifications.tsx | 10 ++- src/app/state/settings.ts | 3 + src/app/utils/time.ts | 3 +- 14 files changed, 203 insertions(+), 15 deletions(-) create mode 100644 src/app/hooks/useDateFormat.ts diff --git a/src/app/atoms/time/Time.jsx b/src/app/atoms/time/Time.jsx index d2159f7b..96e7704b 100644 --- a/src/app/atoms/time/Time.jsx +++ b/src/app/atoms/time/Time.jsx @@ -4,7 +4,7 @@ import PropTypes from 'prop-types'; import dateFormat from 'dateformat'; import { isInSameDay } from '../../../util/common'; -function Time({ timestamp, fullTime, hour24Clock }) { +function Time({ timestamp, fullTime, hour24Clock, dateFormatString }) { const date = new Date(timestamp); const formattedFullTime = dateFormat( @@ -21,7 +21,7 @@ function Time({ timestamp, fullTime, hour24Clock }) { const timeFormat = hour24Clock ? 'HH:MM' : 'hh:MM TT'; - formattedDate = dateFormat(date, isToday || isYesterday ? timeFormat : 'dd/mm/yyyy'); + formattedDate = dateFormat(date, isToday || isYesterday ? timeFormat : dateFormatString); if (isYesterday) { formattedDate = `Yesterday, ${formattedDate}`; } @@ -42,6 +42,7 @@ Time.propTypes = { timestamp: PropTypes.number.isRequired, fullTime: PropTypes.bool, hour24Clock: PropTypes.bool.isRequired, + dateFormatString: PropTypes.string.isRequired, }; export default Time; diff --git a/src/app/components/message/Time.tsx b/src/app/components/message/Time.tsx index c2cd3943..f06662fb 100644 --- a/src/app/components/message/Time.tsx +++ b/src/app/components/message/Time.tsx @@ -6,10 +6,11 @@ export type TimeProps = { compact?: boolean; ts: number; hour24Clock: boolean; + dateFormatString: string; }; export const Time = as<'span', TimeProps & ComponentProps>( - ({ compact, hour24Clock, ts, ...props }, ref) => { + ({ compact, hour24Clock, dateFormatString, ts, ...props }, ref) => { const formattedTime = timeHourMinute(ts, hour24Clock); let time = ''; @@ -20,7 +21,7 @@ export const Time = as<'span', TimeProps & ComponentProps>( } else if (yesterday(ts)) { time = `Yesterday ${formattedTime}`; } else { - time = `${timeDayMonYear(ts)} ${formattedTime}`; + time = `${timeDayMonYear(ts, dateFormatString)} ${formattedTime}`; } return ( diff --git a/src/app/features/message-search/MessageSearch.tsx b/src/app/features/message-search/MessageSearch.tsx index 227c7e78..26085b5f 100644 --- a/src/app/features/message-search/MessageSearch.tsx +++ b/src/app/features/message-search/MessageSearch.tsx @@ -58,6 +58,7 @@ export function MessageSearch({ const [legacyUsernameColor] = useSetting(settingsAtom, 'legacyUsernameColor'); const [hour24Clock] = useSetting(settingsAtom, 'hour24Clock'); + const [dateFormatString] = useSetting(settingsAtom, 'dateFormatString'); const searchInputRef = useRef(null); const scrollTopAnchorRef = useRef(null); @@ -292,6 +293,7 @@ export function MessageSearch({ onOpen={navigateRoom} legacyUsernameColor={legacyUsernameColor || mDirects.has(groupRoom.roomId)} hour24Clock={hour24Clock} + dateFormatString={dateFormatString} /> ); diff --git a/src/app/features/message-search/SearchResultGroup.tsx b/src/app/features/message-search/SearchResultGroup.tsx index c0301699..bc94092b 100644 --- a/src/app/features/message-search/SearchResultGroup.tsx +++ b/src/app/features/message-search/SearchResultGroup.tsx @@ -58,6 +58,7 @@ type SearchResultGroupProps = { onOpen: (roomId: string, eventId: string) => void; legacyUsernameColor?: boolean; hour24Clock: boolean; + dateFormatString: string; }; export function SearchResultGroup({ room, @@ -68,6 +69,7 @@ export function SearchResultGroup({ onOpen, legacyUsernameColor, hour24Clock, + dateFormatString, }: SearchResultGroupProps) { const mx = useMatrixClient(); const useAuthentication = useMediaAuthentication(); @@ -277,7 +279,11 @@ export function SearchResultGroup({ {tagIconSrc && } -