refactor code
This commit is contained in:
parent
2a90a0bb6b
commit
4290ac867d
@ -1,60 +1,12 @@
|
|||||||
import {
|
import {
|
||||||
isOpen,
|
|
||||||
isAfterMarketClose,
|
|
||||||
isBeforeMarketOpen,
|
|
||||||
isWeekend,
|
|
||||||
etfTicker,
|
etfTicker,
|
||||||
displayCompanyName,
|
displayCompanyName,
|
||||||
assetType,
|
assetType,
|
||||||
} from "$lib/store";
|
} 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
|
export const load = async ({ data }) => {
|
||||||
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 }) => {
|
|
||||||
etfTicker.set(data?.getParams?.toUpperCase());
|
etfTicker.set(data?.getParams?.toUpperCase());
|
||||||
assetType.set("etf");
|
assetType.set("etf");
|
||||||
displayCompanyName.set(data?.companyName);
|
displayCompanyName.set(data?.companyName);
|
||||||
await checkMarketHour();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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();
|
|
||||||
};
|
|
||||||
@ -1,60 +1,13 @@
|
|||||||
import {
|
import {
|
||||||
isOpen,
|
|
||||||
isAfterMarketClose,
|
|
||||||
isBeforeMarketOpen,
|
|
||||||
isWeekend,
|
|
||||||
stockTicker,
|
stockTicker,
|
||||||
displayCompanyName,
|
displayCompanyName,
|
||||||
assetType,
|
assetType,
|
||||||
} from "$lib/store";
|
} 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
|
export const load = async ({ data }) => {
|
||||||
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 }) => {
|
|
||||||
stockTicker.set(data?.getParams?.toUpperCase());
|
stockTicker.set(data?.getParams?.toUpperCase());
|
||||||
assetType.set("stock");
|
assetType.set("stock");
|
||||||
displayCompanyName.set(data?.companyName);
|
displayCompanyName.set(data?.companyName);
|
||||||
await checkMarketHour();
|
|
||||||
};
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user