diff --git a/pages/exchange/time-sharing.vue b/pages/exchange/time-sharing.vue index 1324d28..b5720a6 100644 --- a/pages/exchange/time-sharing.vue +++ b/pages/exchange/time-sharing.vue @@ -101,10 +101,40 @@ export default { break; } }, + + isDSTByRules() { + const now = new Date(); + const year = now.getUTCFullYear(); + // 计算夏令时开始时间(3月第二个周日 2:00 AM EDT) + const dstStart = this.getNthSunday(year, 2, 2, 2); // 月份从 0 开始(2=3月) + + // 计算夏令时结束时间(11月第一个周日 2:00 AM EST) + const dstEnd = this.getNthSunday(year, 10, 1, 2); // 月份从 0 开始(10=11月) + + return now >= dstStart && now < dstEnd; + }, + + // 辅助函数:获取某年第n个月的第m个周日(月份从0开始) + getNthSunday(year, month, occurrence, hour) { + let date = new Date(year, month, 1); + let count = 0; + + while (true) { + if (date.getDay() === 0) { + if (++count === occurrence) { + date.setHours(hour); + return date; + } + } + date.setDate(date.getDate() + 1); + } + }, + intiChart($box) { + let timeData = this.isDSTByRules() highstock.setOptions({ global: { - timezoneOffset: 4 * 60, + timezoneOffset: timeData ? 16 * 60 : 17 * 60, }, });