You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
562 B
Go
29 lines
562 B
Go
3 years ago
|
package timex
|
||
|
|
||
|
import (
|
||
|
"github.com/jinzhu/now"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
// DayExpire 日期是否过期
|
||
|
// 使用 BeginningOfDay 判断
|
||
|
func DayExpire(nowTime time.Time, src time.Time, forever bool) bool {
|
||
|
if forever {
|
||
|
return false
|
||
|
}
|
||
|
today := now.With(nowTime).BeginningOfDay()
|
||
|
return !today.Before(now.With(src).BeginningOfDay())
|
||
|
}
|
||
|
|
||
|
// DayRemain 剩余天数(包括今天)
|
||
|
func DayRemain(nowTime time.Time, src time.Time, forever bool) int32 {
|
||
|
if forever {
|
||
|
return -1
|
||
|
}
|
||
|
resp := int32(src.YearDay() - nowTime.YearDay())
|
||
|
if resp < 0 {
|
||
|
resp = 0
|
||
|
}
|
||
|
return resp
|
||
|
}
|