From 08b1b2bfe045599fbac54219cfbf48112a4fa874 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Tue, 17 Dec 2024 23:56:50 +0100 Subject: [PATCH] ui fix --- src/routes/etf/[tickerID]/+page.svelte | 62 +++++++++++----------- src/routes/stocks/[tickerID]/+page.svelte | 63 +++++++++++------------ 2 files changed, 59 insertions(+), 66 deletions(-) diff --git a/src/routes/etf/[tickerID]/+page.svelte b/src/routes/etf/[tickerID]/+page.svelte index b95a3c29..49b9d71e 100644 --- a/src/routes/etf/[tickerID]/+page.svelte +++ b/src/routes/etf/[tickerID]/+page.svelte @@ -483,42 +483,38 @@ //===============================================// function defaultTickMarkFormatter(timePoint, tickMarkType, locale) { - const formatOptions = { - timeZone: "UTC", - }; + const formatOptions = { + timeZone: "UTC", // Ensure UTC time zone + hour12: true, // Use 12-hour format + }; - switch (tickMarkType) { - case 0: // TickMarkType.Year: - formatOptions.year = "numeric"; - break; - case 1: // TickMarkType.Month: - formatOptions.month = "short"; - break; - case 2: // TickMarkType.DayOfMonth: - formatOptions.day = "numeric"; - break; - case 3: // TickMarkType.Time: - formatOptions.hour12 = true; // Use 12-hour clock - formatOptions.hour = "numeric"; // Use numeric hour without leading zero - break; - case 4: // TickMarkType.TimeWithSeconds: - formatOptions.hour12 = true; // Use 12-hour clock - formatOptions.hour = "numeric"; // Use numeric hour without leading zero - formatOptions.minute = "2-digit"; // Always show minutes with leading zero - formatOptions.second = "2-digit"; // Always show seconds with leading zero - break; - default: - // Ensure this default case handles unexpected tickMarkType values - } - if ([3, 4]?.includes(tickMarkType)) { - const date = new Date(timePoint?.timestamp * 1000); - return new Intl.DateTimeFormat(locale, formatOptions)?.format(date); - } else { - const date = new Date(timePoint?.timestamp); - return new Intl.DateTimeFormat(locale, formatOptions)?.format(date); - } + switch (tickMarkType) { + case 0: // TickMarkType.Year: + formatOptions.year = "numeric"; + break; + case 1: // TickMarkType.Month: + formatOptions.month = "short"; + break; + case 2: // TickMarkType.DayOfMonth: + formatOptions.day = "numeric"; + break; + case 3: // TickMarkType.Time: + formatOptions.hour = "numeric"; + break; + case 4: // TickMarkType.TimeWithSeconds: + formatOptions.hour = "numeric"; + formatOptions.minute = "2-digit"; + formatOptions.second = "2-digit"; + break; + default: + return ""; } + // Use 'en-US' to ensure the format '10 PM' + const date = new Date(timePoint.timestamp * 1000); + return new Intl.DateTimeFormat('en-US', formatOptions).format(date); +} + $: options = { width: width, height: height, diff --git a/src/routes/stocks/[tickerID]/+page.svelte b/src/routes/stocks/[tickerID]/+page.svelte index 41b105ec..9ad2ee38 100644 --- a/src/routes/stocks/[tickerID]/+page.svelte +++ b/src/routes/stocks/[tickerID]/+page.svelte @@ -455,42 +455,39 @@ //===============================================// function defaultTickMarkFormatter(timePoint, tickMarkType, locale) { - const formatOptions = { - timeZone: "UTC", - }; + const formatOptions = { + timeZone: "UTC", // Ensure UTC time zone + hour12: true, // Use 12-hour format + }; - switch (tickMarkType) { - case 0: // TickMarkType.Year: - formatOptions.year = "numeric"; - break; - case 1: // TickMarkType.Month: - formatOptions.month = "short"; - break; - case 2: // TickMarkType.DayOfMonth: - formatOptions.day = "numeric"; - break; - case 3: // TickMarkType.Time: - formatOptions.hour12 = true; // Use 12-hour clock - formatOptions.hour = "numeric"; // Use numeric hour without leading zero - break; - case 4: // TickMarkType.TimeWithSeconds: - formatOptions.hour12 = true; // Use 12-hour clock - formatOptions.hour = "numeric"; // Use numeric hour without leading zero - formatOptions.minute = "2-digit"; // Always show minutes with leading zero - formatOptions.second = "2-digit"; // Always show seconds with leading zero - break; - default: - // Ensure this default case handles unexpected tickMarkType values - } - if ([3, 4]?.includes(tickMarkType)) { - const date = new Date(timePoint?.timestamp * 1000); - return new Intl.DateTimeFormat(locale, formatOptions)?.format(date); - } else { - const date = new Date(timePoint?.timestamp); - return new Intl.DateTimeFormat(locale, formatOptions)?.format(date); - } + switch (tickMarkType) { + case 0: // TickMarkType.Year: + formatOptions.year = "numeric"; + break; + case 1: // TickMarkType.Month: + formatOptions.month = "short"; + break; + case 2: // TickMarkType.DayOfMonth: + formatOptions.day = "numeric"; + break; + case 3: // TickMarkType.Time: + formatOptions.hour = "numeric"; + break; + case 4: // TickMarkType.TimeWithSeconds: + formatOptions.hour = "numeric"; + formatOptions.minute = "2-digit"; + formatOptions.second = "2-digit"; + break; + default: + return ""; } + // Use 'en-US' to ensure the format '10 PM' + const date = new Date(timePoint.timestamp * 1000); + return new Intl.DateTimeFormat('en-US', formatOptions).format(date); +} + + $: options = { width: width, height: height,