github.com/kongr45gpen/mattermost-server@v5.11.1+incompatible/utils/time.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package utils
     5  
     6  import (
     7  	"time"
     8  )
     9  
    10  func MillisFromTime(t time.Time) int64 {
    11  	return t.UnixNano() / int64(time.Millisecond)
    12  }
    13  
    14  func TimeFromMillis(millis int64) time.Time {
    15  	return time.Unix(0, millis*int64(time.Millisecond))
    16  }
    17  
    18  func StartOfDay(t time.Time) time.Time {
    19  	year, month, day := t.Date()
    20  	return time.Date(year, month, day, 0, 0, 0, 0, t.Location())
    21  }
    22  
    23  func EndOfDay(t time.Time) time.Time {
    24  	year, month, day := t.Date()
    25  	return time.Date(year, month, day, 23, 59, 59, 999999999, t.Location())
    26  }
    27  
    28  func Yesterday() time.Time {
    29  	return time.Now().AddDate(0, 0, -1)
    30  }