format method

String format({
  1. bool hours = true,
  2. bool minutes = true,
  3. bool seconds = true,
  4. bool shrink = false,
  5. bool shrinkHours = true,
  6. bool shrinkMinutes = true,
  7. bool shrinkSeconds = true,
})

Implementation

String format({
  bool hours = true,
  bool minutes = true,
  bool seconds = true,
  bool shrink = false,
  bool shrinkHours = true,
  bool shrinkMinutes = true,
  bool shrinkSeconds = true,
}) {
  final hh = (this?.inHours ?? 0).toString().padLeft(2, '0');
  final mm =
      ((this?.inMinutes ?? 0).remainder(60)).toString().padLeft(2, '0');
  final ss =
      ((this?.inSeconds ?? 0).remainder(60)).toString().padLeft(2, '0');

  var result = '';

  final showHours = shrink && shrinkHours ? hours && hh != '00' : hours;
  final showMinutes =
      shrink && shrinkMinutes ? minutes && mm != '00' : minutes;
  final showSeconds =
      shrink && shrinkSeconds ? seconds || ss != '00' : seconds;

  if (showHours) result += hh;
  if (showHours && showMinutes) result += ':';
  if (showMinutes) result += mm;
  if ((showHours || showMinutes) && showSeconds) result += ':';
  if (showSeconds) result += ss;

  return result;
}