Skip to content

Commit

Permalink
Merge pull request #98 from calblueprint/monique/time-fix
Browse files Browse the repository at this point in the history
Monique/time fix
  • Loading branch information
BuyankhuuTsCAl authored Apr 23, 2024
2 parents bdf7aea + b1b0de7 commit cbac721
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 45 deletions.
37 changes: 19 additions & 18 deletions src/app/orderConfirmationDelivery/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,21 @@ export default function OrderConfirmationDelivery() {
const searchParams = useSearchParams();
const orderIDFromSearch = searchParams.get('orderID');
const [delivTimes, setDelivTimes] = useState<DeliveryTimes[]>([]);
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

useEffect(() => {
async function fetchProducts() {
const cartItems = (await fetchCartItemsWithQuantityByID(
Expand Down Expand Up @@ -76,24 +91,10 @@ export default function OrderConfirmationDelivery() {
function organizeDelivTime() {
const userGrp = user?.delivery_group == null ? 1 : user?.delivery_group;
const Time = delivTimes[userGrp]?.delivery_time.toLocaleString();
const date =
Time == null ? ['0', '0', '0'] : Time?.substring(0, 10).split('-');
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
];

const dateStr = `${months[Number(date[1]) - 1]} ${date[2]}, ${date[0]}`;
const res: Date = new Date(Time);
const dateStr = `${
months[res.getMonth() - 1]
} ${res.getDate()}, ${res.getFullYear()}`;
return `${dateStr}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/orderPage/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function OrderPage() {
<CenterDiv>
<PageDiv>
<BackButtonDiv>
<BackButton destination="./storefront" />
<BackButton destination="./orderHistory" />
</BackButtonDiv>
<BottomColumnDiv>
<LeftColumnDiv>
Expand Down
45 changes: 19 additions & 26 deletions src/app/orderPageDelivery/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,37 +114,30 @@ export default function OrderPageDelivery() {
function organizeDelivTime() {
const userGrp = user?.delivery_group == null ? 1 : user?.delivery_group;
const Time = delivTimes[userGrp]?.delivery_time.toLocaleString();
const date =
Time == null ? ['0', '0', '0'] : Time?.substring(0, 10).split('-');
const dateStr = `${months[parseInt(date[1], 10) - 1]} ${date[2]}, ${
date[0]
}`;
const res: Date = new Date(Time);
const dateStr = `${
months[res.getMonth() - 1]
} ${res.getDate()}, ${res.getFullYear()}`;
return `${dateStr}`;
}

function organizeOrderDate() {
const Time = order?.created_at.toLocaleString();
const date =
Time == null ? ['0', '0', '0'] : Time?.substring(0, 10).split('-');
const dateStr = `${months[parseInt(date[1], 10) - 1]} ${date[2]}, ${
date[0]
}`;
return `${dateStr}`;
}

function organizeOrderTime() {
const Time = order?.created_at.toLocaleString();

const Time =
order?.created_at == null ? 1 : order?.created_at.toLocaleString();
const res: Date = new Date(Time);
const dateStr = `${
months[res.getMonth() - 1]
} ${res.getDate()}, ${res.getFullYear()}`;
let ampm = 'AM';
const date =
Time == null ? ['00', '00'] : Time?.substring(11, 16).split(':');

if (parseInt(date[0], 10) >= 12) {
date[0] = (parseInt(date[0], 10) - 12).toLocaleString();
let hour = res.getHours();
if (hour > 12) {
hour -= 12;
ampm = 'PM';
} else if (hour === 12) {
ampm = 'PM';
}
const timeStr = `${date[0]}:${date[1]} ${ampm}`;
return `${timeStr}`;
const timeStr = `${hour}:${res.getMinutes()} ${ampm}`;
return [dateStr, timeStr];
}

return (
Expand All @@ -157,8 +150,8 @@ export default function OrderPageDelivery() {
<BackButton destination="./orderHistory" />
<Heading2Bold>Order No. {orderIDFromSearch}</Heading2Bold>
<OutterFavoriteDiv>
<Body1>Order Date: {organizeOrderDate()}</Body1>
<Body1>Order Time: {organizeOrderTime()}</Body1>
<Body1>Order Date: {organizeOrderDate()[0]}</Body1>
<Body1>Order Time: {organizeOrderDate()[1]}</Body1>
<ScrollDiv>
{orders.map(product => (
<FavoriteDiv key={product.id}>
Expand Down
2 changes: 2 additions & 0 deletions src/app/storefront/StoreFrontNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default function StoreFrontNavBar(props: {
const [buttonDisplay, setButtonDisplay] = useState<StorefrontButtons[]>([]);
const [ind, setInd] = useState(0);
let newInd = 0;
const reachedSt = true;
const reachedE = false;
const [reachedStart, setReachedStart] = useState(false);
const [reachedEnd, setReachedEnd] = useState(true);

Expand Down

0 comments on commit cbac721

Please sign in to comment.