2022-01-25 17:00:47 +00:00
|
|
|
// ignore_for_file: unnecessary_this
|
|
|
|
|
|
|
|
extension DurationFormatter on Duration {
|
2022-06-05 22:40:34 +00:00
|
|
|
String toDayHourMinuteSecondFormat() => [
|
|
|
|
this.inHours.remainder(24),
|
|
|
|
this.inMinutes.remainder(60),
|
|
|
|
this.inSeconds.remainder(60)
|
|
|
|
].map((final int seg) => seg.toString().padLeft(2, '0')).join(':');
|
2022-01-25 17:00:47 +00:00
|
|
|
|
|
|
|
String toDayHourMinuteFormat() {
|
2022-06-05 22:40:34 +00:00
|
|
|
final designator = this >= Duration.zero ? '+' : '-';
|
2022-01-25 17:00:47 +00:00
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
final Iterable<String> segments = [
|
2022-01-25 17:00:47 +00:00
|
|
|
this.inHours.remainder(24).abs(),
|
|
|
|
this.inMinutes.remainder(60).abs(),
|
2022-06-05 22:40:34 +00:00
|
|
|
].map((final int seg) => seg.toString().padLeft(2, '0'));
|
2022-01-25 17:00:47 +00:00
|
|
|
|
|
|
|
return '$designator${segments.first}:${segments.last}';
|
|
|
|
}
|
|
|
|
|
2022-06-05 22:40:34 +00:00
|
|
|
// WAT: https://flutterigniter.com/how-to-format-duration/
|
|
|
|
String toHoursMinutesSecondsFormat() =>
|
|
|
|
this.toString().split('.').first.padLeft(8, '0');
|
2022-01-25 17:00:47 +00:00
|
|
|
|
|
|
|
String toDayHourMinuteFormat2() {
|
2022-06-05 22:40:34 +00:00
|
|
|
final Iterable<String> segments = [
|
2022-01-25 17:00:47 +00:00
|
|
|
this.inHours.remainder(24),
|
|
|
|
this.inMinutes.remainder(60),
|
2022-06-05 22:40:34 +00:00
|
|
|
].map((final int seg) => seg.toString().padLeft(2, '0'));
|
2022-05-24 18:55:39 +00:00
|
|
|
return '${segments.first} h ${segments.last} min';
|
2022-01-25 17:00:47 +00:00
|
|
|
}
|
|
|
|
}
|