From 9503e8b45eafa5707deffb6016d2f45b09c0a884 Mon Sep 17 00:00:00 2001 From: liaoxinyu Date: Sun, 9 Mar 2025 23:05:03 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9k=E7=BA=BF=E4=B8=BA=E8=87=AA?= =?UTF-8?q?=E5=8A=A8=E5=88=87=E6=8D=A2=E5=A4=8F=E4=BB=A4=E6=97=B6=E5=92=8C?= =?UTF-8?q?=E5=86=AC=E4=BB=A4=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- static/chart_main/sevencoin.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/static/chart_main/sevencoin.js b/static/chart_main/sevencoin.js index 7fa08ee..29ed30e 100644 --- a/static/chart_main/sevencoin.js +++ b/static/chart_main/sevencoin.js @@ -277,8 +277,17 @@ $(function () { adjustToEasternTime(date) { let timestamp; - // 调整时间为美国东部时间 - timestamp = date - (-28800000)+(new Date(new Date().getTime()).getTimezoneOffset()* 60 * 1000) - 46800000; + // 判断日期是否在夏令时 + const dates = new Date(date); + const isInEDT = this.dateIsInEDT(dates); + // 根据是否在夏令时来调整时间 + if (isInEDT) { + // 在夏令时期间 + timestamp = date - (-28800000)+(new Date(new Date().getTime()).getTimezoneOffset()* 60 * 1000) - 43200000; // 使用43200000毫秒 = 12小时 + } else { + // 在冬令时期间 + timestamp = date - (-28800000)+(new Date(new Date().getTime()).getTimezoneOffset()* 60 * 1000) - 46800000; // 使用46800000毫秒 = 13小时 + } // 创建新的日期对象,并使用调整后的时间戳 const adjustedDate = new Date(timestamp); @@ -288,9 +297,8 @@ $(function () { // 判断日期是否在夏令时(简化的逻辑,实际应用中需要考虑更多的边界情况) dateIsInEDT(date) { const year = date.getUTCFullYear(); - const start = new Date(Date.UTC(year, 2, 13, 7)); // March, 2nd Sunday - const end = new Date(Date.UTC(year, 10, 6, 6)); // November, 1st Sunday - + const start = new Date(Date.UTC(year, 2, 8, 18)); // March, 2nd Sunday + const end = new Date(Date.UTC(year, 10, 3, 18)); // November, 1st Sunday start.setUTCDate(14 - start.getUTCDay()); end.setUTCDate(7 - end.getUTCDay());