fixbugdate

This commit is contained in:
qibin 2025-06-01 22:13:56 +08:00
parent ae1a562bcb
commit ab43f5f8b9

View File

@ -28,7 +28,7 @@ const options = {
timeZone: 'America/New_York',
timeZoneName: 'short'
};
let lastTradingDay
dayjs.extend(utc)
dayjs.extend(timezone)
/*
@ -40,32 +40,30 @@ dayjs.extend(timezone)
如果今天是周六则上一个交易日为周五
其他情况上一个交易日为昨天
*/
const getLastTradingDay = () => {
const now = dayjs().tz('America/New_York')
let lastTradingDay
const dayOfWeek = now.day() // 0:周日, 1:周一, ..., 5:周五, 6:周六
const isBeforeClose = now.hour() < 16 || (now.hour() === 16 && now.minute() === 0 && now.second() === 0)
if (dayOfWeek === 0) { // 周日
// 返回本周五16:00
lastTradingDay = now.day(5).hour(16).minute(0).second(0).millisecond(0)
} else if (dayOfWeek === 6) { // 周六
// 返回本周五16:00
lastTradingDay = now.day(5).hour(16).minute(0).second(0).millisecond(0);
} else if (dayOfWeek === 1 && isBeforeClose) { // 周一16:00前
// 返回上周五16:00使用 subtract 方法减去 3 天
lastTradingDay = now.subtract(3, 'day').hour(16).minute(0).second(0).millisecond(0)
} else if (isBeforeClose) { // 工作日16:00前
// 返回前一天16:00
lastTradingDay = now.subtract(1, 'day').hour(16).minute(0).second(0).millisecond(0)
} else {
// 工作日16:00后返回今天16:00
lastTradingDay = now.hour(16).minute(0).second(0).millisecond(0)
const getLastTradingDay = async () => {
const toDate = dayjs().format('YYYY-MM-DD');
const finalFromDate = dayjs().subtract(7, 'day').format('YYYY-MM-DD');
let url =
'https://common.szjixun.cn/api/stock/history/list?from=' +
finalFromDate +
'&to=' +
toDate;
const res = await axios.get(url)
// console.error(res)
if (res.status === 200) {
if (res.data.status === 0) {
lastTradingDay = dayjs(res.data.data[0].date)
}
return lastTradingDay.format('MMM D, YYYY, h:mm A [EDT]')
}
}
const formatted = ref(getLastTradingDay())
const formatted = ref(null)
const init = async () => {
formatted.value = await getLastTradingDay()
}
init()
const getStockQuate = async () => {
// const res = await axios.get('https://saas-test.szjixun.cn/api/fiee/chart/forward/test')
const res = await axios.get('https://common.szjixun.cn/api/stock/company/data')
@ -73,7 +71,7 @@ const getStockQuate= async()=>{
if (res.status === 200) {
if (res.data.status === 0) {
stockQuote.value = res.data.data
// console.error(stockQuote.value)
}
}
}