aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.ts
diff options
context:
space:
mode:
authorIvan Chen <ivan@thetaggid.com>2020-12-29 20:21:24 -0500
committerGitHub <noreply@github.com>2020-12-29 20:21:24 -0500
commitbd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 (patch)
treeac7219e034a0c4035096c6df8dbe6b92446b5111 /src/utils/common.ts
parentec478d4981c726856485b49b49ac33b0d9e6a903 (diff)
[TMA-461] Notifications Screen (#151)
* renamed ProfileStack to MainStack, created initial notifications data type * cleaned up code * added notifications to redux * finished sectioned list * updated types to make more sense * finished sectioned notifications by date * updated notification type and tested mock backend integration * finished read or unread logic * minor changes * another minor fix * finished integration * moved stuff * added ability to navigate to user profile Co-authored-by: Husam Salhab <47015061+hsalhab@users.noreply.github.com>
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r--src/utils/common.ts19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts
index ae83ad9c..27411149 100644
--- a/src/utils/common.ts
+++ b/src/utils/common.ts
@@ -1,3 +1,4 @@
+import moment from 'moment';
import {Linking} from 'react-native';
import {BROWSABLE_SOCIAL_URLS, TOGGLE_BUTTON_TYPE} from '../constants';
@@ -23,3 +24,21 @@ export const handleOpenSocialUrlOnBrowser = (
Linking.openURL(BROWSABLE_SOCIAL_URLS[social] + `${handle}/`);
}
};
+
+export const getDateAge: (
+ date: moment.Moment,
+) => 'today' | 'yesterday' | 'thisWeek' | 'unknown' = (date: moment.Moment) => {
+ const today = moment().startOf('day');
+ const yesterday = moment().subtract(1, 'days').startOf('day');
+ const weekOld = moment().subtract(7, 'days').startOf('day');
+ if (date.isSame(today, 'd')) {
+ return 'today';
+ } else if (date.isSame(yesterday, 'd')) {
+ return 'yesterday';
+ } else if (date.isAfter(weekOld)) {
+ return 'thisWeek';
+ } else {
+ // this can be longer than a week or in the future
+ return 'unknown';
+ }
+};