[Perf] Message List: Avoid toLocaleTimeString because of bad performance
This commit is contained in:
parent
5c3a530003
commit
842e86cd4c
@ -409,7 +409,7 @@ const Composer: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
closeEmojiTooltip();
|
closeEmojiTooltip();
|
||||||
|
|
||||||
if (IS_SINGLE_COLUMN_LAYOUT) {
|
if (IS_SINGLE_COLUMN_LAYOUT) {
|
||||||
// @perf
|
// @optimization
|
||||||
setTimeout(() => closeSymbolMenu(), SENDING_ANIMATION_DURATION);
|
setTimeout(() => closeSymbolMenu(), SENDING_ANIMATION_DURATION);
|
||||||
} else {
|
} else {
|
||||||
closeSymbolMenu();
|
closeSymbolMenu();
|
||||||
|
|||||||
@ -31,17 +31,19 @@ function toIsoString(date: Date) {
|
|||||||
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
return `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @optimization `toLocaleTimeString` is avoided because of bad performance
|
||||||
export function formatTime(datetime: number | Date, lang: LangFn) {
|
export function formatTime(datetime: number | Date, lang: LangFn) {
|
||||||
const date = typeof datetime === 'number' ? new Date(datetime) : datetime;
|
const date = typeof datetime === 'number' ? new Date(datetime) : datetime;
|
||||||
const timeFormat = lang.timeFormat || '24h';
|
const timeFormat = lang.timeFormat || '24h';
|
||||||
|
|
||||||
const time = date.toLocaleTimeString(lang.code, {
|
let hours = date.getHours();
|
||||||
hour12: timeFormat === '12h',
|
let marker = '';
|
||||||
hour: timeFormat === '12h' ? 'numeric' : '2-digit',
|
if (timeFormat === '12h') {
|
||||||
minute: '2-digit',
|
marker = hours >= 12 ? ' PM' : ' AM';
|
||||||
});
|
hours %= 12;
|
||||||
|
}
|
||||||
|
|
||||||
return timeFormat === '12h' ? time.replace(/^0:/, '12:') : time.replace('24:', '00:');
|
return `${String(hours).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}${marker}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatPastTimeShort(lang: LangFn, datetime: number | Date) {
|
export function formatPastTimeShort(lang: LangFn, datetime: number | Date) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user