// StringToTime converts from Unicode Epoch encoded timestamps to the time.Time type.
164615
func stringToTime(s string) (time.Time, error) {
	sec, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		return time.Time{}, err
	}
	return time.Unix(sec, 0), nil
}
411044
func StringToType(s string, p reflect.Type) interface{} {
	switch p {
	case reflects.TypeTime:
		return ToTime(s)
	case reflects.TypeDuration:
		return ToDuration(s)
	default:
		switch p.Kind() {
		case reflect.String:
			return s
		case reflect.Bool:
			return ToBool(s)
		case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
			return ToInt(s)
		case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
			return ToUint(s)
		case reflect.Slice:
			et := p.Elem()
			if et.Kind() == reflect.String {
				return strings.Split(s, ",")
			}
		default:
			panic(errors.New("unsupported type: " + p.Name()))
		}
	}
	return nil
}
761064
func ToTime(i interface{}) time.Time {
	if i == nil {
		return time.Time{}
	}

	if t, ok := i.(int64); ok {
		return time.Unix(t, 0).UTC()
	} else if t, ok := i.(float64); ok {
		return time.Unix(int64(t), 0).UTC()
	} else if t, ok := i.(time.Time); ok {
		return t
	}

	return time.Time{}
}
1087666
func IDToTime(id string) (t time.Time, err error) {
	if id == "" {
		return time.Time{}, nil
	}
	// The first 8 characters in the object ID are a Unix timestamp
	ts, err := strconv.ParseUint(id[:8], 16, 64)
	if err != nil {
		err = errors.Wrapf(err, "ID '%s' failed to convert to timestamp.", id)
	} else {
		t = time.Unix(int64(ts), 0)
	}
	return
}
885258
func (t *Timings) String() string {
	t.mu.Lock()
	defer t.mu.Unlock()

	tm := struct {
		TotalCount int64
		TotalTime  int64
		Histograms map[string]*Histogram
	}{
		t.totalCount,
		t.totalTime,
		t.histograms,
	}
	data, err := json.Marshal(tm)
	if err != nil {
		data, _ = json.Marshal(err.Error())
	}
	return string(data)
}
281802
func TimeToTimestamp(t time.Time) *timestamp.Timestamp {
	return &timestamp.Timestamp{
		Seconds: t.UnixNano() / int64(time.Second),
		Nanos:   int32(t.UnixNano() % int64(time.Second)),
	}
}
213442
func Time(ms uint64) time.Time {
	s := int64(ms / 1e3)
	ns := int64((ms % 1e3) * 1e6)
	return time.Unix(s, ns)
}
1092076
func ToTime(in interface{}) (time.Time, error) {
	switch val := in.(type) {
	case int64:
		return time.Unix(val, 0), nil
	default:
		t, err := cast.ToTimeE(val)
		if err != nil {
			return t, ErrBadType
		}
		return t, nil
	}
}
766137
func (t Time) String() string {
	return fmt.Sprintf("%s (%s since GPS epoch)", time.Time(t).String(), t.TimeSinceGPSEpoch().String())
}
874577
func (e *Encoding) EncodeToString(src []byte) string {
	dst := make([]byte, EncodedLen(len(src)))
	e.Encode(dst, src)
	return string(dst)
}
662539
func (timestamp *Timestamp) Time() time.Time {
	return time.Date(timestamp.Year, time.Month(timestamp.Month), timestamp.Day,
		timestamp.Hour, timestamp.Min, timestamp.Sec, timestamp.NanoSec, time.UTC)
}
827443
func getTime(v interface{}) time.Time {
	sval, ok := v.(string)
	if !ok {
		return time.Time{}
	}
	t, err := time.Parse(time.RFC3339, sval)
	if err != nil {
		return time.Time{}
	}
	return t
}
658795
func (t Time) Time() time.Time {
	return time.Unix(int64(t)/second, (int64(t)%second)*nanosPerTick)
}
590908
func (m *Message) Timestamp() string {
	return m.Message.Time.Format(time.RFC3339)
}
1344856
func timeString(t time.Time, c *color.Color) string {
	return c.SprintfFunc()(t.Format("2006-01-02 15:04 MST"))
}
412345
func EpochToTime(e int) time.Time {
	tm := time.Unix(int64(e), 0)

	return tm
}
271048
func stringToTimeHookFunc() mapstructure.DecodeHookFunc {
	return func(
		f reflect.Type,
		t reflect.Type,
		data interface{}) (interface{}, error) {
		if f.Kind() != reflect.String {
			return data, nil
		}
		if t != reflect.TypeOf(time.Now()) {
			return data, nil
		}

		// Convert it by parsing
		return time.Parse(time.RFC3339, data.(string))
	}
}