Skip to content

Issue #30 Bug: Order Time does not format time correctly, fix(view-orders) zero pad minutes and seconds #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion application/src/components/view-orders/viewOrders.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,33 @@ class ViewOrders extends Component {
<div className="container-fluid">
{this.state.orders.map(order => {
const createdDate = new Date(order.createdAt);
const dateFormatter = new Intl.DateTimeFormat('en-US', {
hour: 'numeric',
minute: 'numeric',
second: 'numeric',
})
const formattedDate = dateFormatter.formatToParts(createdDate);
const timeElements = {
hours: '',
minutes: '',
seconds: ''
}
for (const element of formattedDate) {
let {type, value} = element;
type = `${type}s`;
if (timeElements.hasOwnProperty(type)) {
timeElements[type] = value;
}
}
const {hours, minutes, seconds} = timeElements;
return (
<div className="row view-order-container" key={order._id}>
<div className="col-md-4 view-order-left-col p-3">
<h2>{order.order_item}</h2>
<p>Ordered by: {order.ordered_by || ''}</p>
</div>
<div className="col-md-4 d-flex view-order-middle-col">
<p>Order placed at {`${createdDate.getHours()}:${createdDate.getMinutes()}:${createdDate.getSeconds()}`}</p>
<p>Order placed at {`${hours}:${minutes}:${seconds}`}</p>
<p>Quantity: {order.quantity}</p>
</div>
<div className="col-md-4 view-order-right-col">
Expand Down