Fixes time display of current/next song UI. Adds localized formatting code for start times of shows current and next.
This commit is contained in:
+31
-7
@@ -1,11 +1,35 @@
|
||||
String formatTimeWindow(String? starts, String? ends) {
|
||||
String formatOne(String? value) {
|
||||
if (value == null || value.length < 16) {
|
||||
return '--:--';
|
||||
}
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
return value.substring(11, 16);
|
||||
// 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 '${formatOne(starts)} - ${formatOne(ends)}';
|
||||
return "--:--";
|
||||
}
|
||||
|
||||
String formatStartingTime(String? startingTime) {
|
||||
if (startingTime != null) {
|
||||
DateTime dtStartTime = DateTime.parse(startingTime);
|
||||
return DateFormat('jm').format(dtStartTime);
|
||||
}
|
||||
return "--:--";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user