···1313type TimeStamp int64
14141515var (
1616- // mock is NOT concurrency-safe!!
1717- mock time.Time
1616+ // mockNow is NOT concurrency-safe!!
1717+ mockNow time.Time
18181919 // Used for IsZero, to check if timestamp is the zero time instant.
2020 timeZeroUnix = time.Time{}.Unix()
2121)
22222323-// Set sets the time to a mocked time.Time
2424-func Set(now time.Time) {
2525- mock = now
2323+// MockSet sets the time to a mocked time.Time
2424+func MockSet(now time.Time) {
2525+ mockNow = now
2626}
27272828-// Unset will unset the mocked time.Time
2929-func Unset() {
3030- mock = time.Time{}
2828+// MockUnset will unset the mocked time.Time
2929+func MockUnset() {
3030+ mockNow = time.Time{}
3131}
32323333// TimeStampNow returns now int64
3434func TimeStampNow() TimeStamp {
3535- if !mock.IsZero() {
3636- return TimeStamp(mock.Unix())
3535+ if !mockNow.IsZero() {
3636+ return TimeStamp(mockNow.Unix())
3737 }
3838 return TimeStamp(time.Now().Unix())
3939}
···8989 return ts.AsTimeInLocation(loc).Format(f)
9090}
91919292-// FormatLong formats as RFC1123Z
9393-func (ts TimeStamp) FormatLong() string {
9494- return ts.Format(time.RFC1123Z)
9595-}
9696-9797-// FormatShort formats as short
9898-func (ts TimeStamp) FormatShort() string {
9999- return ts.Format("Jan 02, 2006")
100100-}
101101-102102-// FormatDate formats a date in YYYY-MM-DD server time zone
9292+// FormatDate formats a date in YYYY-MM-DD
10393func (ts TimeStamp) FormatDate() string {
104104- return time.Unix(int64(ts), 0).String()[:10]
9494+ return ts.Format("2006-01-02")
10595}
1069610797// IsZero is zero time