Skip to content

Commit e767481

Browse files
committed
fix: dont use timezones to calculate duration
1 parent d59d534 commit e767481

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

scripts/user.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,8 @@ async function openTripHistory() {
505505
</div>
506506
`.trim();
507507

508+
console.log(tripHistory);
509+
508510
// populate the trip list
509511
addTripsToDOM(tripHistory);
510512

@@ -555,8 +557,13 @@ function addTripsToDOM(tripHistory) {
555557
const formattedStartTime = tripDate.toLocaleTimeString("pt");
556558

557559
// Get formatted time
558-
let tripTime = new Date(Date.parse(trip.endDate) - Date.parse(trip.startDate));
559-
const formattedTime = tripTime.getHours() + "h" + tripTime.getMinutes().toString().padStart(2, "0") + "m";
560+
const ms = Date.parse(trip.endDate) - Date.parse(trip.startDate);
561+
const formattedTime =
562+
(ms >= 1000 * 60 * 60 ? Math.floor(ms / (1000 * 60 * 60)) + "h" : "") +
563+
(Math.floor(ms / (1000 * 60)) % 60) +
564+
"m" +
565+
(Math.floor(ms / 1000) % 60) +
566+
"s";
560567

561568
// Get formatted cost
562569
let formattedCost = parseFloat(trip.cost).toFixed(2);

0 commit comments

Comments
 (0)