From 0410f6b324ad2ee4fcd7a45d6f679ef02f7243e4 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 28 Sep 2024 06:31:25 +0100 Subject: [PATCH] maybe now?!? --- src/common/model/player/impl/scoresaber-player.ts | 8 ++++++-- src/common/schema/player-schema.ts | 10 ++++++---- src/common/time-utils.ts | 11 +++++++++++ src/components/player/player-rank-chart.tsx | 2 ++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/common/model/player/impl/scoresaber-player.ts b/src/common/model/player/impl/scoresaber-player.ts index d617c95..41bd0bf 100644 --- a/src/common/model/player/impl/scoresaber-player.ts +++ b/src/common/model/player/impl/scoresaber-player.ts @@ -3,7 +3,11 @@ import ScoreSaberPlayerToken from "@/common/model/token/scoresaber/score-saber-p import { PlayerHistory } from "@/common/player/player-history"; import { config } from "../../../../../config"; import ky from "ky"; -import { getDaysAgoDate, getMidnightAlignedDate } from "@/common/time-utils"; +import { + formatDate, + getDaysAgoDate, + getMidnightAlignedDate, +} from "@/common/time-utils"; /** * A ScoreSaber player. @@ -84,7 +88,7 @@ export async function getScoreSaberPlayerFromToken( } if (history) { // Use the latest data for today - history[getMidnightAlignedDate(new Date()).toString()] = { + history[formatDate(getMidnightAlignedDate(new Date()))] = { rank: token.rank, countryRank: token.countryRank, pp: token.pp, diff --git a/src/common/schema/player-schema.ts b/src/common/schema/player-schema.ts index 310f724..925c32f 100644 --- a/src/common/schema/player-schema.ts +++ b/src/common/schema/player-schema.ts @@ -1,6 +1,6 @@ import mongoose, { Document, Schema } from "mongoose"; import { PlayerHistory } from "@/common/player/player-history"; -import { getMidnightAlignedDate } from "@/common/time-utils"; +import { formatDate, getMidnightAlignedDate } from "@/common/time-utils"; import ScoreSaberPlayer from "@/common/model/player/impl/scoresaber-player"; // Interface for Player Document @@ -70,7 +70,7 @@ PlayerSchema.methods.getLastTracked = function (): Date { PlayerSchema.methods.getHistory = function (date: Date): PlayerHistory { return ( - this.statisticHistory.get(getMidnightAlignedDate(date).toUTCString()) || {} + this.statisticHistory.get(formatDate(getMidnightAlignedDate(date))) || {} ); }; @@ -91,8 +91,10 @@ PlayerSchema.methods.setStatisticHistory = function ( if (!this.statisticHistory) { this.statisticHistory = new Map(); } - const alignedDate = getMidnightAlignedDate(date).toUTCString(); - return this.statisticHistory.set(alignedDate, data); + return this.statisticHistory.set( + formatDate(getMidnightAlignedDate(date)), + data, + ); }; PlayerSchema.methods.sortStatisticHistory = function (): Map< diff --git a/src/common/time-utils.ts b/src/common/time-utils.ts index a24e0bd..7cbde10 100644 --- a/src/common/time-utils.ts +++ b/src/common/time-utils.ts @@ -28,6 +28,17 @@ export function timeAgo(input: Date | number) { } } +/** + * Formats the date + * + * @param date the date + */ +export function formatDate(date: Date) { + return date.toLocaleString("en-US", { + timeZone: "Europe/London", + }); +} + /** * Gets the midnight aligned date * diff --git a/src/components/player/player-rank-chart.tsx b/src/components/player/player-rank-chart.tsx index ba404c1..4e3cea2 100644 --- a/src/components/player/player-rank-chart.tsx +++ b/src/components/player/player-rank-chart.tsx @@ -169,6 +169,7 @@ type Props = { }; export default function PlayerRankChart({ player }: Props) { + console.log(player.statisticHistory); if ( player.statisticHistory === undefined || Object.keys(player.statisticHistory).length === 0 @@ -193,6 +194,7 @@ export default function PlayerRankChart({ player }: Props) { // Create labels based on days ago if (daysAgo === 0) { labels.push("Today"); + console.log(dateString); } else if (daysAgo === 1) { labels.push("Yesterday"); } else {