2020-06-26 10:16:13 +00:00
|
|
|
package entity
|
|
|
|
|
2022-10-03 20:59:29 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
)
|
2020-06-26 10:16:13 +00:00
|
|
|
|
2022-10-03 20:59:29 +00:00
|
|
|
// Day specified as time.Duration to improve readability.
|
2020-06-26 10:16:13 +00:00
|
|
|
const Day = time.Hour * 24
|
|
|
|
|
2022-10-03 20:59:29 +00:00
|
|
|
// UnixHour is one hour in UnixTime.
|
|
|
|
const UnixHour int64 = 3600
|
|
|
|
|
|
|
|
// UnixDay is one day in UnixTime.
|
|
|
|
const UnixDay = UnixHour * 24
|
|
|
|
|
|
|
|
// UnixWeek is one week in UnixTime.
|
|
|
|
const UnixWeek = UnixDay * 7
|
|
|
|
|
2022-10-02 09:38:30 +00:00
|
|
|
// UTC returns the current Coordinated Universal Time (UTC).
|
|
|
|
func UTC() time.Time {
|
|
|
|
return time.Now().UTC()
|
|
|
|
}
|
|
|
|
|
2022-10-03 20:59:29 +00:00
|
|
|
// UnixTime returns the current time in seconds since January 1, 1970 UTC.
|
|
|
|
func UnixTime() int64 {
|
|
|
|
return UTC().Unix()
|
|
|
|
}
|
|
|
|
|
2021-08-29 11:26:05 +00:00
|
|
|
// TimeStamp returns the current timestamp in UTC rounded to seconds.
|
|
|
|
func TimeStamp() time.Time {
|
2022-10-02 09:38:30 +00:00
|
|
|
return UTC().Truncate(time.Second)
|
2020-06-26 10:16:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:26:05 +00:00
|
|
|
// TimePointer returns a pointer to the current timestamp.
|
|
|
|
func TimePointer() *time.Time {
|
|
|
|
t := TimeStamp()
|
2021-08-23 14:22:01 +00:00
|
|
|
return &t
|
|
|
|
}
|
|
|
|
|
2020-06-26 10:16:13 +00:00
|
|
|
// Seconds converts an int to a duration in seconds.
|
|
|
|
func Seconds(s int) time.Duration {
|
|
|
|
return time.Duration(s) * time.Second
|
|
|
|
}
|
2021-01-27 14:17:45 +00:00
|
|
|
|
|
|
|
// Yesterday returns the time 24 hours ago.
|
|
|
|
func Yesterday() time.Time {
|
2022-10-02 09:38:30 +00:00
|
|
|
return UTC().Add(-24 * time.Hour)
|
2021-01-27 14:17:45 +00:00
|
|
|
}
|