From 9183fd66b2dc50cc113d387ca246eb45b96c448d Mon Sep 17 00:00:00 2001 From: Gimle Larpes <97182804+GimleLarpes@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:13:00 +0300 Subject: [PATCH] Add settings to enable 24-hour time format and customizable date format (#2347) * Add setting to enable 24-hour time format * added hour24Clock to TimeProps * Add incomplete dateFormatString setting * Move 24-hour toggle to Appearance * Add "Date & Time" subheading, cleanup after merge * Add setting for date formatting * Fix minor formatting and naming issues * Document functions * adress most comments * add hint for date formatting * add support for 24hr time to TimePicker * prevent overflow on small displays --- src/app/atoms/time/Time.jsx | 33 +- src/app/components/message/Time.tsx | 26 +- src/app/components/room-intro/RoomIntro.tsx | 6 +- src/app/components/time-date/TimePicker.tsx | 117 +++--- .../features/message-search/MessageSearch.tsx | 5 + .../message-search/SearchResultGroup.tsx | 10 +- src/app/features/room/RoomTimeline.tsx | 51 ++- .../features/room/jump-to-time/JumpToTime.tsx | 6 +- src/app/features/room/message/Message.tsx | 11 +- .../room/room-pin-menu/RoomPinMenu.tsx | 9 +- .../features/settings/devices/DeviceTile.tsx | 8 +- src/app/features/settings/general/General.tsx | 361 +++++++++++++++++- src/app/hooks/useDateFormat.ts | 34 ++ src/app/pages/client/inbox/Invites.tsx | 66 +++- src/app/pages/client/inbox/Notifications.tsx | 14 +- src/app/state/settings.ts | 7 + src/app/utils/time.ts | 9 +- 17 files changed, 691 insertions(+), 82 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 750b958f..d7bbe439 100644 --- a/src/app/atoms/time/Time.jsx +++ b/src/app/atoms/time/Time.jsx @@ -4,10 +4,25 @@ import PropTypes from 'prop-types'; import dateFormat from 'dateformat'; import { isInSameDay } from '../../../util/common'; -function Time({ timestamp, fullTime }) { +/** + * Renders a formatted timestamp. + * + * Displays the time in hour:minute format if the message is from today or yesterday, unless `fullTime` is true. + * For older messages, it shows the date and time. + * + * @param {number} timestamp - The timestamp to display. + * @param {boolean} [fullTime=false] - If true, always show the full date and time. + * @param {boolean} hour24Clock - Whether to use 24-hour time format. + * @param {string} dateFormatString - Format string for the date part. + * @returns {JSX.Element} A