From 8eb75bf785635edc4948ba6300cb987eaa77781b Mon Sep 17 00:00:00 2001 From: nicolas-arnaud Date: Tue, 14 Mar 2023 10:14:10 +0100 Subject: [PATCH] fix timezone --- .../volume/src/components/MatchHistory.svelte | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/front/volume/src/components/MatchHistory.svelte b/front/volume/src/components/MatchHistory.svelte index 7e0f541..65d8e96 100644 --- a/front/volume/src/components/MatchHistory.svelte +++ b/front/volume/src/components/MatchHistory.svelte @@ -3,7 +3,7 @@ export interface Match { players: Array; score: Array; - date: Date; + date: string; ranked: boolean; } import { API_URL } from "../Auth"; @@ -14,25 +14,25 @@ import { onMount } from "svelte"; export let username: string = "Global"; - function displayDate(str: string) { + function formatDate(str: string) { const splitT = str.split("T"); const splitDate = splitT[0].split("-"); const splitDot = splitT[1].split("."); return `${splitDate[1]}/${splitDate[2]}-${splitDot[0]}`; } - let page = 1; - let data = []; - let newBatch = []; + let page: number = 1; + let data: Array = []; + let newBatch: Array = []; async function fetchData() { + let response; if (username === "Global") { - const response = await fetch(`${API_URL}/globalHistory?page=${page}`, { + response = await fetch(`${API_URL}/globalHistory?page=${page}`, { credentials: "include", mode: "cors", }); - newBatch = (await response.json()).data; } else { - let response = await fetch(`${API_URL}/user/${username}`); + response = await fetch(`${API_URL}/user/${username}`); if (response.ok) { let user = await response.json(); response = await fetch(`${API_URL}/history/${user.ftId}?page=${page}`, { @@ -40,8 +40,21 @@ mode: "cors", }); } - newBatch = (await response.json()).data; } + let tmp = await response.json(); + newBatch = tmp.data.map((match: Match) => { + return { + players: match.players, + score: match.score, + date: + new Date(match.date).toLocaleString("fr-FR", { + timeZone: "Europe/Paris", + dateStyle: "short", + timeStyle: "short", + }), + ranked: match.ranked, + }; + }); page++; } @@ -70,7 +83,7 @@ {#each data as match} - {displayDate(match.date.toString())} + {match.date} {#if match?.players[0]?.username && match?.players[1]?.username} {match.players[0].username}
{match.players[1]