secondsToTimeLeft method

String secondsToTimeLeft()

Implementation

String secondsToTimeLeft() {
  final int h = this ~/ 3600;
  final int m = (this - h * 3600) ~/ 60;
  final int s = this - (h * 3600) - (m * 60);

  final String hourLeft = h.toString().length < 2 ? "0$h" : h.toString();
  final String minuteLeft = m.toString().length < 2 ? "0$m" : m.toString();
  final String secondsLeft = s.toString().length < 2 ? "0$s" : s.toString();

  String result = "";

  if (minuteLeft == "00") {
    result = secondsLeft;
  } else if (hourLeft == "00") {
    result = "$minuteLeft:$secondsLeft";
  } else {
    result = "$hourLeft:$minuteLeft:$secondsLeft";
  }
  return result;
}