From 4dac4c2562c977a570581c0ec28f57aae8f2faf1 Mon Sep 17 00:00:00 2001 From: hzj <1304805162@qq.com> Date: Wed, 21 Jan 2026 18:01:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(cp=E6=8E=92=E8=A1=8C=E6=A6=9C):=20?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=98=9F=E5=BA=A7=E5=AD=A3=E5=BA=A6=E7=9A=84?= =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Ranking/Couple/Ranking.vue | 63 +++++++++++++++++++++------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/views/Ranking/Couple/Ranking.vue b/src/views/Ranking/Couple/Ranking.vue index 8093aa2..80bc055 100644 --- a/src/views/Ranking/Couple/Ranking.vue +++ b/src/views/Ranking/Couple/Ranking.vue @@ -382,32 +382,63 @@ const startCountdown = () => { monthlyCountdownTimer = setInterval(getMonthlyCountdown, 1000) } -// 获取2月19号早上5点的北京时间 +// 获取下一个星座周期的截止时间 const getNextMonthFirstInBeijing = () => { const now = new Date() + // 北京时间星座周期截止日期配置 - [月, 日] + const zodiacCutoffDates = [ + [1, 20], // 摩羯座到水瓶座: 1月20日 + [2, 19], // 水瓶座到双鱼座: 2月19日 + [3, 21], // 双鱼座到白羊座: 3月21日 + [4, 20], // 白羊座到金牛座: 4月20日 + [5, 21], // 金牛座到双子座: 5月21日 + [6, 22], // 双子座到巨蟹座: 6月22日 + [7, 23], // 巨蟹座到狮子座: 7月23日 + [8, 23], // 狮子座到处女座: 8月23日 + [9, 23], // 处女座到天秤座: 9月23日 + [10, 23], // 天秤座到天蝎座: 10月23日 + [11, 22], // 天蝎座到射手座: 11月22日 + [12, 22], // 射手座到摩羯座: 12月22日 + ] + // 获取当前的北京时间 const beijingTime = new Date(now.getTime() + 8 * 60 * 60 * 1000) - const year = beijingTime.getUTCFullYear() - const month = beijingTime.getUTCMonth() - const date = beijingTime.getUTCDate() - const hour = beijingTime.getUTCHours() + const currentYear = beijingTime.getUTCFullYear() + const currentMonth = beijingTime.getUTCMonth() + 1 // 月份从1开始 + const currentDate = beijingTime.getUTCDate() + const currentHour = beijingTime.getUTCHours() - // 确定目标年份 - 如果当前时间在本年度2月19日之前,则目标是今年2月19日;否则是明年2月19日 - let targetYear = year + // 查找当前属于哪个星座周期 + let targetDate = null + let targetYear = currentYear - // 检查是否已经超过今年的2月19日 - if (month > 1 || (month === 1 && date > 19) || (month === 1 && date === 19 && hour >= 5)) { - // 如果当前时间已经超过今年的2月19日5点,则目标是明年的2月19日 - targetYear = year + 1 + // 获取本年度的截止时间 + for (let i = 0; i < zodiacCutoffDates.length; i++) { + const [cutoffMonth, cutoffDate] = zodiacCutoffDates[i] + + // 如果当前日期在某个星座周期内,则返回下一个周期的截止日期 + if ( + currentMonth < cutoffMonth || + (currentMonth === cutoffMonth && currentDate < cutoffDate) || + (currentMonth === cutoffMonth && currentDate === cutoffDate && currentHour < 5) + ) { + // 当前时间处于当前年份的该星座周期内 + targetDate = [cutoffMonth, cutoffDate] + break + } } - // 目标月份固定为2月(月份索引为1) - const targetMonth = 1 // 2月的索引是1(0是1月) + // 如果仍未找到,说明当前是年末的摩羯座周期,需要找下一年的1月20日 + if (!targetDate) { + targetDate = [1, 20] + targetYear = currentYear + 1 + } - // 创建代表北京时间的UTC时间戳 - 2月19号而不是1号 - // 使用Date.UTC创建代表"北京时间"的时间戳 - const targetDateAsBeijing = Date.UTC(targetYear, targetMonth, 19, 5, 0, 0) - 8 * 60 * 60 * 1000 + // 创建目标日期(北京时间) + // 使用Date.UTC创建UTC时间,然后减去时差转换为UTC时间 + const targetDateAsBeijing = + Date.UTC(targetYear, targetDate[0] - 1, targetDate[1], 5, 0, 0) - 8 * 60 * 60 * 1000 return targetDateAsBeijing }