...

Source file src/github.com/launchdarkly/go-sdk-common/v3/ldtime/unix_millis.go

Documentation: github.com/launchdarkly/go-sdk-common/v3/ldtime

     1  package ldtime
     2  
     3  import "time"
     4  
     5  // UnixMillisecondTime is a millisecond timestamp starting from the Unix epoch.
     6  type UnixMillisecondTime uint64
     7  
     8  // UnixMillisFromTime converts a Time value into UnixMillisecondTime.
     9  func UnixMillisFromTime(t time.Time) UnixMillisecondTime {
    10  	ms := time.Duration(t.UnixNano()) / time.Millisecond
    11  	return UnixMillisecondTime(ms)
    12  }
    13  
    14  // UnixMillisNow returns the current date/time as a UnixMillisecondTime.
    15  func UnixMillisNow() UnixMillisecondTime {
    16  	return UnixMillisFromTime(time.Now())
    17  }
    18  
    19  // IsDefined returns true if the time value is non-zero.
    20  //
    21  // This can be used to treat a zero value as "undefined" as an alternative to using a pointer,
    22  // assuming that the exact beginning of the Unix epoch itself is not a valid time in this context.
    23  func (t UnixMillisecondTime) IsDefined() bool {
    24  	return t > 0
    25  }
    26  

View as plain text