Message Meta: Fix time format in alt text (#2938)
This commit is contained in:
parent
46b182bcb1
commit
494b8021f4
@ -66,9 +66,11 @@ const MessageMeta: FC<OwnProps> = ({
|
|||||||
|
|
||||||
const title = useMemo(() => {
|
const title = useMemo(() => {
|
||||||
if (!isActivated) return undefined;
|
if (!isActivated) return undefined;
|
||||||
const createDateTime = formatDateTimeToString(message.date * 1000, lang.code);
|
const createDateTime = formatDateTimeToString(message.date * 1000, lang.code, undefined, lang.timeFormat);
|
||||||
const editDateTime = message.isEdited && formatDateTimeToString(message.editDate! * 1000, lang.code);
|
const editDateTime = message.isEdited
|
||||||
const forwardedDateTime = message.forwardInfo && formatDateTimeToString(message.forwardInfo.date * 1000, lang.code);
|
&& formatDateTimeToString(message.editDate! * 1000, lang.code, undefined, lang.timeFormat);
|
||||||
|
const forwardedDateTime = message.forwardInfo
|
||||||
|
&& formatDateTimeToString(message.forwardInfo.date * 1000, lang.code, undefined, lang.timeFormat);
|
||||||
|
|
||||||
let text = createDateTime;
|
let text = createDateTime;
|
||||||
if (editDateTime) {
|
if (editDateTime) {
|
||||||
@ -81,7 +83,9 @@ const MessageMeta: FC<OwnProps> = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return text;
|
return text;
|
||||||
}, [isActivated, lang, message]);
|
// We need to listen to timeformat change
|
||||||
|
// eslint-disable-next-line react-hooks-static-deps/exhaustive-deps
|
||||||
|
}, [isActivated, lang, message, lang.timeFormat]);
|
||||||
|
|
||||||
const fullClassName = buildClassName(
|
const fullClassName = buildClassName(
|
||||||
'MessageMeta',
|
'MessageMeta',
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
import type { LangFn } from '../hooks/useLang';
|
import type { LangFn } from '../hooks/useLang';
|
||||||
|
import type { TimeFormat } from '../types';
|
||||||
import withCache from './withCache';
|
import withCache from './withCache';
|
||||||
|
|
||||||
const WEEKDAYS_FULL = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
const WEEKDAYS_FULL = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
|
||||||
@ -290,7 +291,10 @@ export function formatDateToString(
|
|||||||
return formatDayToStringWithCache(dayStartAt, locale, noYear, monthFormat, noDay);
|
return formatDayToStringWithCache(dayStartAt, locale, noYear, monthFormat, noDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDateTimeToString(datetime: Date | number, locale = 'en-US', noSeconds?: boolean) {
|
export function formatDateTimeToString(
|
||||||
|
datetime: Date | number, locale = 'en-US', noSeconds?: boolean,
|
||||||
|
timeFormat?: TimeFormat,
|
||||||
|
) {
|
||||||
const date = typeof datetime === 'number' ? new Date(datetime) : datetime;
|
const date = typeof datetime === 'number' ? new Date(datetime) : datetime;
|
||||||
return date.toLocaleString(
|
return date.toLocaleString(
|
||||||
locale,
|
locale,
|
||||||
@ -301,6 +305,7 @@ export function formatDateTimeToString(datetime: Date | number, locale = 'en-US'
|
|||||||
hour: 'numeric',
|
hour: 'numeric',
|
||||||
minute: 'numeric',
|
minute: 'numeric',
|
||||||
second: noSeconds ? undefined : 'numeric',
|
second: noSeconds ? undefined : 'numeric',
|
||||||
|
hourCycle: timeFormat === '12h' ? 'h12' : 'h23',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user