This repository was archived by the owner on Aug 4, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import Moment from 'moment'
4
+ import DatePart from './DatePart'
5
+ import Empty from './Empty'
6
+ import { SHORTDATETIME_FORMAT } from '../utils'
7
+
8
+ /**
9
+ * Displays a datetime relative to the current time eg. "4 days ago" or "in 3 hours"
10
+ * alongside the datetime passed in
11
+ */
12
+ class RelativeDateTime extends React . Component {
13
+ static propTypes = {
14
+ value : PropTypes . string ,
15
+ }
16
+
17
+ render ( ) {
18
+ const date = Moment ( this . props . value )
19
+ const isValid = date . isValid ( )
20
+ if ( isValid ) {
21
+ return (
22
+ < div >
23
+ < div >
24
+ { Moment ( this . props . value ) . fromNow ( ) }
25
+ </ div >
26
+ < div className = "text-muted" >
27
+ < DatePart value = { this . props . value } outputFormat = { SHORTDATETIME_FORMAT } />
28
+ </ div >
29
+ </ div >
30
+ )
31
+ }
32
+ return ( < Empty /> )
33
+ }
34
+ }
35
+ export default RelativeDateTime
Original file line number Diff line number Diff line change @@ -7,4 +7,5 @@ export DatePart from './DatePart'
7
7
export DateTime from './DateTime'
8
8
export BooleanType from './BooleanType'
9
9
export RelativeDate from './RelativeDate'
10
+ export RelativeDateTime from './RelativeDateTime'
10
11
export Currency from './Currency'
You can’t perform that action at this time.
0 commit comments