From bde4b74acc1e211a5f887a56d0ba5010385b8dbf Mon Sep 17 00:00:00 2001
From: Shravya Ramesh <shravs1208@gmail.com>
Date: Tue, 20 Apr 2021 15:35:17 -0700
Subject: Moved code to components

---
 src/components/messages/DateHeader.tsx | 48 ++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 src/components/messages/DateHeader.tsx

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

diff --git a/src/components/messages/DateHeader.tsx b/src/components/messages/DateHeader.tsx
new file mode 100644
index 00000000..34cc2d01
--- /dev/null
+++ b/src/components/messages/DateHeader.tsx
@@ -0,0 +1,48 @@
+import moment from 'moment';
+import React from 'react';
+import {View, Text, StyleSheet} from 'react-native';
+import {normalize} from '../../utils';
+
+const DateHeader: React.FC = ({date}) => {
+  if (!date) {
+    return null;
+  }
+
+  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');
+    }
+  }
+  return (
+    <View style={{backgroundColor: 'transparent'}}>
+      <Text style={styles.dateHeader}>{printDate}</Text>
+    </View>
+  );
+};
+
+const styles = StyleSheet.create({
+  dateHeader: {
+    color: '#7A7A7A',
+    fontWeight: '600',
+    fontSize: normalize(11),
+    textAlign: 'center',
+    marginVertical: '5%',
+  },
+});
+
+export default DateHeader;
-- 
cgit v1.2.3-70-g09d2

