mirror of
https://gitee.com/wanwujie/sub2api
synced 2026-04-18 05:44:46 +08:00
36 lines
610 B
Go
36 lines
610 B
Go
|
|
package service
|
||
|
|
|
||
|
|
import "time"
|
||
|
|
|
||
|
|
// clampInt 将整数限制在指定范围内
|
||
|
|
func clampInt(value, min, max int) int {
|
||
|
|
if value < min {
|
||
|
|
return min
|
||
|
|
}
|
||
|
|
if value > max {
|
||
|
|
return max
|
||
|
|
}
|
||
|
|
return value
|
||
|
|
}
|
||
|
|
|
||
|
|
// clampFloat64 将浮点数限制在指定范围内
|
||
|
|
func clampFloat64(value, min, max float64) float64 {
|
||
|
|
if value < min {
|
||
|
|
return min
|
||
|
|
}
|
||
|
|
if value > max {
|
||
|
|
return max
|
||
|
|
}
|
||
|
|
return value
|
||
|
|
}
|
||
|
|
|
||
|
|
// remainingSecondsUntil 计算到指定时间的剩余秒数,保证非负
|
||
|
|
func remainingSecondsUntil(t time.Time) int {
|
||
|
|
seconds := int(time.Until(t).Seconds())
|
||
|
|
if seconds < 0 {
|
||
|
|
return 0
|
||
|
|
}
|
||
|
|
return seconds
|
||
|
|
}
|
||
|
|
|