// FormatQuarter takes quarter time and formats it using "Q# YYYY".
343361
func FormatQuarter(t time.Time) string {
	return fmt.Sprintf("Q%d %d", MonthToQuarter(uint8(t.Month())), t.Year())
}
921276
func (s *UpdateByQueryService) Q(q string) *UpdateByQueryService {
	s.q = q
	return s
}
907051
func FormatDuration(d time.Duration) string {
	if d == 0 {
		return "0s"
	} else if d%(365*24*time.Hour) == 0 {
		return fmt.Sprintf("%dy", d/(365*24*time.Hour))
	} else if d%(30*24*time.Hour) == 0 {
		return fmt.Sprintf("%dmo", d/(30*24*time.Hour))
	} else if d%(7*24*time.Hour) == 0 {
		return fmt.Sprintf("%dw", d/(7*24*time.Hour))
	} else if d%(24*time.Hour) == 0 {
		return fmt.Sprintf("%dd", d/(24*time.Hour))
	} else if d%time.Hour == 0 {
		return fmt.Sprintf("%dh", d/time.Hour)
	} else if d%time.Minute == 0 {
		return fmt.Sprintf("%dm", d/time.Minute)
	} else if d%time.Second == 0 {
		return fmt.Sprintf("%ds", d/time.Second)
	} else if d%time.Millisecond == 0 {
		return fmt.Sprintf("%dms", d/time.Millisecond)
	} else if d%time.Microsecond == 0 {
		return fmt.Sprintf("%dus", d/time.Microsecond)
	}
	return fmt.Sprintf("%dns", d/time.Nanosecond)
}
361852
func formatToInt(i int, v string) string {
	f, err := strconv.ParseFloat(v, 64)
	if err != nil {
		return v
	}
	return fmt.Sprintf("%d", int(f))
}
837143
func (c *Carbon) StartOfQuarter() *Carbon {
	month := time.Month((c.Quarter()-1)*monthsPerQuarter + 1)

	return create(c.Year(), time.Month(month), 1, 0, 0, 0, 0, c.Location())
}
1369597
func formatLockTime(lockTime uint32) string {
	// The lock time field of a transaction is either a block height at
	// which the transaction is finalized or a timestamp depending on if the
	// value is before the lockTimeThreshold.  When it is under the
	// threshold it is a block height.
	if lockTime < txscript.LockTimeThreshold {
		return fmt.Sprintf("height %d", lockTime)
	}

	return time.Unix(int64(lockTime), 0).String()
}
1014257
func (a *DerivativeAggregation) Format(format string) *DerivativeAggregation {
	a.format = format
	return a
}
1067974
func (ns *Namespace) Format(layout string, v interface{}) (string, error) {
	t, err := cast.ToTimeE(v)
	if err != nil {
		return "", err
	}

	return t.Format(layout), nil
}
1372125
func (c Calendar) formatDateTime(datetime time.Time, pattern []*datetimePatternComponent) (string, error) {
	formatted := ""
	for _, component := range pattern {
		if component.componentType == datetimePatternComponentLiteral {
			formatted += component.pattern
		} else {
			f, err := c.formatDateTimeComponent(datetime, component.pattern)
			if err != nil {
				return "", err
			}
			formatted += f
		}
	}

	return strings.Trim(formatted, " ,"), nil
}
124898
func (t *Translator) formatDateTimeComponentPeriodNarrow(hour int) string {
	if hour < 12 {
		return t.rules.DateTime.FormatNames.Periods.Narrow.AM
	}

	return t.rules.DateTime.FormatNames.Periods.Narrow.PM
}
609160
func QuarterProjection(dt time.Time, current float64) float64 {
	qtStart := QuarterStart(dt)
	durQ2D := dt.Sub(qtStart)
	qtNext := TimeDt6AddNMonths(qtStart, 3)
	durQtr := qtNext.Sub(qtStart)

	projection := current / durQ2D.Seconds() * durQtr.Seconds()
	return projection
}
851835
func (c Calendar) formatDateTimeComponentYearLength2Plus(year int) string {
	yearShort := year % 100

	if yearShort < 10 {
		return fmt.Sprintf("0%d", yearShort)
	}

	return fmt.Sprintf("%d", yearShort)
}
1365472
func AnyStringToQuarterTime(yyyyqSrcStr string) time.Time {
	yyyyqSrcStr = strings.TrimSpace(yyyyqSrcStr)
	// If not a string, return now time.
	if len(yyyyqSrcStr) != 5 {
		return time.Now().UTC()
	}
	// If not a yyyyq pattern, return now time.
	rx := regexp.MustCompile(`^[0-9]{4}[1-4]$`)
	m := rx.FindString(strings.TrimSpace(yyyyqSrcStr))
	if len(m) != 5 {
		return time.Now().UTC()
	}
	// If cannot parse to integer, return now time.
	yyyyqSrc, err := strconv.Atoi(yyyyqSrcStr)
	if err != nil {
		return time.Now().UTC()
	}
	// Have good yyyyq
	// If yyyySrc == yyyyNow, return now time.
	yyyyqNow := QuarterInt32ForTime(time.Now().UTC())
	if int32(yyyyqSrc) == yyyyqNow {
		return time.Now().UTC()
	}
	// return quarter end time
	dtQtrEnd, err := QuarterInt32EndTime(int32(yyyyqSrc))
	if err != nil {
		return time.Now().UTC()
	}
	return dtQtrEnd.UTC()
}
64231
func (a *SumBucketAggregation) Format(format string) *SumBucketAggregation {
	a.format = format
	return a
}
27191
func (txc *TxConnection) Format(params url.Values) string {
	return fmt.Sprintf(
		"%v\t'%v'\t'%v'\t%v\t%v\t%.6f\t%v\t%v\t\n",
		txc.TransactionID,
		callerid.GetPrincipal(txc.EffectiveCallerID),
		callerid.GetUsername(txc.ImmediateCallerID),
		txc.StartTime.Format(time.StampMicro),
		txc.EndTime.Format(time.StampMicro),
		txc.EndTime.Sub(txc.StartTime).Seconds(),
		txc.Conclusion,
		strings.Join(txc.Queries, ";"),
	)
}
1230945
func (t *Translator) FormatPercent(number float64) string {
	return t.formatNumber(t.parseFormat(t.rules.Numbers.Formats.Percent, true), number)
}
304963
func (c Calendar) formatDateTimeComponentMonthAbbreviated(month int) string {
	switch month {
	case 1:
		return c.FormatNames.Months.Abbreviated.Jan
	case 2:
		return c.FormatNames.Months.Abbreviated.Feb
	case 3:
		return c.FormatNames.Months.Abbreviated.Mar
	case 4:
		return c.FormatNames.Months.Abbreviated.Apr
	case 5:
		return c.FormatNames.Months.Abbreviated.May
	case 6:
		return c.FormatNames.Months.Abbreviated.Jun
	case 7:
		return c.FormatNames.Months.Abbreviated.Jul
	case 8:
		return c.FormatNames.Months.Abbreviated.Aug
	case 9:
		return c.FormatNames.Months.Abbreviated.Sep
	case 10:
		return c.FormatNames.Months.Abbreviated.Oct
	case 11:
		return c.FormatNames.Months.Abbreviated.Nov
	case 12:
		return c.FormatNames.Months.Abbreviated.Dec
	}

	return ""
}