formatHour method

  1. @override
String formatHour(
  1. TimeOfDay timeOfDay, {
  2. bool alwaysUse24HourFormat = false,
})
override

Formats TimeOfDay.hour in the given time of day according to the value of timeOfDayFormat.

If alwaysUse24HourFormat is true, formats hour using HourFormat.HH rather than the default for the current locale.

Implementation

@override
String formatHour(TimeOfDay timeOfDay, { bool alwaysUse24HourFormat = false }) {
  switch (hourFormat(of: timeOfDayFormat(alwaysUse24HourFormat: alwaysUse24HourFormat))) {
    case HourFormat.HH:
      return _twoDigitZeroPaddedFormat.format(timeOfDay.hour);
    case HourFormat.H:
      return formatDecimal(timeOfDay.hour);
    case HourFormat.h:
      final int hour = timeOfDay.hourOfPeriod;
      return formatDecimal(hour == 0 ? 12 : hour);
  }
}