// TimeValue returns the value of the time.Time pointer passed in or
// time.Time{} if the pointer is nil.
436689
func TimeValue(v *time.Time) time.Time {
	if v != nil {
		return *v
	}
	return time.Time{}
}
702621
func CompareValues(v1, v2 Value) int {
	switch v1 := v1.(type) {
	case Document:
		v2, ok := v2.(Document)
		if !ok {
			return -1
		} else if len(v1) != len(v2) {
			return len(v1) - len(v2)
		}
		return -1 // TODO: implement proper sorting?
	case Strings:
		v2, ok := v2.(Strings)
		if !ok {
			return -1
		} else if len(v1) != len(v2) {
			return len(v1) - len(v2)
		}
		for i := range v1 {
			if dn := CompareValues(String(v1[i]), String(v2[i])); dn != 0 {
				return dn
			}
		}
		return 0
	case Bytes:
		v2, ok := v2.(Bytes)
		if !ok {
			return -1
		}
		return bytes.Compare(v1, v2)
	case Time:
		v2, ok := v2.(Time)
		if !ok {
			return -1
		}
		t1, t2 := time.Time(v1), time.Time(v2)
		if t1.Equal(t2) {
			return 0
		} else if t1.Before(t2) {
			return -1
		}
		return +1
	case String:
		v2, ok := v2.(String)
		if !ok {
			return -1
		}
		return strings.Compare(string(v1), string(v2))
	case Int:
		v2, ok := v2.(Int)
		if !ok {
			return -1
		}
		if v1 == v2 {
			return 0
		} else if v1 < v2 {
			return -1
		}
		return +1
	case Float:
		v2, ok := v2.(Float)
		if !ok {
			return -1
		}
		if v1 == v2 {
			return 0
		} else if v1 < v2 {
			return -1
		}
		return +1
	}
	return -1
}
191870
func (n NullDateTime) Value() (driver.Value, error) {
	if !n.Valid {
		return nil, nil
	}
	return n.DateTime.Value()
}
1323801
func genericValue(v Value) interface{} {
	if g, ok := v.(*generic); ok {
		return g.p
	}
	return nil
}
1065348
func TimeToFloat(t time.Time) float64 {
	return float64(t.Unix()) + (float64(t.Nanosecond()/int(time.Microsecond)) / float64(1000000))
}
1262837
func (schema *Schema) stringValue(v interface{}) *string {
	switch v := v.(type) {
	default:
		fmt.Printf("stringValue: unexpected type %T\n", v)
	case string:
		return &v
	}
	return nil
}
977881
func IsValue(v interface{}) bool {
	if IsScanValue(v) {
		return true
	}
	if _, ok := v.(string); ok {
		return true
	}
	return false
}
461104
func (pt *ParseTime) Parse(value string) (time.Time, error) {
	times := make(sortedTimes, 0)
	t, priority, _ := parseISO8601(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseRFC8xx1123(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseANSIC(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	t, priority, _ = parseUS(value, pt.location)
	if !t.IsZero() {
		times = append(times, sortedTime{time: t, priority: priority})
	}

	if len(times) == 0 {
		var tmpT time.Time
		return tmpT, errInvalidDateTime
	}

	sort.Sort(times)

	return times[0].time, nil
}
1330603
func (ints Ints) AppendValue(dst []byte, quote int) []byte {
	if len(ints) == 0 {
		return dst
	}

	for _, v := range ints {
		dst = strconv.AppendInt(dst, v, 10)
		dst = append(dst, ',')
	}
	dst = dst[:len(dst)-1]
	return dst
}
234782
func (t TimeDefLocal) Value() (driver.Value, error) {
	return t.T.Local(), nil
}
538383
func (t *Thermometer) parseValue(val string) (*Value, error) {
	var v *Value
	start := strings.Index(val, "t=")
	if start == -1 {
		return v, errors.New("could not parse temp")
	}
	temperatureStr := val[start+2:]
	temperatureStr = strings.Trim(temperatureStr, "\n")
	temperature, err := strconv.ParseFloat(temperatureStr, 64)
	if err != nil {
		return v, err
	}
	value := temperature / 1000.0
	if t.units == "F" || t.units == "f" {
		value = value*1.8 + 32.0
	}
	return &Value{
		Value: value,
		Units: t.units,
	}, nil
}
528279
func (n nowSentinel) Value() (driver.Value, error) {
	now := time.Now().UTC().Format(timeFormat)
	return now, nil
}
445271
func TimeField(name string) *Field {
	ret := FieldWithType(name, formcommon.TIME)
	return ret
}
13533
func toOuchValue(v nosql.Value) interface{} {
	switch v := v.(type) {
	case nil:
		return nil
	case nosql.Strings:
		return []string(v)
	case nosql.String:
		return string(v)
	case nosql.Int:
		return int64(v)
	case nosql.Float:
		return float64(v)
	case nosql.Bool:
		return bool(v)
	case nosql.Time:
		return time.Time(v).UTC().Format(time.RFC3339Nano)
	case nosql.Bytes:
		return base64.StdEncoding.EncodeToString(v)
	default:
		panic(fmt.Errorf("unsupported type: %T", v))
	}
}
352230
func (c *Clock) Time() float32 {
	currStamp := theTimer.Now()
	return float32(float64(currStamp-c.startStamp) / float64(secondsInNano))
}
710899
func (nt NullTime) Value() (driver.Value, error) {
	if !nt.Valid {
		return nil, nil
	}
	return nt.Time, nil
}
1159061
func Time(ts *timestamp.Timestamp) time.Time {
	return time.Unix(ts.Seconds, int64(ts.Nanos))
}