Fixed: Modified time display on dashboard

New Time component for relative time formatting with accessibility
This commit is contained in:
Tom Moor
2018-07-01 19:56:58 -07:00
parent 933fa9732c
commit 2fd8b35ca9
5 changed files with 56 additions and 49 deletions

20
shared/components/Time.js Normal file
View File

@ -0,0 +1,20 @@
// @flow
import * as React from 'react';
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
import format from 'date-fns/format';
type Props = {
dateTime: string,
children?: React.Node,
};
function Time({ dateTime, children }: Props) {
const date = new Date(dateTime);
return (
<time dateTime={dateTime} title={format(date, 'MMMM Do, YYYY h:mm a')}>
{children || distanceInWordsToNow(date)}
</time>
);
}
export default Time;