summaryrefslogtreecommitdiffstatshomepage
path: root/webui/src/components/Moment.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'webui/src/components/Moment.tsx')
-rw-r--r--webui/src/components/Moment.tsx28
1 files changed, 28 insertions, 0 deletions
diff --git a/webui/src/components/Moment.tsx b/webui/src/components/Moment.tsx
new file mode 100644
index 000000000..4bffbd318
--- /dev/null
+++ b/webui/src/components/Moment.tsx
@@ -0,0 +1,28 @@
+import moment from 'moment';
+
+type Props = {
+ date: moment.MomentInput;
+ format: string;
+ fromNowDuring?: number;
+};
+
+const Moment = ({ date, format, fromNowDuring }: Props) => {
+ let dateString: string | undefined;
+ const dateMoment = moment(date);
+
+ if (fromNowDuring) {
+ const diff = moment().diff(dateMoment, 'ms');
+ if (diff < fromNowDuring) {
+ dateString = dateMoment.fromNow();
+ }
+ }
+
+ // we either are out of range or didn't get asked for fromNow
+ if (dateString === undefined) {
+ dateString = dateMoment.format(format);
+ }
+
+ return <span>{dateString}</span>;
+};
+
+export default Moment;