// roundTime rounds the time value according to digits count specified by fsp.
761207
func roundTime(t gotime.Time, fsp int) gotime.Time {
	d := gotime.Duration(math.Pow10(9 - fsp))
	return t.Round(d)
}
553042
func ParseTime(str string, loc *time.Location) (t time.Time, err error) {
	str = strings.TrimSpace(str)
	format := TimeFormat[:19]
	switch len(str) {
	case 10:
		if str == "0000-00-00" {
			return
		}
		format = format[:10]
	case 19:
		if str == "0000-00-00 00:00:00" {
			return
		}
	}
	// Don't expect 0000-00-00 00:00:00.0+
	t, err = time.ParseInLocation(format, str, loc)
	return
}
1124211
func (p *Point) Round(factor ...int) *Point {
	f := 1.0e5
	if len(factor) != 0 {
		f = float64(factor[0])
	}

	for idx, val := range p {
		x := val * f
		p[idx] = math.Floor(x+0.5) / f
	}

	return p
}
853431
func SetTimerPrecision(precision time.Duration) {
	if precision < time.Millisecond {
		panic("time precision can not less than a Millisecond")
	}
	timer.Precision = precision
}
1352022
func ParseTimeFromNum(num int64, tp byte, fsp int) (Time, error) {
	fsp, err := checkFsp(fsp)
	if err != nil {
		return Time{Time: ZeroTime, Type: tp}, errors.Trace(err)
	}

	t, err := parseDateTimeFromNum(num)
	if err != nil {
		return Time{Time: ZeroTime, Type: tp}, errors.Trace(err)
	}

	t.Type = tp
	t.Fsp = fsp
	if err := t.check(); err != nil {
		return Time{Time: ZeroTime, Type: tp}, errors.Trace(err)
	}
	return t, nil
}
509
func RoundDown(t time.Time, d TimeDelta) time.Time {
	td := d.RoundDown(t)
	DebugLogger.Printf("RoundDown( %s, %s ) --> %s", t.Format("2006-01-02 15:04:05 (Mon)"), d.String(),
		td.Format("2006-01-02 15:04:05 (Mon)"))
	return td
}
11143
func (o Timestamp) Time() time.Time {
	return time.Unix(0, int64((o-gregorianToUNIXOffset)*100)).UTC()
}
1251696
func (k *Key) Time() (time.Time, error) {
	return k.TimeFormat(time.RFC3339)
}
898848
func Round(x float64) float64 {
	var absx, y float64
	absx = math.Abs(x)
	y = math.Floor(absx)
	if absx-y >= 0.5 {
		y += 1.0
	}
	return math.Copysign(y, x)
}
826795
func RoundNext(t time.Time, d TimeDelta) time.Time {
	DebugLogger.Printf("RoundNext( %s, %s )", t.Format("2006-01-02 15:04:05 (Mon)"), d.String())
	os := t.Unix()
	lt := d.RoundDown(t)
	shift := d.Seconds()
	shift += shift / 2
	ut := lt.Add(time.Duration(shift) * time.Second) // see RoundUp()
	ut = d.RoundDown(ut)
	ld := os - lt.Unix()
	ud := ut.Unix() - os
	if ld < ud {
		return lt
	}
	return ut
}
940552
func Strftime(t *time.Time, f string) string {
	var result []string
	format := []rune(f)

	add := func(str string) {
		result = append(result, str)
	}

	for i := 0; i < len(format); i++ {
		switch format[i] {
		case '%':
			if i < len(format)-1 {
				switch format[i+1] {
				case 'a':
					add(shortDayNames[t.Weekday()])
				case 'A':
					add(longDayNames[t.Weekday()])
				case 'w':
					add(fmt.Sprintf("%d", t.Weekday()))
				case 'd':
					add(fmt.Sprintf("%02d", t.Day()))
				case 'b':
					add(shortMonthNames[t.Month()])
				case 'B':
					add(longMonthNames[t.Month()])
				case 'm':
					add(fmt.Sprintf("%02d", t.Month()))
				case 'y':
					add(fmt.Sprintf("%02d", t.Year()%100))
				case 'Y':
					add(fmt.Sprintf("%02d", t.Year()))
				case 'H':
					add(fmt.Sprintf("%02d", t.Hour()))
				case 'I':
					if t.Hour() == 0 {
						add(fmt.Sprintf("%02d", 12))
					} else if t.Hour() > 12 {
						add(fmt.Sprintf("%02d", t.Hour()-12))
					} else {
						add(fmt.Sprintf("%02d", t.Hour()))
					}
				case 'p':
					if t.Hour() < 12 {
						add("AM")
					} else {
						add("PM")
					}
				case 'M':
					add(fmt.Sprintf("%02d", t.Minute()))
				case 'S':
					add(fmt.Sprintf("%02d", t.Second()))
				case 'f':
					add(fmt.Sprintf("%06d", t.Nanosecond()/1000))
				case 'z':
					add(t.Format("-0700"))
				case 'Z':
					add(t.Format("MST"))
				case 'j':
					add(fmt.Sprintf("%03d", t.YearDay()))
				case 'U':
					add(fmt.Sprintf("%02d", weekNumber(t, 'U')))
				case 'W':
					add(fmt.Sprintf("%02d", weekNumber(t, 'W')))
				case 'c':
					add(t.Format("Mon Jan 2 15:04:05 2006"))
				case 'x':
					add(fmt.Sprintf("%02d/%02d/%02d", t.Month(), t.Day(), t.Year()%100))
				case 'X':
					add(fmt.Sprintf("%02d:%02d:%02d", t.Hour(), t.Minute(), t.Second()))
				case '%':
					add("%")
				}
				i += 1
			}
		default:
			add(string(format[i]))
		}
	}

	return strings.Join(result, "")
}
548020
func Round(n float64) uint64 {
	if n < 0 {
		return uint64(math.Ceil(n - 0.5))
	}
	return uint64(math.Floor(n + 0.5))
}
278872
func Round(input float64, places int) (rounded float64, err error) {

	// If the float is not a number
	if math.IsNaN(input) {
		return math.NaN(), NaNErr
	}

	// Find out the actual sign and correct the input for later
	sign := 1.0
	if input < 0 {
		sign = -1
		input *= -1
	}

	// Use the places arg to get the amount of precision wanted
	precision := math.Pow(10, float64(places))

	// Find the decimal place we are looking to round
	digit := input * precision

	// Get the actual decimal number as a fraction to be compared
	_, decimal := math.Modf(digit)

	// If the decimal is less than .5 we round down otherwise up
	if decimal >= 0.5 {
		rounded = math.Ceil(digit)
	} else {
		rounded = math.Floor(digit)
	}

	// Finally we do the math to actually create a rounded number
	return rounded / precision * sign, nil
}
213442
func Time(ms uint64) time.Time {
	s := int64(ms / 1e3)
	ns := int64((ms % 1e3) * 1e6)
	return time.Unix(s, ns)
}
296981
func ParseDatetimeFromNum(sc *stmtctx.StatementContext, num int64) (Time, error) {
	return ParseTimeFromNum(sc, num, mysql.TypeDatetime, DefaultFsp)
}
1233819
func (it *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
	statusCode := BogusStatusCode

	// Remember the current time.
	now := time.Now()

	// Make the request using the next RoundTripper.
	resp, err := it.next.RoundTrip(req)
	if resp != nil {
		statusCode = resp.StatusCode
	}

	// Observe the time it took to make the request.
	RequestDurationSeconds.WithLabelValues(
		req.URL.Scheme,
		req.URL.Host,
		it.cbs.PathProcessor(req.URL.Path),
		it.cbs.QueryProcessor(req.URL.RawQuery),
		req.Method,
		it.cbs.CodeProcessor(statusCode),
	).Observe(time.Since(now).Seconds())

	// return the response and error reported from the next RoundTripper.
	return resp, err
}
1350671
func round(number float64, precision int) float64 {
	return math.Round(number*10*float64(precision)) / (10.0 * float64(precision))
}