format method
String
format(
{ - bool hours = true,
- bool minutes = true,
- bool seconds = true,
- bool shrink = false,
- bool shrinkHours = true,
- bool shrinkMinutes = true,
- 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;
}