From 59d90f15809890da05ede6a04e532da6a7af8d0b Mon Sep 17 00:00:00 2001
From: Shravya Ramesh <shravs1208@gmail.com>
Date: Wed, 21 Apr 2021 10:47:27 -0700
Subject: Moved date string manipulation code to utils

---
 src/components/messages/DateHeader.tsx | 36 ++++++++--------------------------
 1 file changed, 8 insertions(+), 28 deletions(-)

(limited to 'src/components/messages/DateHeader.tsx')

diff --git a/src/components/messages/DateHeader.tsx b/src/components/messages/DateHeader.tsx
index 34cc2d01..cc7dce2c 100644
--- a/src/components/messages/DateHeader.tsx
+++ b/src/components/messages/DateHeader.tsx
@@ -1,36 +1,15 @@
-import moment from 'moment';
 import React from 'react';
 import {View, Text, StyleSheet} from 'react-native';
-import {normalize} from '../../utils';
+import {getFormatedDate, normalize} from '../../utils';
 
-const DateHeader: React.FC = ({date}) => {
-  if (!date) {
-    return null;
-  }
+interface DateHeaderProps {
+  date: object;
+}
 
-  var dateMoment = moment(date).startOf('day');
-  var printDate = '';
-
-  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)) {
-    printDate = 'Today';
-  } else if (YESTERDAY.isSame(dateMoment)) {
-    printDate = 'Yesterday';
-  } else if (dateMoment.isBetween(LAST_7_DAYS, YESTERDAY)) {
-    printDate = dateMoment.format('dddd');
-  } else {
-    if (dateMoment.get('year') === TODAY.get('year')) {
-      printDate = dateMoment.format('MMMM D') + 'th';
-    } else {
-      printDate = dateMoment.format('MMMM D ') + 'th' + dateMoment.get('year');
-    }
-  }
+const DateHeader: React.FC<DateHeaderProps> = ({date}) => {
   return (
-    <View style={{backgroundColor: 'transparent'}}>
-      <Text style={styles.dateHeader}>{printDate}</Text>
+    <View style={styles.dateContainer}>
+      <Text style={styles.dateHeader}>{getFormatedDate(date)}</Text>
     </View>
   );
 };
@@ -43,6 +22,7 @@ const styles = StyleSheet.create({
     textAlign: 'center',
     marginVertical: '5%',
   },
+  dateContainer: {backgroundColor: 'transparent'},
 });
 
 export default DateHeader;
-- 
cgit v1.2.3-70-g09d2

