// CFDateToTime will convert the given CFDateRef to a time.Time.
971847
func CFDateToTime(d C.CFDateRef) time.Time {
	abs := C.CFDateGetAbsoluteTime(d)
	s, ns := absoluteTimeToUnix(abs)
	return time.Unix(s, ns)
}
826220
func strftime(format string, t time.Time) string {
	layout := ""
	length := len(format)
	for i := 0; i < length; i++ {
		if format[i] == '%' && i <= length-2 {
			if layoutCmd, ok := conversion[format[i+1:i+2]]; ok {
				layout = layout + layoutCmd
				i++
				continue
			}
		}
		layout = layout + format[i:i+1]
	}
	return t.Format(layout)
}
1156873
func formatListTime(t keybase1.Time) string {
	layout := "2006-01-02 15:04:05"
	return keybase1.FromTime(t).Format(layout)
}
1141734
func formatTime(v interface{}, dateFormat string) string {
	if typed, isTyped := v.(time.Time); isTyped {
		return typed.Format(dateFormat)
	}
	if typed, isTyped := v.(int64); isTyped {
		return time.Unix(0, typed).Format(dateFormat)
	}
	if typed, isTyped := v.(float64); isTyped {
		return time.Unix(0, int64(typed)).Format(dateFormat)
	}
	return ""
}
1316227
func (d Duration) ConvertToTime(tp uint8) (Time, error) {
	year, month, day := gotime.Now().Date()
	// just use current year, month and day.
	n := gotime.Date(year, month, day, 0, 0, 0, 0, gotime.Local)
	n = n.Add(d.Duration)

	t := Time{
		Time: FromGoTime(n),
		Type: mysql.TypeDatetime,
		Fsp:  d.Fsp,
	}

	return t.Convert(tp)
}
82831
func ParseDatetime(str string) (Time, error) {
	return ParseTime(str, mysql.TypeDatetime, DefaultFsp)
}
441995
func fmtEtimeDuration(d time.Duration) string {
	days := d / (24 * time.Hour)
	hours := d % (24 * time.Hour)
	minutes := hours % time.Hour
	seconds := math.Mod(minutes.Seconds(), 60)
	var b bytes.Buffer
	if days > 0 {
		fmt.Fprintf(&b, "%02d-", days)
	}
	if hours/time.Hour > 0 {
		fmt.Fprintf(&b, "%02d:", hours/time.Hour)
	}
	fmt.Fprintf(&b, "%02d:", minutes/time.Minute)
	fmt.Fprintf(&b, "%02.0f", seconds)
	return b.String()
}
343491
func uintptrCFDateToTime(p uintptr) time.Time {
	abs := C.CFDateGetAbsoluteTimeSafe(C.uintptr_t(p))
	s, ns := absoluteTimeToUnix(abs)
	return time.Unix(s, ns)
}
972649
func (t *StandardResettingTimer) Time(f func()) {
	ts := time.Now()
	f()
	t.Update(time.Since(ts))
}
1048692
func FileDataFromRelativeTimeString(
	ctx context.Context, config libkbfs.Config, h *tlfhandle.Handle,
	filename string) ([]byte, bool, error) {
	if !strings.HasPrefix(filename, ArchivedRelTimeFilePrefix) {
		return nil, false, nil
	}

	rev, err := RevFromRelativeTimeString(
		ctx, config, h, filename[len(ArchivedRelTimeFilePrefix):])
	if err != nil {
		return nil, false, err
	}

	return []byte(ArchivedRevDirPrefix + strconv.FormatInt(int64(rev), 10)),
		true, nil
}
1029123
func (f *FullAlbum) ReleaseDateTime() time.Time {
	if f.ReleaseDatePrecision == "day" {
		result, _ := time.Parse(DateLayout, f.ReleaseDate)
		return result
	}
	if f.ReleaseDatePrecision == "month" {
		ym := strings.Split(f.ReleaseDate, "-")
		year, _ := strconv.Atoi(ym[0])
		month, _ := strconv.Atoi(ym[1])
		return time.Date(year, time.Month(month), 1, 0, 0, 0, 0, time.UTC)
	}
	year, _ := strconv.Atoi(f.ReleaseDate)
	return time.Date(year, 1, 1, 0, 0, 0, 0, time.UTC)
}
740672
func Time(v time.Time) *datatypes.Time {
	r := datatypes.Time{Time: v}
	return &r
}
656233
func ToTimeE(i interface{}) (tim time.Time, err error) {
	i = indirect(i)

	switch v := i.(type) {
	case time.Time:
		return v, nil
	case string:
		return StringToDate(v)
	case int:
		return time.Unix(int64(v), 0), nil
	case int64:
		return time.Unix(v, 0), nil
	case int32:
		return time.Unix(int64(v), 0), nil
	case uint:
		return time.Unix(int64(v), 0), nil
	case uint64:
		return time.Unix(int64(v), 0), nil
	case uint32:
		return time.Unix(int64(v), 0), nil
	default:
		return time.Time{}, fmt.Errorf("unable to cast %#v of type %T to Time", i, i)
	}
}
1166166
func (a *Array) Time(t time.Time) *Array {
	a.buf = enc.AppendTime(enc.AppendArrayDelim(a.buf), t, TimeFieldFormat)
	return a
}
412345
func EpochToTime(e int) time.Time {
	tm := time.Unix(int64(e), 0)

	return tm
}
596320
func TimeToExcelTime(t time.Time, date1904 bool) float64 {
	// Get the number of days since the unix epoc
	daysSinceUnixEpoc := float64(t.Unix())/secondsInADay
	// Get the number of nanoseconds in days since Unix() is in seconds.
	nanosPart := float64(t.Nanosecond())/nanosInADay
	// Add both together plus the number of days difference between unix and Excel epocs.
	var offsetDays float64
	if date1904 {
		offsetDays = daysBetween1970And1904
	} else {
		offsetDays = daysBetween1970And1900
	}
	daysSinceExcelEpoc := daysSinceUnixEpoc + offsetDays + nanosPart
	return daysSinceExcelEpoc
}
66531
func Convert(ref C.CFTypeRef) (interface{}, error) {
	typeID := C.CFGetTypeID(ref)
	if typeID == C.CFStringGetTypeID() {
		return CFStringToString(C.CFStringRef(ref)), nil
	} else if typeID == C.CFDictionaryGetTypeID() {
		return ConvertCFDictionary(C.CFDictionaryRef(ref))
	} else if typeID == C.CFArrayGetTypeID() {
		arr := CFArrayToArray(C.CFArrayRef(ref))
		results := make([]interface{}, 0, len(arr))
		for _, ref := range arr {
			v, err := Convert(ref)
			if err != nil {
				return nil, err
			}
			results = append(results, v)
			return results, nil
		}
	} else if typeID == C.CFDataGetTypeID() {
		b, err := CFDataToBytes(C.CFDataRef(ref))
		if err != nil {
			return nil, err
		}
		return b, nil
	} else if typeID == C.CFNumberGetTypeID() {
		return CFNumberToInterface(C.CFNumberRef(ref)), nil
	} else if typeID == C.CFBooleanGetTypeID() {
		if C.CFBooleanGetValue(C.CFBooleanRef(ref)) != 0 {
			return true, nil
		}
		return false, nil
	}

	return nil, fmt.Errorf("Invalid type: %s", CFTypeDescription(ref))
}