From 4290ac867d2711d3e334f38fdb0a308d37176737 Mon Sep 17 00:00:00 2001 From: MuslemRahimi Date: Wed, 27 Nov 2024 22:23:27 +0100 Subject: [PATCH] refactor code --- src/routes/etf/[tickerID]/+layout.ts | 50 +------------------------ src/routes/options-flow/+page.ts | 46 ----------------------- src/routes/stocks/[tickerID]/+layout.ts | 49 +----------------------- 3 files changed, 2 insertions(+), 143 deletions(-) delete mode 100644 src/routes/options-flow/+page.ts diff --git a/src/routes/etf/[tickerID]/+layout.ts b/src/routes/etf/[tickerID]/+layout.ts index 0f19dcab..42a25e60 100644 --- a/src/routes/etf/[tickerID]/+layout.ts +++ b/src/routes/etf/[tickerID]/+layout.ts @@ -1,60 +1,12 @@ import { - isOpen, - isAfterMarketClose, - isBeforeMarketOpen, - isWeekend, etfTicker, displayCompanyName, assetType, } from "$lib/store"; -const checkMarketHour = async () => { - const holidays = [ - "2024-01-01", - "2024-01-15", - "2024-02-19", - "2024-03-29", - "2024-05-27", - "2024-06-19", - "2024-07-04", - "2024-09-02", - "2024-11-28", - "2024-12-25", - ]; - const currentDate = new Date().toISOString().split("T")[0]; - // Get the current time in the ET time zone - const etTimeZone = "America/New_York"; - const currentTime = new Date().toLocaleString("en-US", { - timeZone: etTimeZone, - }); - - // Determine if the NYSE is currently open or closed - const currentHour = new Date(currentTime).getHours(); - const isWeekendValue = - new Date(currentTime).getDay() === 6 || - new Date(currentTime).getDay() === 0; - const isBeforeMarketOpenValue = - currentHour < 9 || - (currentHour === 9 && new Date(currentTime).getMinutes() < 30); - const isAfterMarketCloseValue = currentHour >= 16; - - isOpen.set( - !( - isWeekendValue || - isBeforeMarketOpenValue || - isAfterMarketCloseValue || - holidays?.includes(currentDate) - ), - ); - isWeekend.set(isWeekendValue); - isBeforeMarketOpen.set(isBeforeMarketOpenValue); - isAfterMarketClose.set(isAfterMarketCloseValue); -}; - -export const load = async ({ data }) => { +export const load = async ({ data }) => { etfTicker.set(data?.getParams?.toUpperCase()); assetType.set("etf"); displayCompanyName.set(data?.companyName); - await checkMarketHour(); }; diff --git a/src/routes/options-flow/+page.ts b/src/routes/options-flow/+page.ts deleted file mode 100644 index 2dc6fe35..00000000 --- a/src/routes/options-flow/+page.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { isOpen } from "$lib/store"; - -const checkMarketHour = async () => { - const holidays = [ - "2024-01-01", - "2024-01-15", - "2024-02-19", - "2024-03-29", - "2024-05-27", - "2024-06-19", - "2024-07-04", - "2024-09-02", - "2024-11-28", - "2024-12-25", - ]; - const currentDate = new Date().toISOString().split("T")[0]; - - // Get the current time in the ET time zone - const etTimeZone = "America/New_York"; - const currentTime = new Date().toLocaleString("en-US", { - timeZone: etTimeZone, - }); - - // Determine if the NYSE is currently open or closed - const currentHour = new Date(currentTime).getHours(); - const isWeekendValue = - new Date(currentTime).getDay() === 6 || - new Date(currentTime).getDay() === 0; - const isBeforeMarketOpenValue = - currentHour < 9 || - (currentHour === 9 && new Date(currentTime).getMinutes() < 30); - const isAfterMarketCloseValue = currentHour >= 16; - - isOpen.set( - !( - isWeekendValue || - isBeforeMarketOpenValue || - isAfterMarketCloseValue || - holidays?.includes(currentDate) - ) - ); -}; - -export const load = async () => { - await checkMarketHour(); -}; diff --git a/src/routes/stocks/[tickerID]/+layout.ts b/src/routes/stocks/[tickerID]/+layout.ts index 208e5b77..89a1d1e4 100644 --- a/src/routes/stocks/[tickerID]/+layout.ts +++ b/src/routes/stocks/[tickerID]/+layout.ts @@ -1,60 +1,13 @@ import { - isOpen, - isAfterMarketClose, - isBeforeMarketOpen, - isWeekend, stockTicker, displayCompanyName, assetType, } from "$lib/store"; -const checkMarketHour = async () => { - const holidays = [ - "2024-01-01", - "2024-01-15", - "2024-02-19", - "2024-03-29", - "2024-05-27", - "2024-06-19", - "2024-07-04", - "2024-09-02", - "2024-11-28", - "2024-12-25", - ]; - const currentDate = new Date().toISOString().split("T")[0]; - // Get the current time in the ET time zone - const etTimeZone = "America/New_York"; - const currentTime = new Date().toLocaleString("en-US", { - timeZone: etTimeZone, - }); - // Determine if the NYSE is currently open or closed - const currentHour = new Date(currentTime).getHours(); - const isWeekendValue = - new Date(currentTime).getDay() === 6 || - new Date(currentTime).getDay() === 0; - const isBeforeMarketOpenValue = - currentHour < 9 || - (currentHour === 9 && new Date(currentTime).getMinutes() < 30); - const isAfterMarketCloseValue = currentHour >= 16; - - isOpen.set( - !( - isWeekendValue || - isBeforeMarketOpenValue || - isAfterMarketCloseValue || - holidays?.includes(currentDate) - ), - ); - isWeekend.set(isWeekendValue); - isBeforeMarketOpen.set(isBeforeMarketOpenValue); - isAfterMarketClose.set(isAfterMarketCloseValue); -}; - -export const load = async ({ params, data }) => { +export const load = async ({ data }) => { stockTicker.set(data?.getParams?.toUpperCase()); assetType.set("stock"); displayCompanyName.set(data?.companyName); - await checkMarketHour(); }; \ No newline at end of file