quantize method
Rounds this to a value divisible by amount.
The result will be the nearest time divisible by amount that's
earlier than or the same as this. If amount is negative,
the result will be the nearest time later than or the same as this.
In other words, this returns floor(this / amount * amount) if
this is positive, and ceiling(this / amount * amount) if this is
negative.
Examples:
final time = LocalTime(4, 5, 6, 7);
expect(time.quantize(Timespan(days: 1)), hasTime(0));
expect(time.quantize(Timespan(hours: 3)), hasTime(3));
expect(time.quantize(Timespan(minutes: 10)), hasTime(4, 0));
expect(time.quantize(Timespan(seconds: 4)), hasTime(4, 5, 4));
expect(time.quantize(Timespan(nanoseconds: 5)), hasTime(4, 5, 6, 5));
Implementation
@experimental
LocalTime quantize(Timespan amount) => LocalTime(
0,
0,
0,
(nanosecondsSinceMidnight / amount.inNanoseconds).floor() *
amount.inNanoseconds);