// downloadTimestamp is responsible for downloading the timestamp.json
// Timestamps are special in that we ALWAYS attempt to download and only
// use cache if the download fails (and the cache is still valid).
425645
func (c *tufClient) downloadTimestamp() error {
	logrus.Debug("Loading timestamp...")
	role := data.CanonicalTimestampRole
	consistentInfo := c.newBuilder.GetConsistentInfo(role)

	// always get the remote timestamp, since it supersedes the local one
	cachedTS, cachedErr := c.cache.GetSized(role.String(), notary.MaxTimestampSize)
	_, remoteErr := c.tryLoadRemote(consistentInfo, cachedTS)

	// check that there was no remote error, or if there was a network problem
	// If there was a validation error, we should error out so we can download a new root or fail the update
	switch remoteErr.(type) {
	case nil:
		return nil
	case store.ErrMetaNotFound, store.ErrServerUnavailable, store.ErrOffline, store.NetworkError:
		break
	default:
		return remoteErr
	}

	// since it was a network error: get the cached timestamp, if it exists
	if cachedErr != nil {
		logrus.Debug("no cached or remote timestamp available")
		return remoteErr
	}

	logrus.Warn("Error while downloading remote metadata, using cached timestamp - this might not be the latest version available remotely")
	err := c.newBuilder.Load(role, cachedTS, 1, false)
	if err == nil {
		logrus.Debug("successfully verified cached timestamp")
	}
	return err

}
1240109
func ParseDatapointTimestamp(timestamp string) (*time.Time, error) {
	if timestamp == "" {
		return nil, errors.New("Received an empty timestamp")
	}
	parsed, err := time.Parse(time.RFC3339, timestamp)
	if err != nil {
		return nil, err
	}
	return &parsed, nil
}
193006
func (s *UsageRecord) SetTimestamp(v time.Time) *UsageRecord {
	s.Timestamp = &v
	return s
}
1299691
func (s *MetricDatum) SetTimestamp(v time.Time) *MetricDatum {
	s.Timestamp = &v
	return s
}
1048582
func (a *DispatchMouseEventArgs) SetTimestamp(timestamp TimeSinceEpoch) *DispatchMouseEventArgs {
	a.Timestamp = timestamp
	return a
}
875512
func (s *GetCoreDefinitionOutput) SetLastUpdatedTimestamp(v string) *GetCoreDefinitionOutput {
	s.LastUpdatedTimestamp = &v
	return s
}
660158
func (s *LabelDetection) SetTimestamp(v int64) *LabelDetection {
	s.Timestamp = &v
	return s
}
700079
func readTimestamp(ts *timestamp.Timestamp) time.Time {
	t, err := ptypes.Timestamp(ts)
	if err != nil {
		return time.Time{}
	}
	return t
}
663508
func ClockTimestamp(db XODB) (time.Time, error) {
	var err error

	// sql query
	const sqlstr = `SELECT pg_catalog.clock_timestamp()`

	// run query
	var ret time.Time
	XOLog(sqlstr)
	err = db.QueryRow(sqlstr).Scan(&ret)
	if err != nil {
		return time.Time{}, err
	}

	return ret, nil
}
526098
func (s *FileSystemSize) SetTimestamp(v time.Time) *FileSystemSize {
	s.Timestamp = &v
	return s
}
533282
func (a *EmulateTouchFromMouseEventArgs) SetTimestamp(timestamp TimeSinceEpoch) *EmulateTouchFromMouseEventArgs {
	a.Timestamp = timestamp
	return a
}
811161
func (a *DispatchTouchEventArgs) SetTimestamp(timestamp TimeSinceEpoch) *DispatchTouchEventArgs {
	a.Timestamp = timestamp
	return a
}
722607
func ConvertToTimestamp(timeString string) *Timestamp {
	parsed, _ := time.Parse(time.RFC3339Nano, timeString)
	return &Timestamp{parsed}
}
377871
func (s *TrustedAdvisorCheckResult) SetTimestamp(v string) *TrustedAdvisorCheckResult {
	s.Timestamp = &v
	return s
}
177446
func (v *Validator) validTimestamp(ts string) bool {
	t, err := stringToTime(ts)
	if err != nil {
		return false
	}
	diff := time.Now().Add(ValidityWindow / 2).Sub(t)
	return diff < ValidityWindow && diff > 0
}
758230
func (p *PushEventCommit) GetTimestamp() Timestamp {
	if p == nil || p.Timestamp == nil {
		return Timestamp{}
	}
	return *p.Timestamp
}
836135
func (s *Activity) SetTimeStamp(v time.Time) *Activity {
	s.TimeStamp = &v
	return s
}