getAlignmentUnit function Null safety

Duration getAlignmentUnit(
  1. Duration interval
)

Returns an alignment unit can be passed to alignDateTime in order to align the date/time units. For example, if the specified interval is 15 minutes, the alignment unit is 1 minute.

Implementation

Duration getAlignmentUnit(Duration interval) {
  return Duration(
    days: interval.inDays > 0 ? 1 : 0,
    hours: interval.inDays == 0 && interval.inHours > 0 ? 1 : 0,
    minutes: interval.inHours == 0 && interval.inMinutes > 0 ? 1 : 0,
    seconds: interval.inMinutes == 0 && interval.inSeconds > 0 ? 1 : 0,
    milliseconds:
        interval.inSeconds == 0 && interval.inMilliseconds > 0 ? 1 : 0,
    microseconds:
        interval.inMilliseconds == 0 && interval.inMicroseconds > 0 ? 1 : 0,
  );
}