Vaani/lib/shared/extensions/duration_format.dart

19 lines
566 B
Dart
Raw Normal View History

2024-06-16 22:24:32 -04:00
extension DurationFormat on Duration {
/// formats the duration of the book as `10h 30m`
///
/// will add up all the durations of the audio files first
/// then convert them to the given format
String get formattedBinary {
final hours = inHours;
final minutes = inMinutes.remainder(60);
return '${hours}h ${minutes}m';
}
}
2024-06-28 06:01:56 -04:00
extension OnlyTime on DateTime {
// in format HH:MM:ss
// padding with 0
String get time =>
'${hour.toString().padLeft(2, '0')}:${minute.toString().padLeft(2, '0')}:${second.toString().padLeft(2, '0')}';
}