// formatDateTimeComponentSecond renders a second component
424381
func (t *Translator) formatDateTimeComponentSecond(datetime time.Time, length int) (string, error) {
	second := datetime.Second()

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

	return "", translatorError{message: fmt.Sprintf("unsupported second: %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])
}
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 ""
}
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
}
724138
func WithTimeFormat(timeformat string) Configurator {
	return func(app *Application) {
		app.config.TimeFormat = timeformat
	}
}
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 ""
}
1324950
func (l Log) FormatTime() string {
	if l.Logger.TimeFormat == "" {
		return ""
	}
	return l.Time.Format(l.Logger.TimeFormat)
}
188182
func (s *CancelResizeOutput) SetElapsedTimeInSeconds(v int64) *CancelResizeOutput {
	s.ElapsedTimeInSeconds = &v
	return s
}
179968
func (c Calendar) formatDateTimeComponentDayOfWeekNarrow(dayOfWeek time.Weekday) string {
	switch dayOfWeek {
	case time.Sunday:
		return c.FormatNames.Days.Narrow.Sun
	case time.Monday:
		return c.FormatNames.Days.Narrow.Mon
	case time.Tuesday:
		return c.FormatNames.Days.Narrow.Tue
	case time.Wednesday:
		return c.FormatNames.Days.Narrow.Wed
	case time.Thursday:
		return c.FormatNames.Days.Narrow.Thu
	case time.Friday:
		return c.FormatNames.Days.Narrow.Fri
	case time.Saturday:
		return c.FormatNames.Days.Narrow.Sat
	}

	return ""
}
1241025
func GetFormatType(format string) (isDuration, isDate bool) {
	format = skipWhiteSpace(format)
	var token string
	var succ bool
	for {
		token, format, succ = getFormatToken(format)
		if len(token) == 0 {
			break
		}
		if !succ {
			isDuration, isDate = false, false
			break
		}
		var durationTokens bool
		var dateTokens bool
		if len(token) >= 2 && token[0] == '%' {
			switch token[1] {
			case 'h', 'H', 'i', 'I', 's', 'S', 'k', 'l':
				durationTokens = true
			case 'y', 'Y', 'm', 'M', 'c', 'b', 'D', 'd', 'e':
				dateTokens = true
			}
		}
		if durationTokens {
			isDuration = true
		} else if dateTokens {
			isDate = true
		}
		if isDuration && isDate {
			break
		}
	}
	return
}
972995
func (c Calendar) 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 "", fmt.Errorf("unsupported hour-12: %d", length)
}
1098223
func FormatDateTime(key string, val time.Time) (string, string) {
	return key, val.UTC().Format("20060102T150405Z")
}
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)
}
1228177
func SetTimeFormat(lo Logger, fo string) error {
	return list.SetTimeFormat(lo, fo)
}
1140385
func (s *RestoreStatus) SetElapsedTimeInSeconds(v int64) *RestoreStatus {
	s.ElapsedTimeInSeconds = &v
	return s
}
733803
func (n *IcsNode) DateDecode() (time.Time, error) {

	// DTEND;VALUE=DATE:20140406
	if val, ok := n.Params["VALUE"]; ok {
		switch {
		case val == "DATE":
			t, err := time.Parse("20060102", n.Val)
			if err != nil {
				return time.Time{}, err
			}
			return t, nil
		case val == "DATE-TIME":
			t, err := time.Parse("20060102T150405", n.Val)
			if err != nil {
				return time.Time{}, err
			}
			return t, nil
		}
	}
	// DTSTART;TZID=Europe/Paris:20140116T120000
	if val, ok := n.Params["TZID"]; ok {
		loc, err := time.LoadLocation(val)
		if err != nil {
			return time.Time{}, err
		}
		t, err := time.ParseInLocation("20060102T150405", n.Val, loc)
		if err != nil {
			return time.Time{}, err
		}
		return t, nil
	}
	//DTSTART:19980119T070000Z utf datetime
	if len(n.Val) == 16 {
		t, err := time.Parse("20060102T150405Z", n.Val)
		if err != nil {
			return time.Time{}, err
		}
		return t, nil
	}

	return time.Time{}, nil
}
662292
func (t *Translator) formatDateTimeComponentDayOfWeekShort(dayOfWeek time.Weekday) string {
	switch dayOfWeek {
	case time.Sunday:
		return t.rules.DateTime.FormatNames.Days.Short.Sun
	case time.Monday:
		return t.rules.DateTime.FormatNames.Days.Short.Mon
	case time.Tuesday:
		return t.rules.DateTime.FormatNames.Days.Short.Tue
	case time.Wednesday:
		return t.rules.DateTime.FormatNames.Days.Short.Wed
	case time.Thursday:
		return t.rules.DateTime.FormatNames.Days.Short.Thu
	case time.Friday:
		return t.rules.DateTime.FormatNames.Days.Short.Fri
	case time.Saturday:
		return t.rules.DateTime.FormatNames.Days.Short.Sat
	}

	return ""
}