chore: sleep timer custom hour format

This commit is contained in:
Kingkor Roy Tirtho 2023-06-20 09:39:27 +06:00
parent b78e7f57a0
commit c93c229b0f
4 changed files with 32 additions and 1 deletions

View File

@ -171,7 +171,7 @@ class PlayerActions extends HookConsumerWidget {
title: Text(
customHoursEnabled
? context.l10n.custom_hours
: sleepTimer.toHumanReadableString(),
: sleepTimer.format(abbreviated: true),
),
// only enabled when there's no preset timers selected
enabled: customHoursEnabled,

View File

@ -1,6 +1,28 @@
import 'package:duration/locale.dart';
import 'package:spotube/utils/primitive_utils.dart';
import 'package:duration/duration.dart';
extension DurationToHumanReadableString on Duration {
String toHumanReadableString() =>
"${inMinutes.remainder(60)}:${PrimitiveUtils.zeroPadNumStr(inSeconds.remainder(60))}";
String format({
DurationTersity tersity = DurationTersity.second,
DurationTersity upperTersity = DurationTersity.week,
DurationLocale locale = const EnglishDurationLocale(),
String? spacer,
String? delimiter,
String? conjugation,
bool abbreviated = false,
}) =>
printDuration(
this,
tersity: tersity,
upperTersity: upperTersity,
locale: locale,
spacer: spacer,
delimiter: delimiter,
conjugation: conjugation,
abbreviated: abbreviated,
);
}

View File

@ -474,6 +474,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.0"
duration:
dependency: "direct main"
description:
name: duration
sha256: d0b29d0a345429e3986ac56d60e4aef65b37d11e653022b2b9a4b361332b777f
url: "https://pub.dev"
source: hosted
version: "3.0.12"
envied:
dependency: "direct main"
description:

View File

@ -103,6 +103,7 @@ dependencies:
media_kit_native_event_loop: ^1.0.4
dbus: ^0.7.8
background_downloader: ^7.4.0
duration: ^3.0.12
dev_dependencies:
build_runner: ^2.3.2