Skip to content

Commit

Permalink
time adjusted for timepicker
Browse files Browse the repository at this point in the history
  • Loading branch information
Prakhar-commits committed Mar 20, 2024
1 parent 8724b1d commit 186573a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/components/displayTable/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ const TableRow = ({
const formatTime = (timeString: string): string => {
const time = new Date(timeString);

const localTime = time.toLocaleTimeString("en-US", {
hour: "2-digit",
minute: "2-digit",
hour12: true,
});
return localTime;
const hours = time.getHours();
const minutes = time.getMinutes();
const period = hours >= 12 ? "PM" : "AM";
const formattedHours = hours % 12 || 12;
const formattedMinutes = minutes.toString().padStart(2, "0");

return `${formattedHours}:${formattedMinutes} ${period}`;
};

const startTime = formatTime(start_time!);
Expand Down
6 changes: 5 additions & 1 deletion src/utils/FormInputHandling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ function formatDateForPicker(date: Date): string {
}

function formatTimeForPicker(date: Date): string {
return date.toISOString().split("T")[1].slice(0, 5); // Extracts the time part
const localTime = new Date(
date.getTime() - date.getTimezoneOffset() * 60000
).toISOString();
return localTime.split("T")[1].slice(0, 5);
}

async function getASession(id: number) {
Expand All @@ -35,6 +38,7 @@ async function getASession(id: number) {
const endDate = formatDateForPicker(new Date(data.end_time!));

const startTime = formatTimeForPicker(new Date(data.start_time!));

const endTime = formatTimeForPicker(new Date(data.end_time!));

return {
Expand Down

0 comments on commit 186573a

Please sign in to comment.