about summary refs log tree commit diff
path: root/app/javascript/mastodon/components/relative_timestamp.js
diff options
context:
space:
mode:
Diffstat (limited to 'app/javascript/mastodon/components/relative_timestamp.js')
-rw-r--r--app/javascript/mastodon/components/relative_timestamp.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/javascript/mastodon/components/relative_timestamp.js b/app/javascript/mastodon/components/relative_timestamp.js
new file mode 100644
index 000000000..9c7a8121e
--- /dev/null
+++ b/app/javascript/mastodon/components/relative_timestamp.js
@@ -0,0 +1,20 @@
+import React from 'react';
+import { injectIntl, FormattedRelative } from 'react-intl';
+import PropTypes from 'prop-types';
+
+const RelativeTimestamp = ({ intl, timestamp }) => {
+  const date = new Date(timestamp);
+
+  return (
+    <time dateTime={timestamp} title={intl.formatDate(date, { hour12: false, year: 'numeric', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' })}>
+      <FormattedRelative value={date} />
+    </time>
+  );
+};
+
+RelativeTimestamp.propTypes = {
+  intl: PropTypes.object.isRequired,
+  timestamp: PropTypes.string.isRequired
+};
+
+export default injectIntl(RelativeTimestamp);