feat: bugfix
This commit is contained in:
@@ -71,15 +71,19 @@ const RelatedConceptsSection = ({ eventTitle, effectiveTradingDate, eventTime })
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
// 格式化交易日期
|
||||
// 格式化交易日期 - 统一使用 moment 处理
|
||||
let formattedTradeDate;
|
||||
if (typeof effectiveTradingDate === 'string') {
|
||||
formattedTradeDate = effectiveTradingDate;
|
||||
} else if (effectiveTradingDate instanceof Date) {
|
||||
try {
|
||||
// 不管传入的是什么格式,都用 moment 解析并格式化为 YYYY-MM-DD
|
||||
formattedTradeDate = moment(effectiveTradingDate).format('YYYY-MM-DD');
|
||||
} else if (moment.isMoment(effectiveTradingDate)) {
|
||||
formattedTradeDate = effectiveTradingDate.format('YYYY-MM-DD');
|
||||
} else {
|
||||
|
||||
// 验证日期是否有效
|
||||
if (!moment(formattedTradeDate, 'YYYY-MM-DD', true).isValid()) {
|
||||
console.warn('[RelatedConceptsSection] 无效日期,使用当前日期');
|
||||
formattedTradeDate = moment().format('YYYY-MM-DD');
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('[RelatedConceptsSection] 日期格式化失败,使用当前日期', error);
|
||||
formattedTradeDate = moment().format('YYYY-MM-DD');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user