Skip to content

Commit

Permalink
Merge pull request #113 from Full-Stack-Collective/appt-requested-time
Browse files Browse the repository at this point in the history
Caluculate time between dates for appt requests
  • Loading branch information
Amanda2900 authored Sep 26, 2023
2 parents 11864f5 + 29fd283 commit 160852e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/AdminAppointmentDetailsPopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { Calendar as CalendarIcon } from 'lucide-react';
import { cn } from '@/lib/utils';
import ConfirmationEmailData from '@/types/ConfirmationEmailData';
import PracticeEmailData from '@/types/PracticeEmailData';
import { updateRequestCreatedTime } from '@/utils/times';

type AdminAppointmentDetailsPopupProps = {
open: boolean;
Expand Down Expand Up @@ -94,6 +95,7 @@ const AdminAppointmentDetailsPopup = ({
scheduled_time,
scheduled_by,
is_cancelled,
created_at,
} = clickedAppointment;

const SEVEN_30_AM_IN_MINUTES = 60 * 7.5;
Expand Down Expand Up @@ -249,6 +251,7 @@ const AdminAppointmentDetailsPopup = ({
}
if (!isAppointmentScheduled && !isAppointmentCancelled) {
statusList.push('Waiting');
statusList.push(updateRequestCreatedTime(created_at!));
}

return statusList.map((status, index) => (
Expand Down
31 changes: 31 additions & 0 deletions src/utils/times.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const ONE_DAY_IN_MILLISECONDS = 86400000;
const ONE_HOUR_IN_MILLISECONDS = 3600000;

function getDaysBetweenDates(timeBetween: number) {
const daysBetween = timeBetween / ONE_DAY_IN_MILLISECONDS;
const days =
daysBetween >= 0 ? Math.floor(daysBetween) : Math.ceil(daysBetween);

if (days === 1) return `Requested 1 day ago`;
return `Requested ${days} days ago`;
}

function getHoursBetweenDates(timeBetween: number) {
const hoursBetween = timeBetween / ONE_HOUR_IN_MILLISECONDS;
const hours =
hoursBetween >= 0 ? Math.floor(hoursBetween) : Math.ceil(hoursBetween);

if (hours > 24) return getDaysBetweenDates(timeBetween);

if (hours < 1) return `Requested < 1 hour ago`;
else if (hours === 1) return `Requested 1 hour ago`;
return `Requested ${hours} hours ago`;
}

export function updateRequestCreatedTime(dateCreated: string) {
const today = new Date();
const requestCreated = new Date(dateCreated);
const timeBetween = today.getTime() - requestCreated.getTime();

return getHoursBetweenDates(timeBetween);
}

0 comments on commit 160852e

Please sign in to comment.