14378fbf39
* Checkpoint: it builds The config, db, model, network, os, and public packages have had some fixes to glaringly obvious flaws, dead code removed, and stylistic changes. * Style changes and old code removal in router Router needs a lot of work done to its (lack of) error handling. * Dead code removal and style changes Now up to util/email/email.go. After I'm finished with the initial sweep I'll go back and fix error handling and security issues. Then I'll fix the broken API. Then I'll go through to add documentation and fix code visibility. * Finish dead code removal and style changes Vendored libraries not touched. Everything still needs security fixes and documentation. There's also one case of broken functionality. * Fix accidental find-and-replace * Style, error checking, saftey, bug fix changes * Redo error checking erased during merge * Re-add merge-erased fix. Make Safe safe.
47 lignes
1,2 Kio
Go
47 lignes
1,2 Kio
Go
package timeHelper
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/ewhal/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
|
|
}
|