toString method

  1. @override
String toString({
  1. bool reduce = true,
})
override

In commands when Time is used, string are generated dynamically. When days can be expressed in 0.5 steps, the suffix d is generated. When seconds can be expressed in 0.25 steps, the suffix s is generated.

So a word of warning, even when providing integer ticks, objD can decide to simplify the commands. For example Time(10) becomes 0.5s. This behaviour might change in the future, if there are serious concerns.

In case you want to have just the ticks, either use .ticks on a Time object or call toString with reduce set to false: Time(10).toString(reduce=false) => 10.

Implementation

@override
String toString({bool reduce = true}) {
  if (isInfinite) throw "Called .toString on an infinite time";

  if (reduce && ticks % (_TICKSINDAY / 2) == 0) {
    return '${ticks / _TICKSINDAY}d'.replaceFirst('.0d', 'd');
  }
  if (reduce && ticks % (_TICKSINSECOND / 4) == 0) {
    return '${ticks / _TICKSINSECOND}s'.replaceFirst('.0s', 's');
  }
  return ticks.toString();
}