// untptrCFDateToTime converts a uintptr (assumed to have been
// converted from a CFDateRef) to a time.Time.
//
// This is an adaptation of CFDateTimeToTime.
343491
func uintptrCFDateToTime(p uintptr) time.Time {
	abs := C.CFDateGetAbsoluteTimeSafe(C.uintptr_t(p))
	s, ns := absoluteTimeToUnix(abs)
	return time.Unix(s, ns)
}
18426
func TimeToProto(t time.Time) *logutilpb.Time {
	seconds := t.Unix()
	nanos := int64(t.Sub(time.Unix(seconds, 0)))
	return &logutilpb.Time{
		Seconds:     seconds,
		Nanoseconds: int32(nanos),
	}
}
1311722
func UnmarshalTimeOfDayTz(s string) (tod TimeOfDay, err error) {
	zoneIndex := strings.IndexAny(s, "Z+-")
	var timePart string
	var hasOffset bool
	var offset int
	if zoneIndex == -1 {
		hasOffset = false
		timePart = s
	} else {
		hasOffset = true
		timePart = s[:zoneIndex]
		if offset, err = parseTimezone(s[zoneIndex:]); err != nil {
			return
		}
	}

	hour, minute, second, err := parseTimeParts(timePart)
	if err != nil {
		return
	}

	fromMidnight := time.Duration(hour*3600+minute*60+second) * time.Second

	// ISO8601 special case - values up to 24:00:00 are allowed, so using
	// strictly greater-than for the maximum value.
	if fromMidnight > 24*time.Hour || minute >= 60 || second >= 60 {
		return TimeOfDay{}, fmt.Errorf("soap time.tz: value %q has value(s) out of range", s)
	}

	return TimeOfDay{
		FromMidnight: time.Duration(hour*3600+minute*60+second) * time.Second,
		HasOffset:    hasOffset,
		Offset:       offset,
	}, 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{}
}
505902
func (h *Timing) TCPConnectTime(tCPConnectTime int64) *Timing {
	h.tCPConnectTime = tCPConnectTime
	h.tCPConnectTimeSet = true
	return h
}
281802
func TimeToTimestamp(t time.Time) *timestamp.Timestamp {
	return &timestamp.Timestamp{
		Seconds: t.UnixNano() / int64(time.Second),
		Nanos:   int32(t.UnixNano() % int64(time.Second)),
	}
}
729732
func ProtoToTime(ts *logutilpb.Time) time.Time {
	if ts == nil {
		// treat nil like the empty Timestamp
		return time.Unix(0, 0).UTC()
	}
	return time.Unix(ts.Seconds, int64(ts.Nanoseconds)).UTC()
}
374930
func toTime(s string) (t time.Time, err error) {
	if s != "" {
		t, err = time.Parse(time.RFC3339, s)
	}

	return
}
749678
func NewTimeAPI(t time.Time) TimeAPI {
	return TimeAPI{
		S: dbtypes.NewTimeDef(t),
	}
}
218735
func ConvertDurationPtr(d *Duration) *time.Duration {
	if d == nil {
		return nil
	}
	res := time.Duration(*d)
	return &res
}
1101621
func (pt *ParseTime) RFC8xx1123(value string) (time.Time, error) {
	t, _, err := parseRFC8xx1123(value, pt.location)
	return t, err
}
1052714
func (v *Value) ToTimestamp() (t time.Time, ok bool) {
	switch v.vType {
	case typeTimestamp:
		return v.value.(time.Time), true
	}
	return t, false
}
1316814
func TimeToNTP(t time.Time) uint64 {
	if t.IsZero() {
		return 0
	}
	return uint64(t.Unix()) + ntpDelta
}
105302
func TclToKeybaseTime(tcl TypedChainLink) *KeybaseTime {
	return &KeybaseTime{
		Unix:  tcl.GetCTime().Unix(),
		Chain: tcl.GetMerkleSeqno(),
	}
}
615760
func encodeUTCDateTime(buf *bytes.Buffer, name string, val UTCDateTime) error {
	// type
	if err := buf.WriteByte(_UTC_DATETIME); err != nil {
		return err
	}

	// name
	if err := writeCstring(buf, name); err != nil {
		return err
	}

	// value
	return binary.Write(buf, binary.LittleEndian, val)
}
48724
func StrToTime(str string, args ...string) (unixtime int) {
	layout := "2006-01-02 15:04:05"
	if len(args) > 0 {
		layout = args[0]
	}
	t, err := time.Parse(layout, str)
	if err == nil {
		unixtime = int(t.Unix())
	} else {
		fmt.Println(err, str)
	}
	return
}
1260174
func (s Slice) GetUTCDate() (time.Time, error) {
	if !s.IsUTCDate() {
		return time.Time{}, InvalidTypeError{"Expecting type UTCDate"}
	}
	v := toInt64(readIntegerFixed(s[1:], 8)) // milliseconds since epoch
	sec := v / 1000
	nsec := (v % 1000) * 1000000
	return time.Unix(sec, nsec).UTC(), nil
}