Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use relative times for Conversations panel timestamps. #2707

Open
wants to merge 2 commits into
base: clearnet
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions ts/components/conversation/Timestamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import moment from 'moment';
// tslint:disable-next-line: no-submodule-imports
import useInterval from 'react-use/lib/useInterval';
import styled from 'styled-components';
import { sync as osLocaleSync } from 'os-locale';

type Props = {
timestamp?: number;
Expand All @@ -18,7 +19,6 @@ const TimestampContainerNotListItem = styled.div`
font-size: var(--font-size-xs);
line-height: 16px;
letter-spacing: 0.3px;
text-transform: uppercase;
user-select: none;
`;

Expand Down Expand Up @@ -48,14 +48,29 @@ export const Timestamp = (props: Props) => {

const momentValue = moment(timestamp);
let dateString: string = '';
// Set the locale for the timestamps.
moment.locale(osLocaleSync().replace(/_/g, '-'));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's a blocking call which is a bad idea to have in the renderer side

You should be able to get the locale required by the user (and not just the system one) using:
const lang = (window.i18n as any).getLocale();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That code will retrieve only the generic language, e.g. en, not the specific locale variant, such as en_gb.


if (momentFromNow) {
dateString = momentValue.fromNow();
const now = moment();

if (momentValue.isSame(now, 'day')) {
// Today: Use the time only.
dateString = momentValue.format('LT');
} else if (now.diff(momentValue, 'days') < 6) {
// Less than a week old: Use the day and time.
dateString = momentValue.format('ddd LT');
} else if (momentValue.isSame(now, 'year')) {
// This year: Use the month, day of month and time.
dateString = momentValue.format('MMM D LT');
} else {
// Last year or older: Use the full date.
dateString = momentValue.format('L');
}
} else {
dateString = momentValue.format('lll');
}

dateString = dateString.replace('minutes', 'mins').replace('minute', 'min');

const title = moment(timestamp).format('llll');
if (props.isConversationListItem) {
return <TimestampContainerListItem title={title}>{dateString}</TimestampContainerListItem>;
Expand Down