2022-01-25 17:00:47 +00:00
|
|
|
// ignore_for_file: unnecessary_this
|
|
|
|
|
2023-07-02 15:23:33 +00:00
|
|
|
import 'dart:ui';
|
|
|
|
|
|
|
|
import 'package:duration/duration.dart';
|
|
|
|
import 'package:duration/locale.dart';
|
2022-01-25 17:00:47 +00:00
|
|
|
|
2023-07-02 15:23:33 +00:00
|
|
|
extension DurationFormatter on Duration {
|
|
|
|
String toTimezoneOffsetFormat() {
|
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}';
|
|
|
|
}
|
|
|
|
|
2023-07-02 15:23:33 +00:00
|
|
|
String toPrettyString(final Locale locale) =>
|
|
|
|
prettyDuration(this, locale: getDurationLocale(locale));
|
2022-01-25 17:00:47 +00:00
|
|
|
}
|
2023-07-02 15:23:33 +00:00
|
|
|
|
|
|
|
DurationLocale getDurationLocale(final Locale locale) =>
|
|
|
|
DurationLocale.fromLanguageCode(locale.languageCode) ??
|
|
|
|
const EnglishDurationLocale();
|