2017-10-25 11:33:19 -05:00
|
|
|
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
|
|
|
// See License.txt for license information.
|
|
|
|
|
|
2015-11-28 14:56:30 +01:00
|
|
|
package utils
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func MillisFromTime(t time.Time) int64 {
|
|
|
|
|
return t.UnixNano() / int64(time.Millisecond)
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-25 15:38:13 +01:00
|
|
|
func TimeFromMillis(millis int64) time.Time {
|
|
|
|
|
return time.Unix(0, millis*int64(time.Millisecond))
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-28 14:56:30 +01:00
|
|
|
func StartOfDay(t time.Time) time.Time {
|
|
|
|
|
year, month, day := t.Date()
|
|
|
|
|
return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func EndOfDay(t time.Time) time.Time {
|
|
|
|
|
year, month, day := t.Date()
|
|
|
|
|
return time.Date(year, month, day, 23, 59, 59, 999999999, t.Location())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Yesterday() time.Time {
|
|
|
|
|
return time.Now().AddDate(0, 0, -1)
|
|
|
|
|
}
|