Files
bd-server/pkg/lzkit/lzUtils/time.go
2026-05-08 11:30:05 +08:00

29 lines
663 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package lzUtils
import (
"database/sql"
"time"
)
// RenewMembership 延长会员有效期
// 规则如果旧到期时间还没过在旧到期时间上续1年如果已过期或为空从当前时间起算1年
func RenewMembership(expiry sql.NullTime) sql.NullTime {
now := time.Now()
var baseTime time.Time
if expiry.Valid && expiry.Time.After(now) {
// 未过期 → 在旧到期时间上续1年
baseTime = expiry.Time
} else {
// 已过期或为空 → 从现在开始算1年
baseTime = now
}
// 增加一年(自动处理闰年)
newTime := baseTime.AddDate(1, 0, 0)
return sql.NullTime{
Time: newTime,
Valid: true,
}
}