Skip to content

Commit

Permalink
Add full timestamps when hovering over relative times (e.g. "3 months…
Browse files Browse the repository at this point in the history
… ago") (#739)
  • Loading branch information
jake-low authored Sep 11, 2024
1 parent 8177b71 commit 2eb29b7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 29 deletions.
22 changes: 12 additions & 10 deletions src/components/changeset/discussions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @flow
import React from 'react';
import { connect } from 'react-redux';
import { formatDistanceToNow, parse } from 'date-fns';
import { parse } from 'date-fns';
import AnchorifyText from 'react-anchorify-text';

import AssemblyAnchor from '../assembly_anchor';
import { CommentForm } from './comment';
import TranslateButton from './translate_button';
import { RelativeTime } from '../relative_time';
import { SignInButton } from './sign_in_button';
import { UserOSMLink } from './user_osm_link';

Expand Down Expand Up @@ -54,15 +55,16 @@ class Discussions extends React.PureComponent {
)}
</span>
<span>
{formatDistanceToNow(
// eslint-disable-next-line
parse(
comment.get('date'),
"yyyy-MM-dd'T'HH:mm:ssX",
new Date()
),
{ addSuffix: true }
)}
<RelativeTime
datetime={
// eslint-disable-next-line
parse(
comment.get('date'),
"yyyy-MM-dd'T'HH:mm:ssX",
new Date()
)
}
/>
</span>
</div>
<div className="flex-parent flex-parent--column mt6 mb3">
Expand Down
6 changes: 4 additions & 2 deletions src/components/changeset/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import React from 'react';
import { connect } from 'react-redux';
import { Map } from 'immutable';
import { formatDistanceToNow, parse } from 'date-fns';
import { parse } from 'date-fns';

import { CreateDeleteModify } from '../create_delete_modify';
import { Details } from './details';
import { RelativeTime } from '../relative_time';
import { useIsUserListed } from '../../hooks/UseIsUserListed';

type propsType = {|
Expand Down Expand Up @@ -79,7 +80,8 @@ function HeaderComponent({
&nbsp;({userEditCount} edits)
</span>
)}
&nbsp;created&nbsp;{formatDistanceToNow(date, { addSuffix: true })}
&nbsp;created&nbsp;
<RelativeTime datetime={date} />
</span>
</div>
</div>
Expand Down
26 changes: 15 additions & 11 deletions src/components/changeset/user.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { Link } from 'react-router-dom';
import showdown from 'showdown';
import { formatDistanceToNow, parse } from 'date-fns';
import { parse } from 'date-fns';

import { Avatar } from '../avatar';
import { getObjAsQueryParam } from '../../utils/query_params';
import { RelativeTime } from '../relative_time';
import { SignInButton } from './sign_in_button';
import { TrustWatchUser } from './trust_watch_user';
import { UserOSMLink } from './user_osm_link';
Expand Down Expand Up @@ -89,16 +90,13 @@ export class User extends React.PureComponent {
this.props.userDetails.get('description') || ''
);
const registrationDate = this.props.userDetails.get('accountCreated')
? formatDistanceToNow(
parse(
this.props.userDetails.get('accountCreated'),
// eslint-disable-next-line
"yyyy-MM-dd'T'HH:mm:ssX",
new Date()
),
{ addSuffix: true }
? parse(
this.props.userDetails.get('accountCreated'),
// eslint-disable-next-line
"yyyy-MM-dd'T'HH:mm:ssX",
new Date()
)
: '';
: null;

return (
<div className="px12 py6">
Expand All @@ -117,7 +115,13 @@ export class User extends React.PureComponent {
</div>
<div>
<p className="txt-s color-gray align-center">
{`Joined ${registrationDate} | `}
{registrationDate != null && (
<React.Fragment>
Joined&nbsp;
<RelativeTime datetime={registrationDate} />
{' | '}
</React.Fragment>
)}
{this.props.userDetails.get('count')
? this.renderUidFilterLink()
: `${this.props.userDetails.get(
Expand Down
11 changes: 5 additions & 6 deletions src/components/list/title.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// @flow
import React from 'react';
import { connect } from 'react-redux';
import { formatDistanceToNow, parse } from 'date-fns';
import { parse } from 'date-fns';

import { RelativeTime } from '../relative_time';
import { useIsUserListed } from '../../hooks/UseIsUserListed';

function TitleComponent({
Expand Down Expand Up @@ -37,11 +38,9 @@ function TitleComponent({
</strong>
<span className="txt-s mr3">
&nbsp;
{formatDistanceToNow(
// eslint-disable-next-line
parse(date, "yyyy-MM-dd'T'HH:mm:ssX", new Date()),
{ addSuffix: true }
)}
<RelativeTime
datetime={parse(date, "yyyy-MM-dd'T'HH:mm:ssX", new Date())}
/>
</span>
</span>
</div>
Expand Down
10 changes: 10 additions & 0 deletions src/components/relative_time.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react';
import { formatDistanceToNow } from 'date-fns';

export function RelativeTime({ datetime, addSuffix = true }: Object) {
return (
<time datetime={datetime.toISOString()} title={datetime.toString()}>
{formatDistanceToNow(datetime, { addSuffix })}
</time>
);
}

0 comments on commit 2eb29b7

Please sign in to comment.