toSeconds method

double toSeconds()

Calculates total duration in seconds as a sum of all individual parts (except years and months) from the IsoDuration object.

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(
    isPrecise,
    'years and months values of the IsoDuration object must be equal to 0!',
  );
  final weeksToSecs = weeks * _secsInDay * 7;
  final daysToSecs = days * _secsInDay;
  final hrsToSecs = hours * _secsInHour;
  final minsToSecs = minutes * 60;
  return weeksToSecs + daysToSecs + hrsToSecs + minsToSecs + seconds;
}