mirror of
https://github.com/HChaZZY/PiliPlus.git
synced 2025-12-17 23:56:13 +08:00
feat: match info
opt dateformat Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
29
lib/utils/duration_util.dart
Normal file
29
lib/utils/duration_util.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'dart:math' show pow;
|
||||
|
||||
class DurationUtil {
|
||||
static String formatDuration(num? seconds) {
|
||||
if (seconds == null || seconds == 0) {
|
||||
return '00:00';
|
||||
}
|
||||
int h = seconds ~/ 3600;
|
||||
seconds %= 3600;
|
||||
int m = seconds ~/ 60;
|
||||
seconds %= 60;
|
||||
String sms = seconds is double
|
||||
? seconds.toStringAsFixed(3).padLeft(6, '0')
|
||||
: seconds.toString().padLeft(2, '0');
|
||||
return h == 0
|
||||
? "${m.toString().padLeft(2, '0')}:$sms"
|
||||
: "${h.toString().padLeft(2, '0')}:${m.toString().padLeft(2, '0')}:$sms";
|
||||
}
|
||||
|
||||
static int parseDuration(String data) {
|
||||
List<int> split =
|
||||
data.split(':').reversed.map((e) => int.parse(e)).toList();
|
||||
int duration = 0;
|
||||
for (int i = 0; i < split.length; i++) {
|
||||
duration += split[i] * pow(60, i).toInt();
|
||||
}
|
||||
return duration;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user