// GenerateTimestamp generates a new timestamp given a previous (optional) timestamp
// We can't just load the previous timestamp, because it may have been signed by a different
// timestamp key (maybe from a previous root version)
11886
func (rb *repoBuilder) GenerateTimestamp(prev *data.SignedTimestamp) ([]byte, int, error) {
	switch {
	case rb.repo.cryptoService == nil:
		return nil, 0, ErrInvalidBuilderInput{msg: "cannot generate timestamp without a cryptoservice"}
	case rb.IsLoaded(data.CanonicalTimestampRole):
		return nil, 0, ErrInvalidBuilderInput{msg: "timestamp has already been loaded"}
	}

	// SignTimestamp always serializes the loaded snapshot and signs in the data, so we must always
	// have the snapshot loaded first
	if err := rb.checkPrereqsLoaded([]data.RoleName{data.CanonicalRootRole, data.CanonicalSnapshotRole}); err != nil {
		return nil, 0, err
	}

	switch prev {
	case nil:
		if err := rb.repo.InitTimestamp(); err != nil {
			rb.repo.Timestamp = nil
			return nil, 0, err
		}
	default:
		if err := data.IsValidTimestampStructure(prev.Signed); err != nil {
			return nil, 0, err
		}
		rb.repo.Timestamp = prev
	}

	sgnd, err := rb.repo.SignTimestamp(data.DefaultExpires(data.CanonicalTimestampRole))
	if err != nil {
		rb.repo.Timestamp = nil
		return nil, 0, err
	}

	sgndJSON, err := json.Marshal(sgnd)
	if err != nil {
		rb.repo.Timestamp = nil
		return nil, 0, err
	}

	// The snapshot should have been loaded (and not checksummed, since a timestamp
	// cannot have been loaded), so it is awaiting checksumming. Since this
	// timestamp was generated using the snapshot awaiting checksumming, we can
	// remove it from rb.loadedNotChecksummed. There should be no other items
	// awaiting checksumming now since loading/generating a snapshot should have
	// cleared out everything else in `loadNotChecksummed`.
	delete(rb.loadedNotChecksummed, data.CanonicalSnapshotRole)

	return sgndJSON, rb.repo.Timestamp.Signed.Version, nil
}
432572
func (s *StackEvent) SetTimestamp(v time.Time) *StackEvent {
	s.Timestamp = &v
	return s
}
36747
func (s *MetricData) SetTimestamp(v time.Time) *MetricData {
	s.Timestamp = &v
	return s
}
622065
func LoadTimestamp(t *timestamp.Timestamp, v time.Time) *timestamp.Timestamp {
	if t == nil {
		if v.IsZero() {
			return nil
		}

		t = &timestamp.Timestamp{}
	}

	t.Seconds = v.Unix()
	t.Nanos = int32(v.Nanosecond())
	return t
}
644120
func addTimestamp(buffer *bytes.Buffer) {
	now := now()
	year, month, day := now.Date()
	hour, minute, second := now.Clock()

	var tmp = new([23]byte)
	writeInt(tmp, 4, 0, year)
	tmp[4] = '-'
	writeInt(tmp, 2, 5, int(month))
	tmp[7] = '-'
	writeInt(tmp, 2, 8, day)
	tmp[10] = ' '
	writeInt(tmp, 2, 11, hour)
	tmp[13] = ':'
	writeInt(tmp, 2, 14, minute)
	tmp[16] = ':'
	writeInt(tmp, 2, 17, second)
	tmp[19] = '.'
	writeInt(tmp, 3, 20, now.Nanosecond()/1000000)
	buffer.Write(tmp[:])
}
388860
func (w *WebHookCommit) GetTimestamp() time.Time {
	if w == nil || w.Timestamp == nil {
		return time.Time{}
	}
	return *w.Timestamp
}
542199
func (b *InsertBuilder) Timestamp(t time.Time) *InsertBuilder {
	b.using.Timestamp(t)
	return b
}
1315900
func (b *BackupEngineInfo) GetTimestamp(index int) int64 {
	return int64(C.rocksdb_backup_engine_info_timestamp(b.c, C.int(index)))
}
722607
func ConvertToTimestamp(timeString string) *Timestamp {
	parsed, _ := time.Parse(time.RFC3339Nano, timeString)
	return &Timestamp{parsed}
}
836135
func (s *Activity) SetTimeStamp(v time.Time) *Activity {
	s.TimeStamp = &v
	return s
}
91198
func CreateUtcTimestamp() *timestamp.Timestamp {
	now := time.Now().UTC()
	secs := now.Unix()
	nanos := int32(now.UnixNano() - (secs * 1000000000))
	return &(timestamp.Timestamp{Seconds: secs, Nanos: nanos})
}
1048582
func (a *DispatchMouseEventArgs) SetTimestamp(timestamp TimeSinceEpoch) *DispatchMouseEventArgs {
	a.Timestamp = timestamp
	return a
}
793820
func (ne *NodeEvent) SetTimestamp(ts time.Time) *NodeEvent {
	ne.Timestamp = ts
	return ne
}
919193
func (s *AlarmHistoryItem) SetTimestamp(v time.Time) *AlarmHistoryItem {
	s.Timestamp = &v
	return s
}
998703
func (s *TelemetryRecord) SetTimestamp(v time.Time) *TelemetryRecord {
	s.Timestamp = &v
	return s
}
161015
func CreateTimestamp(time_point []string) Timestamp {
	year, _ := strconv.Atoi(time_point[0])
	month, _ := strconv.Atoi(time_point[1])
	day, _ := strconv.Atoi(time_point[2])
	hour, _ := strconv.Atoi(time_point[3])
	min, _ := strconv.Atoi(time_point[4])
	sec, milliSec, microSec, nanoSec, picoSec := secondFragments(time_point[5])

	return Timestamp{
		Year:     year,
		Month:    month,
		Day:      day,
		Hour:     hour,
		Min:      min,
		Sec:      sec,
		MilliSec: milliSec,
		MicroSec: microSec,
		NanoSec:  nanoSec,
		PicoSec:  picoSec,
	}
}
1260943
func (s *CelebrityRecognition) SetTimestamp(v int64) *CelebrityRecognition {
	s.Timestamp = &v
	return s
}