Closed liplum closed 9 months ago
I made this.
extension DurationX on Duration {
IsoDuration toIso() {
final isNegativeDuration = isNegative;
// Convert the absolute value of each duration component
final years = inDays ~/ 365;
final months = (inDays % 365) ~/ 30;
final weeks = ((inDays % 365) % 30) ~/ 7;
final days = ((inDays % 365) % 30) % 7;
final hours = inHours % 24;
final minutes = inMinutes % 60;
final seconds = inSeconds % 60;
return IsoDuration(
years: years,
months: months,
weeks: weeks,
days: days,
hours: hours,
minutes: minutes,
seconds: seconds,
isNegativeDuration: isNegativeDuration,
);
}
}
Thanks a lot, I added your extension in v0.16.0!
Help wanted
I don't really know IsoDuration format and how to convert it to Dart
Duration
. So I was looking for aDuration.toIsoDuration()
function in the source code, but I didn't.Would you like to provide an extension function, a named/factory constructor, or a static function to convert
Duration
object toIsoDuration
object? That would be very helpful.