toTimeString method

String toTimeString({
  1. bool? showHours,
})

Implementation

String toTimeString({bool? showHours}) {
  String twoDigits(int n) {
    if (n >= 10) return "$n";
    return "0$n";
  }

  if (inMicroseconds < 0) {
    return "-${-this}";
  }
  String twoDigitMinutes =
      twoDigits(inMinutes.remainder(Duration.minutesPerHour));
  String twoDigitSeconds =
      twoDigits(inSeconds.remainder(Duration.secondsPerMinute));
  String twoDigitHours = twoDigits(inHours);
  return showHours ?? inHours > 0
      ? "$twoDigitHours:$twoDigitMinutes:$twoDigitSeconds"
      : "$twoDigitMinutes:$twoDigitSeconds";
}