35 lines
1.1 KiB
Dart
35 lines
1.1 KiB
Dart
import 'package:intl/intl.dart';
|
|
|
|
// Source - https://stackoverflow.com/a/54775297
|
|
// Posted by diegoveloper, modified by community. See post 'Timeline' for change history
|
|
// Retrieved 2026-05-09, License - CC BY-SA 4.0
|
|
|
|
String _printDuration(Duration duration) {
|
|
String negativeSign = duration.isNegative ? '-' : '';
|
|
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
|
String twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60).abs());
|
|
String twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60).abs());
|
|
return "$negativeSign$twoDigitMinutes:$twoDigitSeconds";
|
|
}
|
|
|
|
String formatTimeWindow(String? starts, String? ends) {
|
|
if (starts != null && ends != null) {
|
|
DateTime startDt = DateTime.parse(starts);
|
|
DateTime endDt = DateTime.parse(ends);
|
|
|
|
Duration songLength = endDt.difference(startDt);
|
|
|
|
return _printDuration(songLength);
|
|
}
|
|
|
|
return "--:--";
|
|
}
|
|
|
|
String formatStartingTime(String? startingTime) {
|
|
if (startingTime != null) {
|
|
DateTime dtStartTime = DateTime.parse(startingTime);
|
|
return DateFormat('jm').format(dtStartTime);
|
|
}
|
|
return "--:--";
|
|
}
|