func timeAsString(gotime time.Time, unit units.Unit) string { var dur duration.Duration if !gotime.IsZero() { dur = duration.SinceEpoch(gotime) } return dur.StringUsingUnits(unit) }
func (m *Metric) convertToJson() { m.Value, m.Kind, m.SubType = asJson(m.Value, m.Kind, m.SubType, m.Unit) if m.TimeStamp == nil { m.TimeStamp = "" } else { m.TimeStamp = duration.SinceEpoch(m.TimeStamp.(time.Time)).String() } }
func (e *connectionErrorsType) Set( m *collector.Endpoint, err error, timestamp time.Time) { newError := &messages.Error{ HostName: m.HostName(), Timestamp: duration.SinceEpoch(timestamp).String(), Error: err.Error(), } e.lock.Lock() defer e.lock.Unlock() e.errorMap[m] = newError }
func (m *Metric) convertToJson() { m.Value, m.Kind, m.SubType = asJson(m.Value, m.Kind, m.SubType, m.Unit) switch i := m.TimeStamp.(type) { case nil: m.TimeStamp = "" case time.Time: m.TimeStamp = duration.SinceEpoch(i).String() case string: // Do nothing we are already in json format default: m.TimeStamp = fmt.Sprintf("%v", i) } }
func timeToDuration(t time.Time) (result duration.Duration) { if t.IsZero() { return } return duration.SinceEpoch(t) }