Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/util/timeHelper/time_helper.go

48 lignes
1,2 Kio
Go
Brut Vue normale Historique

package timeHelper
import (
"time"
2017-05-17 07:58:40 +02:00
"github.com/NyaaPantsu/nyaa/util/log"
)
func FewDaysLater(day int) time.Time {
return FewDurationLater(time.Duration(day) * 24 * time.Hour)
}
func TwentyFourHoursLater() time.Time {
return FewDurationLater(time.Duration(24) * time.Hour)
}
func SixHoursLater() time.Time {
return FewDurationLater(time.Duration(6) * time.Hour)
}
func InTimeSpan(start, end, check time.Time) bool {
log.Debugf("check after before: %s %t %t\n", check, check.After(start), check.Before(end))
return check.After(start) && check.Before(end)
}
func InTimeSpanNow(start, end time.Time) bool {
now := time.Now()
return InTimeSpan(start, end, now)
}
func FewDurationLater(duration time.Duration) time.Time {
// When Save time should considering UTC
fewDurationLater := time.Now().Add(duration)
log.Debugf("time : %s", fewDurationLater)
return fewDurationLater
}
func FewDurationLaterMillisecond(duration time.Duration) int64 {
return FewDurationLater(duration).UnixNano() / int64(time.Millisecond)
}
func IsExpired(expirationTime time.Time) bool {
log.Debugf("expirationTime : %s", expirationTime)
after := time.Now().After(expirationTime)
log.Debugf("after : %t", after)
return after
}