//
// TimestampFromEpoch creates a new Timestamp from the specified time.Time
//
431630
func TimestampFromEpoch(secondsSinceEpoch float64) Timestamp {
	sec := int64(secondsSinceEpoch)
	nsec := int64((secondsSinceEpoch - float64(sec) + 0.0000005) * 1000000000.0)
	return Timestamp{time.Unix(sec, nsec).UTC()}
}
281802
func TimeToTimestamp(t time.Time) *timestamp.Timestamp {
	return &timestamp.Timestamp{
		Seconds: t.UnixNano() / int64(time.Second),
		Nanos:   int32(t.UnixNano() % int64(time.Second)),
	}
}
870941
func GetTimeFromTS(ts uint64) time.Time {
	ms := ExtractPhysical(ts)
	return time.Unix(ms/1e3, (ms%1e3)*1e6)
}
374177
func (c *ChatUpdateCall) Timestamp(timestamp string) *ChatUpdateCall {
	c.timestamp = timestamp
	return c
}
1164995
func (n *Parser) getTimestamp(evMap map[string]interface{}) time.Time {
	var (
		setBothFieldsMsg = "Timestamp format and field must both be set to be used, one was not. Using current time instead."
	)

	// Custom (user-defined) timestamp field/format takes priority over the
	// default parsing behavior. Try that first.
	if n.conf.TimeFieldFormat != "" || n.conf.TimeFieldName != "" {
		if n.conf.TimeFieldFormat == "" || n.conf.TimeFieldName == "" {
			logrus.Debug(setBothFieldsMsg)
			return httime.Now()
		}
		return httime.GetTimestamp(evMap, n.conf.TimeFieldName, n.conf.TimeFieldFormat)
	}

	if _, ok := evMap["time_local"]; ok {
		return httime.GetTimestamp(evMap, "time_local", commonLogFormatTimeLayout)
	}

	if _, ok := evMap["time_iso8601"]; ok {
		return httime.GetTimestamp(evMap, "time_iso8601", iso8601TimeLayout)
	}

	if _, ok := evMap["msec"]; ok {
		return httime.GetTimestamp(evMap, "msec", "")
	}

	return httime.GetTimestamp(evMap, "", "")
}
181555
func (e *eventTimestamper) Time() time.Time {
	e.lock.RLock()
	t := e.timestamp
	e.lock.RUnlock()
	return t
}
439611
func (b *bdpEstimator) timesnap(d [8]byte) {
	if bdpPing.data != d {
		return
	}
	b.sentAt = time.Now()
}
446711
func (c *ReactionsRemoveCall) Timestamp(timestamp string) *ReactionsRemoveCall {
	c.timestamp = timestamp
	return c
}
870126
func Timestamp(t time.Time) uint64 {
	return uint64(t.Unix())*1000 +
		uint64(t.Nanosecond()/int(time.Millisecond))
}
329179
func (b *BatchBuilder) TimestampNamed(name string) *BatchBuilder {
	b.using.TimestampNamed(name)
	return b
}
339179
func (o *pdOracle) GetTimestamp(ctx context.Context) (uint64, error) {
	ts, err := o.getTimestamp(ctx)
	if err != nil {
		return 0, errors.Trace(err)
	}
	o.setLastTS(ts)
	return ts, nil
}
605128
func (b *BatchBuilder) Timestamp(t time.Time) *BatchBuilder {
	b.using.Timestamp(t)
	return b
}
100188
func TimeToTimespec(time time.Time) (ts syscall.Timespec) {
	nsec := int64(0)
	if !time.IsZero() {
		nsec = time.UnixNano()
	}
	return syscall.NsecToTimespec(nsec)
}
985567
func readFileTimestamp(p string) (time.Time, error) {
	b, err := ioutil.ReadFile(p)
	if err != nil {
		if os.IsNotExist(err) {
			err = errors.Wrap(errdefs.ErrNotFound, err.Error())
		}
		return time.Time{}, err
	}

	var t time.Time
	if err := t.UnmarshalText(b); err != nil {
		return time.Time{}, errors.Wrapf(err, "could not parse timestamp file %v", p)
	}

	return t, nil
}
103013
func (c *ChatDeleteCall) Timestamp(timestamp string) *ChatDeleteCall {
	c.timestamp = timestamp
	return c
}
758230
func (p *PushEventCommit) GetTimestamp() Timestamp {
	if p == nil || p.Timestamp == nil {
		return Timestamp{}
	}
	return *p.Timestamp
}
614313
func (stub *ChaincodeStub) GetTxTimestamp() (*timestamp.Timestamp, error) {
	hdr, err := utils.GetHeader(stub.proposal.Header)
	if err != nil {
		return nil, err
	}
	chdr, err := utils.UnmarshalChannelHeader(hdr.ChannelHeader)
	if err != nil {
		return nil, err
	}

	return chdr.GetTimestamp(), nil
}