floatToTime12 method

String floatToTime12(
  1. double time, {
  2. bool suffix = true,
})

Implementation

String floatToTime12(double time, {bool suffix = true}) {
  if (time.isNaN) return InvalidTime;
  time = fixhour(time + 0.5 / 60); // add 0.5 minutes to round
  int hours = time.floor();
  final int minutes = ((time - hours) * 60).floor();
  final String suffixStr = suffix ? (hours >= 12 ? ' PM' : ' AM') : '';
  hours = ((hours + 12 - 1) % 12 + 1);
  return '$hours:${twoDigitsFormat(minutes)}$suffixStr';
}