// MillisecondsTimeValue converts an int64 pointer to a time.Time value
// representing milliseconds sinch Epoch or time.Time{} if the pointer is nil.
487151
func MillisecondsTimeValue(v *int64) time.Time {
	if v != nil {
		return time.Unix(0, (*v * 1000000))
	}
	return time.Time{}
}
503724
func (ns *NamedStopwatch) ElapsedMilliSeconds(name string) float64 {
	if ns == nil {
		return float64(0)
	}
	ns.RLock()
	defer ns.RUnlock()

	if s, ok := ns.stopwatches[name]; ok {
		return s.ElapsedMilliSeconds()
	}
	return float64(0)
}
603194
func (t TimeSinceEpoch) Time() time.Time {
	ts := float64(t) / 1
	secs := int64(ts)
	nsecs := int64((ts - float64(secs)) * 1000000000)
	return time.Unix(secs, nsecs)
}
531072
func (s *TypedAttributeValue) SetDatetimeValue(v time.Time) *TypedAttributeValue {
	s.DatetimeValue = &v
	return s
}
750295
func (tu Unit) Value() (time.Duration, error) {
	if d, found := unitsToDuration[tu]; found {
		return d, nil
	}
	return 0, errUnrecognizedTimeUnit
}
264745
func (d *Decoder) parseValue(v reflect.Value) (bool, error) {
	// we support one level of indirection at the moment
	if v.Kind() == reflect.Ptr {
		// if the pointer is nil, allocate a new element of the type it
		// points to
		if v.IsNil() {
			v.Set(reflect.New(v.Type().Elem()))
		}
		v = v.Elem()
	}

	if d.parseUnmarshaler(v) {
		return true, nil
	}

	// common case: interface{}
	if v.Kind() == reflect.Interface && v.NumMethod() == 0 {
		iface, _ := d.parseValueInterface()
		v.Set(reflect.ValueOf(iface))
		return true, nil
	}

	b, err := d.r.ReadByte()
	if err != nil {
		panic(err)
	}
	d.Offset++

	switch b {
	case 'e':
		return false, nil
	case 'd':
		return true, d.parseDict(v)
	case 'l':
		return true, d.parseList(v)
	case 'i':
		d.parseInt(v)
		return true, nil
	default:
		if b >= '0' && b <= '9' {
			// It's a string.
			d.buf.Reset()
			// Write the first digit of the length to the buffer.
			d.buf.WriteByte(b)
			return true, d.parseString(v)
		}

		d.raiseUnknownValueType(b, d.Offset-1)
	}
	panic("unreachable")
}
1106401
func (*StdClock) NowNanoseconds() int64 {
	sec, nsec, _ := now()
	return sec*1e9 + int64(nsec)
}
455432
func (d Duration) MicroSecond() int {
	_, _, _, _, frac := splitDuration(d.Duration)
	return frac
}
95161
func TimeValueSlice(src []*time.Time) []time.Time {
	dst := make([]time.Time, len(src))
	for i := 0; i < len(src); i++ {
		if src[i] != nil {
			dst[i] = *(src[i])
		}
	}
	return dst
}
1131374
func newTimedValue(value interface{}, err error, staleDuration, expiryDuration time.Duration) *TimedValue {
	switch val := value.(type) {
	case TimedValue:
		if val.Created.IsZero() {
			val.Created = time.Now()
		}
		return &val
	case *TimedValue:
		if val.Created.IsZero() {
			val.Created = time.Now()
		}
		return val
	default:
		if staleDuration == 0 && expiryDuration == 0 {
			return &TimedValue{Value: value, Err: err, Created: time.Now()}
		}
		var stale, expiry time.Time
		now := time.Now()
		if staleDuration > 0 {
			stale = now.Add(staleDuration)
		}
		if expiryDuration > 0 {
			expiry = now.Add(expiryDuration)
		}
		return &TimedValue{Value: value, Err: err, Created: time.Now(), Stale: stale, Expiry: expiry}
	}
}
1171159
func (f *TimeFuncs) Millisecond(n interface{}) gotime.Duration {
	return gotime.Millisecond * gotime.Duration(conv.ToInt64(n))
}
296200
func TimeToFloat(t time.Time) float64 {
	return float64(t.Unix()) + (float64(t.Nanosecond()) / 1e9)
}
609590
func (ns NullTime) Value() (driver.Value, error) {
	if (time.Time)(ns).IsZero() {
		return nil, nil
	}
	return (time.Time)(ns).Format("2006-01-02 15:04:05"), nil
}
528279
func (n nowSentinel) Value() (driver.Value, error) {
	now := time.Now().UTC().Format(timeFormat)
	return now, nil
}
296013
func containerResourceRuntimeValue(fs *v1.ResourceFieldSelector, pod *v1.Pod, container *v1.Container) (string, error) {
	containerName := fs.ContainerName
	if len(containerName) == 0 {
		return resource.ExtractContainerResourceValue(fs, container)
	}
	return resource.ExtractResourceValueByContainerName(fs, pod, containerName)
}
176905
func SerializeValue(c types.Cell, now time.Time) *pb.MetricsData {
	d := pb.MetricsData{}
	d.Field = field.Serialize(c.Fields, c.FieldVals)

	if c.ValueType.IsCumulative() {
		d.StartTimestamp = toTimestamp(c.ResetTime)
	} else {
		d.StartTimestamp = toTimestamp(now)
	}
	d.EndTimestamp = toTimestamp(now)

	switch c.ValueType {
	case types.NonCumulativeIntType, types.CumulativeIntType:
		d.Value = &pb.MetricsData_Int64Value{c.Value.(int64)}
	case types.NonCumulativeFloatType, types.CumulativeFloatType:
		d.Value = &pb.MetricsData_DoubleValue{c.Value.(float64)}
	case types.CumulativeDistributionType, types.NonCumulativeDistributionType:
		d.Value = &pb.MetricsData_DistributionValue{serializeDistribution(c.Value.(*distribution.Distribution))}
	case types.StringType:
		d.Value = &pb.MetricsData_StringValue{c.Value.(string)}
	case types.BoolType:
		d.Value = &pb.MetricsData_BoolValue{c.Value.(bool)}
	}
	return &d
}
1288425
func (t *TimePeriod) ToSeconds() (int64, error) {
	if t == nil {
		return 0, nil
	}
	switch t := t.Time.(type) {
	case *TimePeriod_Duration:
		return t.ToSeconds()
	case *TimePeriod_Seconds:
		return t.Seconds, nil
	default:
		return 0, errors.Reason("unexpected type %T", t).Err()
	}
}