fixbugdate
This commit is contained in:
parent
ae1a562bcb
commit
ab43f5f8b9
@ -18,65 +18,63 @@ export const useStockQuote = createGlobalState(() => {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const options = {
|
const options = {
|
||||||
year: 'numeric',
|
year: 'numeric',
|
||||||
month: 'short',
|
month: 'short',
|
||||||
day: 'numeric',
|
day: 'numeric',
|
||||||
hour: 'numeric',
|
hour: 'numeric',
|
||||||
minute: '2-digit',
|
minute: '2-digit',
|
||||||
hour12: true,
|
hour12: true,
|
||||||
timeZone: 'America/New_York',
|
timeZone: 'America/New_York',
|
||||||
timeZoneName: 'short'
|
timeZoneName: 'short'
|
||||||
};
|
};
|
||||||
|
|
||||||
dayjs.extend(utc)
|
|
||||||
dayjs.extend(timezone)
|
|
||||||
/*
|
|
||||||
美股的常规发行日(交易日)为周一至周五,遇到法定假日则顺延。
|
|
||||||
如果你只需要“上一个交易日”(不考虑法定假日)的情况下
|
|
||||||
获取当前美东时间。
|
|
||||||
如果今天是周一,则上一个交易日为上周五。
|
|
||||||
如果今天是周日,则上一个交易日为上周五。
|
|
||||||
如果今天是周六,则上一个交易日为周五。
|
|
||||||
其他情况,上一个交易日为昨天。
|
|
||||||
*/
|
|
||||||
const getLastTradingDay = () => {
|
|
||||||
const now = dayjs().tz('America/New_York')
|
|
||||||
let lastTradingDay
|
let lastTradingDay
|
||||||
const dayOfWeek = now.day() // 0:周日, 1:周一, ..., 5:周五, 6:周六
|
dayjs.extend(utc)
|
||||||
const isBeforeClose = now.hour() < 16 || (now.hour() === 16 && now.minute() === 0 && now.second() === 0)
|
dayjs.extend(timezone)
|
||||||
|
/*
|
||||||
|
美股的常规发行日(交易日)为周一至周五,遇到法定假日则顺延。
|
||||||
|
如果你只需要“上一个交易日”(不考虑法定假日)的情况下
|
||||||
|
获取当前美东时间。
|
||||||
|
如果今天是周一,则上一个交易日为上周五。
|
||||||
|
如果今天是周日,则上一个交易日为上周五。
|
||||||
|
如果今天是周六,则上一个交易日为周五。
|
||||||
|
其他情况,上一个交易日为昨天。
|
||||||
|
*/
|
||||||
|
|
||||||
if (dayOfWeek === 0) { // 周日
|
const getLastTradingDay = async () => {
|
||||||
// 返回本周五16:00
|
const toDate = dayjs().format('YYYY-MM-DD');
|
||||||
lastTradingDay = now.day(5).hour(16).minute(0).second(0).millisecond(0)
|
const finalFromDate = dayjs().subtract(7, 'day').format('YYYY-MM-DD');
|
||||||
} else if (dayOfWeek === 6) { // 周六
|
let url =
|
||||||
// 返回本周五16:00
|
'https://common.szjixun.cn/api/stock/history/list?from=' +
|
||||||
lastTradingDay = now.day(5).hour(16).minute(0).second(0).millisecond(0);
|
finalFromDate +
|
||||||
} else if (dayOfWeek === 1 && isBeforeClose) { // 周一16:00前
|
'&to=' +
|
||||||
// 返回上周五16:00,使用 subtract 方法减去 3 天
|
toDate;
|
||||||
lastTradingDay = now.subtract(3, 'day').hour(16).minute(0).second(0).millisecond(0)
|
const res = await axios.get(url)
|
||||||
} else if (isBeforeClose) { // 工作日16:00前
|
// console.error(res)
|
||||||
// 返回前一天16:00
|
if (res.status === 200) {
|
||||||
lastTradingDay = now.subtract(1, 'day').hour(16).minute(0).second(0).millisecond(0)
|
if (res.data.status === 0) {
|
||||||
} else {
|
lastTradingDay = dayjs(res.data.data[0].date)
|
||||||
// 工作日16:00后,返回今天16:00
|
}
|
||||||
lastTradingDay = now.hour(16).minute(0).second(0).millisecond(0)
|
return lastTradingDay.format('MMM D, YYYY, h:mm A [EDT]')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return lastTradingDay.format('MMM D, YYYY, h:mm A [EDT]')
|
|
||||||
}
|
|
||||||
|
|
||||||
const formatted = ref(getLastTradingDay())
|
const formatted = ref(null)
|
||||||
const getStockQuate= async()=>{
|
const init = async () => {
|
||||||
// const res = await axios.get('https://saas-test.szjixun.cn/api/fiee/chart/forward/test')
|
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')
|
const res = await axios.get('https://common.szjixun.cn/api/stock/company/data')
|
||||||
// console.error(res)
|
// console.error(res)
|
||||||
if(res.status === 200){
|
if (res.status === 200) {
|
||||||
if(res.data.status === 0){
|
if (res.data.status === 0) {
|
||||||
stockQuote.value=res.data.data
|
stockQuote.value = res.data.data
|
||||||
// console.error(stockQuote.value)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
formatted,
|
formatted,
|
||||||
getStockQuate,
|
getStockQuate,
|
||||||
|
Loading…
Reference in New Issue
Block a user