Skip to content

High performance, self-hosted, newsletter and mailing list manager with a modern dashboard. Single binary app.

Refactor UI time diff display function to prefix '-' on past dates.

Kailash Nadhfbc27ae4b256
diff --git a/frontend/src/utils.js b/frontend/src/utils.js
index 68c05a12..7d7a9dd0 100644
--- a/frontend/src/utils.js
+++ b/frontend/src/utils.js
@@ -68,7 +68,15 @@ export default class Utils {
return out;
};
- duration = (start, end) => dayjs(end).from(dayjs(start), true);
+ duration = (start, end) => {
+ const a = dayjs(start);
+ const b = dayjs(end);
+
+ // Get the duration string, eg: "2 days".
+ const diff = b.from(a, true);
+
+ return `${b.isBefore(a) ? '-' : ''}${diff}`;
+ };
// Simple, naive, e-mail address check.
validateEmail = (e) => e.match(reEmail);