aboutsummaryrefslogtreecommitdiff
path: root/src/utils/messages.ts
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-04-21 10:47:27 -0700
committerShravya Ramesh <shravs1208@gmail.com>2021-04-21 10:47:27 -0700
commit59d90f15809890da05ede6a04e532da6a7af8d0b (patch)
treebddeb56ac93cd8b114422192b77bfbee7c0eaec8 /src/utils/messages.ts
parentebb59d9632d76b133f226925bbf611df09c7419b (diff)
Moved date string manipulation code to utils
Diffstat (limited to 'src/utils/messages.ts')
-rw-r--r--src/utils/messages.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/messages.ts b/src/utils/messages.ts
index f4215bf0..0e73f639 100644
--- a/src/utils/messages.ts
+++ b/src/utils/messages.ts
@@ -137,3 +137,28 @@ export const createChannel = async (
throw error;
}
};
+
+export const getFormatedDate = (date: object) => {
+ const dateMoment = moment(date).startOf('day');
+ let dateToRender = '';
+
+ const TODAY = moment().startOf('day');
+ const YESTERDAY = moment().subtract(1, 'day').startOf('day');
+ const LAST_7_DAYS = moment().subtract(7, 'day').startOf('day');
+
+ if (TODAY.isSame(dateMoment)) {
+ dateToRender = 'Today';
+ } else if (YESTERDAY.isSame(dateMoment)) {
+ dateToRender = 'Yesterday';
+ } else if (dateMoment.isBetween(LAST_7_DAYS, YESTERDAY)) {
+ dateToRender = dateMoment.format('dddd');
+ } else {
+ if (dateMoment.get('year') === TODAY.get('year')) {
+ dateToRender = dateMoment.format('MMMM D') + 'th';
+ } else {
+ dateToRender =
+ dateMoment.format('MMMM D ') + 'th' + dateMoment.get('year');
+ }
+ }
+ return dateToRender;
+};