toSeconds method

double toSeconds()

Calculates total duration only in seconds from the IsoDuration object. It is a sum of all individual parts, except years and months.

Note: values years and months of IsoDuration must be equal to 0. Otherwise, it is not possible to accurately count the total of seconds.

For example:

final dur = IsoDuration(hours: 1, minutes: 2, seconds: 5.5)
dur.toSeconds(); // 3725.5

Implementation

double toSeconds() {
  assert(years == 0 && months == 0,
      'years and months values of the IsoDuration object must be 0!');
  const secsInDay = 86400;
  const secsInHour = 3600;

  final weeksInSecs = weeks * secsInDay * 7;
  final daysInSecs = days * secsInDay;
  final hrsInSecs = hours * secsInHour;
  final minsInSecs = minutes * 60;
  return weeksInSecs + daysInSecs + hrsInSecs + minsInSecs + seconds;
}