2017-05-06 21:21:39 +02:00
package timeHelper
import (
"time"
2017-07-02 16:54:55 +02:00
"github.com/NyaaPantsu/nyaa/utils/log"
2017-05-06 21:21:39 +02:00
)
2017-05-26 12:12:52 +02:00
// FewDaysLater : Give time now + some days
2017-05-06 21:21:39 +02:00
func FewDaysLater ( day int ) time . Time {
return FewDurationLater ( time . Duration ( day ) * 24 * time . Hour )
}
2017-05-26 12:12:52 +02:00
// TwentyFourHoursLater : Give time now + 24 hours
2017-05-06 21:21:39 +02:00
func TwentyFourHoursLater ( ) time . Time {
return FewDurationLater ( time . Duration ( 24 ) * time . Hour )
}
2017-05-26 12:12:52 +02:00
// SixHoursLater : Give time now + 6 hours
2017-05-06 21:21:39 +02:00
func SixHoursLater ( ) time . Time {
return FewDurationLater ( time . Duration ( 6 ) * time . Hour )
}
2017-05-26 12:12:52 +02:00
// InTimeSpan : check if time given is in the given time encapsulation
2017-05-06 21:21:39 +02:00
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 )
}
2017-05-26 12:12:52 +02:00
// InTimeSpanNow : check if time now is in the given time encapsulation
2017-05-06 21:21:39 +02:00
func InTimeSpanNow ( start , end time . Time ) bool {
now := time . Now ( )
return InTimeSpan ( start , end , now )
}
2017-05-26 12:12:52 +02:00
// FewDurationLater : Give time now + some time duration
2017-05-06 21:21:39 +02:00
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
}
2017-05-26 12:12:52 +02:00
// FewDurationLaterMillisecond : Give time now + some millisecond
2017-05-06 21:21:39 +02:00
func FewDurationLaterMillisecond ( duration time . Duration ) int64 {
return FewDurationLater ( duration ) . UnixNano ( ) / int64 ( time . Millisecond )
}
2017-05-26 12:12:52 +02:00
// IsExpired : check if time given is expired
2017-05-06 21:21:39 +02:00
func IsExpired ( expirationTime time . Time ) bool {
log . Debugf ( "expirationTime : %s" , expirationTime )
after := time . Now ( ) . After ( expirationTime )
log . Debugf ( "after : %t" , after )
return after
}