// FiletimeToDuration converts a Filetime to a time.Duration. Do not use this
// method to convert a Filetime to an actual clock time, for that use
// Filetime.Nanosecond().
506005
func FiletimeToDuration(ft *syscall.Filetime) time.Duration {
	n := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) // in 100-nanosecond intervals
	return time.Duration(n * 100)
}
587431
func (a *SynthesizeTapGestureArgs) SetDuration(duration int) *SynthesizeTapGestureArgs {
	a.Duration = &duration
	return a
}
1282359
func (s *FileTime) Time() UTCTime {
	return UTCTime(time.Unix(int64(s.Convert()), 0))
}
649295
func (c *Context) GetDuration(key string) (d time.Duration) {
	if val, ok := c.Get(key); ok && val != nil {
		d, _ = val.(time.Duration)
	}
	return
}
218735
func ConvertDurationPtr(d *Duration) *time.Duration {
	if d == nil {
		return nil
	}
	res := time.Duration(*d)
	return &res
}
746993
func MakeDuration(target string, def int) time.Duration {
	if !elapso.MatchString(target) {
		return time.Duration(def)
	}

	matchs := elapso.FindAllStringSubmatch(target, -1)

	if len(matchs) <= 0 {
		return time.Duration(def)
	}

	match := matchs[0]

	if len(match) < 3 {
		return time.Duration(def)
	}

	dur := time.Duration(ConvertToInt(match[1], def))

	mtype := match[2]

	switch mtype {
	case "s":
		return dur * time.Second
	case "mcs":
		return dur * time.Microsecond
	case "ns":
		return dur * time.Nanosecond
	case "ms":
		return dur * time.Millisecond
	case "m":
		return dur * time.Minute
	case "h":
		return dur * time.Hour
	default:
		return time.Duration(dur) * time.Second
	}
}
1027905
func toSeconds(duration time.Duration) time.Duration {
	seconds := duration.Nanoseconds() / nanosecondsPerSecond
	nanoseconds := seconds * nanosecondsPerSecond
	return time.Duration(nanoseconds)
}
240829
func (stats *LogStats) TotalTime() time.Duration {
	return stats.EndTime.Sub(stats.StartTime)
}
664160
func (s *InsertableImage) SetDuration(v int64) *InsertableImage {
	s.Duration = &v
	return s
}
662347
func formatDuration(duration time.Duration) string {
	// We're not supporting negative durations
	if duration.Seconds() <= 0 {
		return "PT0S"
	}

	h := int(duration.Hours())
	m := int(duration.Minutes()) - (h * 60)
	s := int(duration.Seconds()) - (h*3600 + m*60)

	res := "PT"
	if h > 0 {
		res = fmt.Sprintf("%s%dH", res, h)
	}
	if m > 0 {
		res = fmt.Sprintf("%s%dM", res, m)
	}
	if s > 0 {
		res = fmt.Sprintf("%s%dS", res, s)
	}

	return res
}
1349402
func (l *ListDuration) AddDuration(d time.Duration) {
	l.Duration = l.Duration + d
	l.TimesInList++
}
369774
func (c *Parser) Duration() (time.Duration, error) {
	if c == nil {
		return 0, errors.New("can't calculate the duration of a nil pointer")
	}
	if c.ID == [4]byte{} || c.AvgBytesPerSec == 0 {
		err := c.Parse()
		if err != nil {
			return 0, nil
		}
	}
	switch c.Format {
	case WavFormatID:
		return c.wavDuration()
	default:
		return 0, ErrFmtNotSupported
	}
}
1372820
func (h *Histogram) RecordDuration(v time.Duration) error {
	return h.RecordIntScale(int64(v), -9)
}
417668
func (d Duration) Duration() (time.Duration, error) {
	switch {
	case byte(d) == 0x00:
		return time.Duration(0), nil
	case byte(d) <= 0x7F:
		return time.Duration(d) * time.Second, nil
	case d <= 0xFD:
		return time.Duration(d-0x7F) * time.Minute, nil
	}
	return time.Duration(0), fmt.Errorf("Factory default duration")
}
508239
func NewDuration(s string) (duration, error) {
	var e duration
	err := e.FromString(s)
	if err != nil {
		return 0, err
	}
	return e, nil
}
1257257
func convertStringToDuration(sc *stmtctx.StatementContext, str string, fsp int) (d types.Duration, t types.Time,
	isDuration bool, err error) {
	if n := strings.IndexByte(str, '.'); n >= 0 {
		lenStrFsp := len(str[n+1:])
		if lenStrFsp <= types.MaxFsp {
			fsp = mathutil.Max(lenStrFsp, fsp)
		}
	}
	return types.StrToDuration(sc, str, fsp)
}
514945
func NumberToDuration(number int64, fsp int) (Duration, error) {
	if number > TimeMaxValue {
		// Try to parse DATETIME.
		if number >= 10000000000 { // '2001-00-00 00-00-00'
			if t, err := ParseDatetimeFromNum(nil, number); err == nil {
				dur, err1 := t.ConvertToDuration()
				return dur, errors.Trace(err1)
			}
		}
		dur, err1 := MaxMySQLTime(fsp).ConvertToDuration()
		terror.Log(err1)
		return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number)))
	} else if number < -TimeMaxValue {
		dur, err1 := MaxMySQLTime(fsp).ConvertToDuration()
		terror.Log(err1)
		dur.Duration = -dur.Duration
		return dur, ErrOverflow.GenWithStackByArgs("Duration", strconv.Itoa(int(number)))
	}
	var neg bool
	if neg = number < 0; neg {
		number = -number
	}

	if number/10000 > TimeMaxHour || number%100 >= 60 || (number/100)%100 >= 60 {
		return ZeroDuration, errors.Trace(ErrInvalidTimeFormat.GenWithStackByArgs(number))
	}
	t := Time{Time: FromDate(0, 0, 0, int(number/10000), int((number/100)%100), int(number%100), 0), Type: mysql.TypeDuration, Fsp: fsp}
	dur, err := t.ConvertToDuration()
	if err != nil {
		return ZeroDuration, errors.Trace(err)
	}
	if neg {
		dur.Duration = -dur.Duration
	}
	return dur, nil
}