// formatDateTimeComponentPeriod renders a period component (AM/PM).
352387
func (t *Translator) formatDateTimeComponentPeriod(datetime time.Time, length int) (string, error) {
	hour := datetime.Hour()

	switch length {
	case datetimeFormatLength1Plus:
		return t.formatDateTimeComponentPeriodWide(hour), nil
	case datetimeFormatLengthAbbreviated:
		return t.formatDateTimeComponentPeriodAbbreviated(hour), nil
	case datetimeFormatLengthWide:
		return t.formatDateTimeComponentPeriodWide(hour), nil
	case datetimeFormatLengthNarrow:
		return t.formatDateTimeComponentPeriodNarrow(hour), nil
	}

	return "", translatorError{message: fmt.Sprintf("unsupported day-period: %d", length)}
}
908003
func (s *CloudWatchAlarmConfiguration) SetPeriod(v int64) *CloudWatchAlarmConfiguration {
	s.Period = &v
	return s
}
897211
func (c Calendar) formatDateTimeComponentMonthNarrow(month int) string {
	switch month {
	case 1:
		return c.FormatNames.Months.Narrow.Jan
	case 2:
		return c.FormatNames.Months.Narrow.Feb
	case 3:
		return c.FormatNames.Months.Narrow.Mar
	case 4:
		return c.FormatNames.Months.Narrow.Apr
	case 5:
		return c.FormatNames.Months.Narrow.May
	case 6:
		return c.FormatNames.Months.Narrow.Jun
	case 7:
		return c.FormatNames.Months.Narrow.Jul
	case 8:
		return c.FormatNames.Months.Narrow.Aug
	case 9:
		return c.FormatNames.Months.Narrow.Sep
	case 10:
		return c.FormatNames.Months.Narrow.Oct
	case 11:
		return c.FormatNames.Months.Narrow.Nov
	case 12:
		return c.FormatNames.Months.Narrow.Dec
	}

	return ""
}
18100
func (s *DescribeAlarmsForMetricInput) SetPeriod(v int64) *DescribeAlarmsForMetricInput {
	s.Period = &v
	return s
}
162988
func (s *GetTagsInput) SetTimePeriod(v *DateInterval) *GetTagsInput {
	s.TimePeriod = v
	return s
}
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)}
}
830442
func (t *Translator) formatDateTimeComponentMonth2Plus(month int) string {
	if month < 10 {
		return fmt.Sprintf("0%d", month)
	}
	return fmt.Sprintf("%d", month)
}
848166
func (servo *Servo) SetPeriod(milliseconds int) error {
	return servo.PWM.SetPeriod(servo.Pin, int64(milliseconds*1000000))
}
436231
func (s *ResultByTime) SetTimePeriod(v *DateInterval) *ResultByTime {
	s.TimePeriod = v
	return s
}
312208
func (s *CloudWatchLogsLogStream) SetDatetimeFormat(v string) *CloudWatchLogsLogStream {
	s.DatetimeFormat = &v
	return s
}
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 ""
}
933043
func (t Time) DateFormat(layout string) (string, error) {
	var buf bytes.Buffer
	inPatternMatch := false
	for _, b := range layout {
		if inPatternMatch {
			if err := t.convertDateFormat(b, &buf); err != nil {
				return "", errors.Trace(err)
			}
			inPatternMatch = false
			continue
		}

		// It's not in pattern match now.
		if b == '%' {
			inPatternMatch = true
		} else {
			buf.WriteRune(b)
		}
	}
	return buf.String(), nil
}
379107
func (s *ForecastResult) SetTimePeriod(v *DateInterval) *ForecastResult {
	s.TimePeriod = v
	return s
}
1273856
func (cfg Config) FormatRelativeDuration(d time.Duration) string {

	isPast := d >= 0

	if d < 0 {
		d = -d
	}

	s, _ := cfg.getTimeText(d, true)

	if isPast {
		return strings.Join([]string{cfg.PastPrefix, s, cfg.PastSuffix}, "")
	} else {
		return strings.Join([]string{cfg.FuturePrefix, s, cfg.FutureSuffix}, "")
	}
}
46595
func (g *gossip) ProtocolPeriod() {
	startTime := time.Now()

	g.node.pingNextMember()
	endTime := time.Now()

	g.protocol.Lock()

	lag := endTime.Sub(g.protocol.lastPeriod)
	wasFirst := (g.protocol.numPeriods == 0)

	g.protocol.lastPeriod = endTime
	g.protocol.numPeriods++
	g.protocol.timing.Update(int64(time.Now().Sub(startTime)))
	g.protocol.Unlock()

	if !wasFirst {
		g.node.EmitEvent(ProtocolFrequencyEvent{
			Duration: lag,
		})
	}
}
242735
func (s *Session) RenewPeriodic(initialTTL string, id string, q *WriteOptions, doneCh <-chan struct{}) error {
	ctx := q.Context()

	ttl, err := time.ParseDuration(initialTTL)
	if err != nil {
		return err
	}

	waitDur := ttl / 2
	lastRenewTime := time.Now()
	var lastErr error
	for {
		if time.Since(lastRenewTime) > ttl {
			return lastErr
		}
		select {
		case <-time.After(waitDur):
			entry, _, err := s.Renew(id, q)
			if err != nil {
				waitDur = time.Second
				lastErr = err
				continue
			}
			if entry == nil {
				return ErrSessionExpired
			}

			// Handle the server updating the TTL
			ttl, _ = time.ParseDuration(entry.TTL)
			waitDur = ttl / 2
			lastRenewTime = time.Now()

		case <-doneCh:
			// Attempt a session destroy
			s.Destroy(id, q)
			return nil

		case <-ctx.Done():
			// Bail immediately since attempting the destroy would
			// use the canceled context in q, which would just bail.
			return ctx.Err()
		}
	}
}
840118
func (s *MetricAlarm) SetPeriod(v int64) *MetricAlarm {
	s.Period = &v
	return s
}