formatCurrentPrecision method

  1. @override
  2. @protected
bool formatCurrentPrecision(
  1. StringJoiner sj,
  2. int lastPrecision,
  3. int currentPrecision,
  4. double durationMs,
)
override

Return value indicates whether to stop the loop

Implementation

@override
@protected bool formatCurrentPrecision(StringJoiner sj, int lastPrecision, int currentPrecision, double durationMs)
{
  // Show days or hours if at least one, otherwise skip.
  if (currentPrecision >= TimePrecision.HOURS) {
    if (durationMs < currentPrecision) {
      return false; // Skip if not at least 1.
    }
  }

  double numerator = durationMs;

  if (lastPrecision != 0) {
    numerator = numerator % lastPrecision.toDouble();
  }

  // Handles all.
  sj.add( StringUtil.padNumber( ( numerator / currentPrecision.toDouble() ).floor().toDouble(), _PAD_VALUE) );

  return false; // Always continue loop.
}