format method
Formats the duration with a custom format string.
Supported tokens:
YorYY- YearsMorMM- MonthsDorDD- DaysHorHH- Hoursmormm- Minutessorss- Seconds
Implementation
String format(String formatStr) {
var result = formatStr;
// Calculate total values (kept for potential future use)
// final totalDays = this.days + (weeks * 7) + (months * 30) + (years * 365);
// final totalHours = hours + (totalDays * 24);
// final totalMinutes = minutes + (totalHours * 60);
// final totalSeconds = seconds + (totalMinutes * 60);
// Replace tokens
result = result.replaceAll('YY', years.toString().padLeft(2, '0'));
result = result.replaceAll('Y', years.toString());
result = result.replaceAll('MM', months.toString().padLeft(2, '0'));
result = result.replaceAll('M', months.toString());
result = result.replaceAll('DD', days.toString().padLeft(2, '0'));
result = result.replaceAll('D', days.toString());
result = result.replaceAll('HH', hours.toString().padLeft(2, '0'));
result = result.replaceAll('H', hours.toString());
result = result.replaceAll('mm', minutes.toString().padLeft(2, '0'));
result = result.replaceAll('m', minutes.toString());
result = result.replaceAll('ss', seconds.toString().padLeft(2, '0'));
result = result.replaceAll('s', seconds.toString());
return result;
}