mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-02 23:17:17 +00:00
27 lines
791 B
Dart
27 lines
791 B
Dart
// ignore_for_file: unnecessary_this
|
|
|
|
import 'dart:ui';
|
|
|
|
import 'package:duration/duration.dart';
|
|
import 'package:duration/locale.dart';
|
|
|
|
extension DurationFormatter on Duration {
|
|
String toTimezoneOffsetFormat() {
|
|
final designator = this >= Duration.zero ? '+' : '-';
|
|
|
|
final Iterable<String> segments = [
|
|
this.inHours.remainder(24).abs(),
|
|
this.inMinutes.remainder(60).abs(),
|
|
].map((final int seg) => seg.toString().padLeft(2, '0'));
|
|
|
|
return '$designator${segments.first}:${segments.last}';
|
|
}
|
|
|
|
String toPrettyString(final Locale locale) =>
|
|
prettyDuration(this, locale: getDurationLocale(locale));
|
|
}
|
|
|
|
DurationLocale getDurationLocale(final Locale locale) =>
|
|
DurationLocale.fromLanguageCode(locale.languageCode) ??
|
|
const EnglishDurationLocale();
|