Skip to content

Commit

Permalink
format the date/time correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
KamogeloMoeketse committed Jul 22, 2024
1 parent 3c8e1c6 commit aa2939a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions frontend/occupi-mobile4/screens/Notifications/Notifications.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ const Notifications = () => {

const formatNotificationDate = (sendTime) => {
const now = new Date();
// console.log(now);
const notificationDate = new Date(sendTime);
console.log(notificationDate);

const differenceInHours = Math.floor((now - notificationDate) / (1000 * 60 * 60));
const differenceInDays = Math.floor(differenceInHours / 24);

if (differenceInDays === 0) {
console.log(differenceInDays);
return differenceInHours < 1 ? 'less than an hour ago' : `${differenceInHours} hours ago`;
} else if (differenceInDays === 1) {
return 'yesterday';
Expand All @@ -46,7 +49,7 @@ const Notifications = () => {
notifications.forEach(notification => {
const formattedDate = formatNotificationDate(notification.send_time);

if (formattedDate.includes('hours ago')) {
if (formattedDate.includes('hours ago') || formattedDate.includes('hour ago')) {
todayNotifications.push(notification);
} else if (formattedDate === 'yesterday') {
yesterdayNotifications.push(notification);
Expand All @@ -61,11 +64,6 @@ const Notifications = () => {
const getNotifications = async () => {
let userEmail = await SecureStore.getItemAsync('Email');
let authToken = await SecureStore.getItemAsync('Token');
// const baseUrl = 'https://dev.occupi.tech/api/get-notifications';
const params = new URLSearchParams();
params.append('filter', '{"emails":["[email protected]"]}');

// const url = `${baseUrl}?${params.toString()}`;

try {
const response = await axios.get('https://dev.occupi.tech/api/get-notifications', {
Expand Down
6 changes: 4 additions & 2 deletions frontend/occupi-mobile4/screens/Office/BookingDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ const BookingDetails = () => {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': `${authToken}`
'Authorization': `${authToken}`,
'X-Timezone': 'Africa/Johannesburg'
},
body: JSON.stringify(body),
credentials: "include"
Expand All @@ -122,7 +123,8 @@ const BookingDetails = () => {
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'Authorization': `${authToken}`
'Authorization': `${authToken}`,
'X-Timezone': 'Africa/Johannesburg'
},
credentials: "include"
});
Expand Down

0 comments on commit aa2939a

Please sign in to comment.