夏令时优化

This commit is contained in:
hahwu 2025-03-31 10:10:03 +08:00
parent c7a5363a75
commit 534d00a975

View File

@ -30,8 +30,16 @@ func MonthZeroTimestamp() int64 {
func NextZeroTimestampDuration() int64 {
now := time.Now()
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
return midnight.AddDate(0, 0, 1).Unix() - now.Unix()
location := now.Location()
midnight := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, location)
nextMidnight := midnight.AddDate(0, 0, 1)
// Adjust for daylight saving time transitions
_, nowOffset := now.Zone()
_, nextMidnightOffset := nextMidnight.Zone()
offsetDifference := nextMidnightOffset - nowOffset
return nextMidnight.Unix() - now.Unix() + int64(offsetDifference)
}
// 获取距离下个中午十二点时间戳的秒数