parseFullDurationValue function

Duration? parseFullDurationValue(
  1. String? value
)

Parses a full Duration value from a string.

The string must be in the format of HH:MM:SS.uS.

The micro seconds are padded with zeros to 6 digits for easier use.

Implementation

Duration? parseFullDurationValue(String? value) {
  if (value == null) return null;

  final parts = value.split('.');

  final bigValues = parts.firstOrNull?.split(':');
  final microSeconds = parts.elementAtOrNull(1)?.padRight(6, '0');

  return Duration(
    hours: int.tryParse(bigValues?.elementAtOrNull(0) ?? '0') ?? 0,
    minutes: int.tryParse(bigValues?.elementAtOrNull(1) ?? '0') ?? 0,
    seconds: int.tryParse(bigValues?.elementAtOrNull(2) ?? '0') ?? 0,
    microseconds: int.tryParse(microSeconds ?? '0') ?? 0,
  );
}