// formatDateTimeComponentDay renders a day-of-year component.
184713
func (t *Translator) formatDateTimeComponentDay(datetime time.Time, length int) (string, error) {
	day := datetime.Day()

	switch length {
	case datetimeFormatLength1Plus:
		return fmt.Sprintf("%d", day), nil
	case datetimeFormatLength2Plus:
		if day < 10 {
			return fmt.Sprintf("0%d", day), nil
		}
		return fmt.Sprintf("%d", day), nil
	}

	return "", translatorError{message: fmt.Sprintf("unsupported day-of-year: %d", length)}
}
259730
func Format(ts *timestamp.Timestamp, layout string) string {
	return Time(ts).Format(layout)
}
85359
func (self *StandardFormatter) FormatAll(record *LogRecord) string {
	return fmt.Sprintf(self.strFormat, self.getFormatArgsFunc(record)...)
}
1156873
func formatListTime(t keybase1.Time) string {
	layout := "2006-01-02 15:04:05"
	return keybase1.FromTime(t).Format(layout)
}
1290430
func (s *Room) SetProviderCalendarId(v string) *Room {
	s.ProviderCalendarId = &v
	return s
}
508778
func (c Calendar) formatDateTimeComponentQuarter(datetime time.Time, length int) (string, error) {
	return "", nil
}
199270
func FormatTime(t *time.Time, formatISO bool) string {
	if formatISO {
		// If requested, use ISO time format.
		// The format we use is RFC3339 without the "T". From the spec:
		// NOTE: ISO 8601 defines date and time separated by "T".
		// Applications using this syntax may choose, for the sake of
		// readability, to specify a full-date and full-time separated by
		// (say) a space character.
		return t.UTC().Format("2006-01-02 15:04:05Z")
	}
	// Otherwise use local time.
	return t.Local().Format("02 Jan 2006 15:04:05Z07:00")
}
339066
func (b *builtinTimeFormatSig) formatTime(ctx sessionctx.Context, t types.Duration, formatMask string) (res string, err error) {
	t2 := types.Time{
		Time: types.FromDate(0, 0, 0, t.Hour(), t.Minute(), t.Second(), t.MicroSecond()),
		Type: mysql.TypeDate, Fsp: 0}

	str, err := t2.DateFormat(formatMask)
	return str, err
}
700422
func (c *Carbon) SetDay(d int) {
	c.Time = time.Date(c.Year(), c.Month(), d, c.Hour(), c.Minute(), c.Second(), c.Nanosecond(), c.Location())
}
82600
func (cfg Config) FormatReference(t time.Time, reference time.Time) string {

	d := reference.Sub(t)

	if (d >= 0 && d >= cfg.Max) || (d < 0 && -d >= cfg.Max) {
		return t.Format(cfg.DefaultLayout)
	}

	return cfg.FormatRelativeDuration(d)
}
856362
func ParseAndGetLayout(date string) (time.Time, string, error) {
	if len(strings.TrimSpace(date)) == 0 {
		return time.Time{}, "", errors.New("Empty string cannot be parsed to date")
	}
	// Check standard date formats first.
	for _, f := range standardDateFormats {
		if t, err := time.Parse(f, date); err == nil {
			return t, f, nil
		}
	}
	s := strings.ToLower(date)
	layout := &bytes.Buffer{}
	prefix := getPrefix(s)
	layout.WriteString(prefix)
	s = strings.TrimPrefix(s, prefix)

	// Check for day of week.
	for _, d := range daysOfWeek {
		if strings.HasPrefix(s, d) {
			s = strings.TrimPrefix(s, d)
			layout.WriteString(formatEEEE)
		}
	}
	for _, d := range daysOfWeekShort {
		if strings.HasPrefix(s, d) {
			s = strings.TrimPrefix(s, d)
			layout.WriteString(formatEEE)
		}
	}

	// Get rid of prefix and suffix.
	prefix = getPrefix(s)
	separators := separatorRegex.FindAllStringSubmatch(s, -1)
	if len(prefix) > 0 {
		s = strings.TrimPrefix(s, prefix)
		layout.WriteString(prefix)
		separators = separators[1:]
	}
	var suffix string
	if len(separators) > 0 && strings.HasSuffix(s, separators[len(separators)-1][0]) {
		suffix = separators[len(separators)-1][0]
		s = strings.TrimSuffix(s, suffix)
		separators = separators[:len(separators)-1]
	}

	// Narrow down formats needed to check.
	// TODO: Make more efficient by checking fewer formats variations.
	var formats []string
	containsTime := containsTime(date)
	containsTimezone := containsTimezone(date)
	var onlyTime bool
	if containsLongMonth(s) {
		formats = dateFormatsWithLongMonth
	} else if containsShortMonth(s) {
		formats = dateFormatsWithShortMonth
	} else if (len(separators) <= 3 && containsTime && containsTimezone) || (len(separators) <= 2 && containsTime) {
		if containsTimezone {
			formats = getCombinations(timeFormats, timeZoneFormats, false)
		} else {
			formats = timeFormats
		}
		onlyTime = true
	} else if len(separators) == 0 {
		// If the date is all munged together, assume year is first rather than month.
		formats = dateFormatsNumericYearFirst
	} else {
		formats = dateFormatsNumeric
	}
	if containsTimezone {
		// time.Parse only accepts uppercase timezones names, so need to convert back.
		if tz := timezoneRegex.FindStringSubmatch(date); len(tz) > 0 {
			s = strings.Replace(s, strings.ToLower(tz[0]), tz[0], -1)
		}
	}

	// Check possible formats.
	for _, f := range formats {
		variations := getVariations(f, containsTime && !onlyTime, containsTimezone && !onlyTime)
		var correct string
		for _, v := range variations {
			if strings.Contains(v, ":") {
				v = strings.Replace(v, ":", ".", -1)
			}
			l := formatWithSeparators(v, separators)
			if _, err := time.Parse(l, s); err == nil {
				correct = l
				break
			}
		}
		if len(correct) > 0 {
			layout.WriteString(correct)
			break
		}
	}
	layout.WriteString(suffix)

	// Return Date and format.
	date = strings.Replace(date, "AM", "am", -1)
	date = strings.Replace(date, "PM", "pm", -1)
	t, err := time.Parse(layout.String(), date)
	if err != nil {
		return time.Time{}, "", err
	}
	return t, layout.String(), err
}
170065
func (t *Translator) formatDateTimeComponentMonth(datetime time.Time, length int) (string, error) {

	month := int(datetime.Month())

	switch length {
	case datetimeFormatLength1Plus:
		return t.formatDateTimeComponentMonth1Plus(month), nil
	case datetimeFormatLength2Plus:
		return t.formatDateTimeComponentMonth2Plus(month), nil
	case datetimeFormatLengthAbbreviated:
		return t.formatDateTimeComponentMonthAbbreviated(month), nil
	case datetimeFormatLengthWide:
		return t.formatDateTimeComponentMonthWide(month), nil
	case datetimeFormatLengthNarrow:
		return t.formatDateTimeComponentMonthNarrow(month), nil
	}

	return "", translatorError{message: fmt.Sprintf("unsupported month length: %d", length)}
}
707403
func (c Calendar) formatDateTimeComponent(datetime time.Time, pattern string) (string, error) {
	switch pattern[0:1] {
	case string(datetimeFormatUnitEra):
		return c.formatDateTimeComponentEra(datetime, len(pattern))
	case string(datetimeFormatUnitYear):
		return c.formatDateTimeComponentYear(datetime, len(pattern))
	case string(datetimeFormatUnitMonth):
		return c.formatDateTimeComponentMonth(datetime, len(pattern))
	case string(datetimeFormatUnitDayOfWeek):
		return c.formatDateTimeComponentDayOfWeek(datetime, len(pattern))
	case string(datetimeFormatUnitDay):
		return c.formatDateTimeComponentDay(datetime, len(pattern))
	case string(datetimeFormatUnitHour12):
		return c.formatDateTimeComponentHour12(datetime, len(pattern))
	case string(datetimeFormatUnitHour24):
		return c.formatDateTimeComponentHour24(datetime, len(pattern))
	case string(datetimeFormatUnitMinute):
		return c.formatDateTimeComponentMinute(datetime, len(pattern))
	case string(datetimeFormatUnitSecond):
		return c.formatDateTimeComponentSecond(datetime, len(pattern))
	case string(datetimeFormatUnitPeriod):
		return c.formatDateTimeComponentPeriod(datetime, len(pattern))
	case string(datetimeForamtUnitQuarter):
		return c.formatDateTimeComponentQuarter(datetime, len(pattern))
	case string(datetimeFormatUnitTimeZone1):
		fallthrough
	case string(datetimeFormatUnitTimeZone2):
		return c.formatDateTimeComponentTimeZone(datetime, len(pattern))
	}

	return "", errors.New("unknown datetime format unit: " + pattern[0:1])
}
1244727
func (c Calendar) formatDateTimeComponentMonth2Plus(month int) string {
	if month < 10 {
		return fmt.Sprintf("0%d", month)
	}
	return fmt.Sprintf("%d", month)
}
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
}
284426
func convertTimeFormat(layout string) string {
	for format, conv := range convertMapping {
		layout = strings.Replace(layout, format, conv, -1)
	}
	return layout
}
113675
func (t *Translator) formatDateTimeComponentHour12(datetime time.Time, length int) (string, error) {
	hour := datetime.Hour()
	if hour > 12 {
		hour = hour - 12
	}

	switch length {
	case datetimeFormatLength1Plus:
		return fmt.Sprintf("%d", hour), nil
	case datetimeFormatLength2Plus:
		if hour < 10 {
			return fmt.Sprintf("0%d", hour), nil
		}
		return fmt.Sprintf("%d", hour), nil
	}

	return "", translatorError{message: fmt.Sprintf("unsupported hour-12: %d", length)}
}