aboutsummaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorIvan Chen <ivan@tagg.id>2021-05-07 16:55:14 -0400
committerGitHub <noreply@github.com>2021-05-07 16:55:14 -0400
commit893e7bf7a49eb612a975dddae4d792a035b9f420 (patch)
tree25d8200a7479ca14cc1984ebd45c151344d157f3 /src/utils
parent85dbf012ad864a1149939c7eaf43c3ebb56a1853 (diff)
parent679b46ac69149fb93a7a3781fa7f88c53dc77b33 (diff)
Merge pull request #402 from ankit-thanekar007/tma-800-notification-timestamp
[TMA-800] : Added timestamps on notification
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/moments.ts34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils/moments.ts b/src/utils/moments.ts
index 87f062af..90d69519 100644
--- a/src/utils/moments.ts
+++ b/src/utils/moments.ts
@@ -37,3 +37,37 @@ export const getTimePosted = (date_time: string) => {
}
return time;
};
+
+export const getTimeInShorthand = (date_time: string) => {
+ const datePosted = moment(date_time);
+ const now = moment();
+ var time = date_time;
+ var difference = now.diff(datePosted, 's');
+
+ // Creating elapsedTime string to display to user
+ // 0 to less than 1 minute
+ if (difference < 60) {
+ time = difference + 's';
+ }
+ // 1 minute to less than 1 hour
+ else if (difference >= 60 && difference < 60 * 60) {
+ difference = now.diff(datePosted, 'm');
+ time = difference + 'm';
+ }
+ // 1 hour to less than 1 day
+ else if (difference >= 60 * 60 && difference < 24 * 60 * 60) {
+ difference = now.diff(datePosted, 'h');
+ time = difference + 'h';
+ }
+ // Any number of days
+ else if (difference >= 24 * 60 * 60 && difference < 24 * 60 * 60 * 7) {
+ difference = now.diff(datePosted, 'd');
+ time = difference + 'd';
+ }
+ // More than 7 days
+ else if (difference >= 24 * 60 * 60 * 7) {
+ difference = now.diff(datePosted, 'w');
+ time = difference + 'w';
+ }
+ return time;
+};