forked from taskcluster/taskcluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
34 lines (30 loc) · 974 Bytes
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Component } from 'react';
import { formatDistance, formatDistanceStrict } from 'date-fns';
import { date } from '../../utils/prop-types';
/**
* Display a human-readable relative string between a date and now.
* Optionally also show a relative distance between that date and an
* additional offset date.
*/
export default class DateDistance extends Component {
static defaultProps = {
offset: null,
};
static propTypes = {
/**
* The origin date for which to render a relative string from now.
*/
from: date.isRequired,
/**
* An optional date for which to also show a relative string between `from`
* and `offset`.
*/
offset: date,
};
render() {
const { from, offset } = this.props;
const fromNow = formatDistanceStrict(from, new Date(), { addSuffix: true });
const offsetNow = offset && formatDistance(from, offset);
return offsetNow ? `${fromNow} (${offsetNow} later)` : fromNow;
}
}