From 127259bccce157e79d29732f2cec4fdfe6ca2a74 Mon Sep 17 00:00:00 2001 From: liaoxinyu Date: Wed, 19 Mar 2025 17:55:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B8=81=E5=B8=81=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E8=87=AA=E5=8A=A8=E5=8C=96=E8=BD=AC=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/exchange/time-sharing.vue | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) 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, }, });