Skip to content
This repository was archived by the owner on Aug 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
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
35 changes: 35 additions & 0 deletions src/types/RelativeDateTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react'
import PropTypes from 'prop-types'
import Moment from 'moment'
import DatePart from './DatePart'
import Empty from './Empty'
import {SHORTDATETIME_FORMAT} from '../utils'

/**
* Displays a datetime relative to the current time eg. "4 days ago" or "in 3 hours"
* alongside the datetime passed in
*/
class RelativeDateTime extends React.Component {
static propTypes = {
value: PropTypes.string,
}

render() {
const date = Moment(this.props.value)
const isValid = date.isValid()
if (isValid) {
return (
<div>
<div>
{Moment(this.props.value).fromNow()}
</div>
<div className="text-muted">
<DatePart value={this.props.value} outputFormat={SHORTDATETIME_FORMAT} />
</div>
</div>
)
}
return (<Empty />)
}
}
export default RelativeDateTime
1 change: 1 addition & 0 deletions src/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export DatePart from './DatePart'
export DateTime from './DateTime'
export BooleanType from './BooleanType'
export RelativeDate from './RelativeDate'
export RelativeDateTime from './RelativeDateTime'
export Currency from './Currency'