feat(cp排行榜): 补充星座季度的倒计时

This commit is contained in:
hzj 2026-01-21 18:01:07 +08:00
parent c9d9f31529
commit 4dac4c2562

View File

@ -382,32 +382,63 @@ const startCountdown = () => {
monthlyCountdownTimer = setInterval(getMonthlyCountdown, 1000)
}
// 2195
//
const getNextMonthFirstInBeijing = () => {
const now = new Date()
// - [, ]
const zodiacCutoffDates = [
[1, 20], // : 120
[2, 19], // : 219
[3, 21], // : 321
[4, 20], // : 420
[5, 21], // : 521
[6, 22], // : 622
[7, 23], // : 723
[8, 23], // : 823
[9, 23], // : 923
[10, 23], // : 1023
[11, 22], // : 1122
[12, 22], // : 1222
]
//
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()
// - 219219219
let targetYear = year
//
let targetDate = null
let targetYear = currentYear
// 219
if (month > 1 || (month === 1 && date > 19) || (month === 1 && date === 19 && hour >= 5)) {
// 2195219
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
}
}
// 21
const targetMonth = 1 // 2101
// 120
if (!targetDate) {
targetDate = [1, 20]
targetYear = currentYear + 1
}
// UTC - 2191
// 使Date.UTC""
const targetDateAsBeijing = Date.UTC(targetYear, targetMonth, 19, 5, 0, 0) - 8 * 60 * 60 * 1000
//
// 使Date.UTCUTCUTC
const targetDateAsBeijing =
Date.UTC(targetYear, targetDate[0] - 1, targetDate[1], 5, 0, 0) - 8 * 60 * 60 * 1000
return targetDateAsBeijing
}