2023-03-06 00:04:59 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2023-02-26 19:52:45 +01:00
|
|
|
String formatTime(int seconds) {
|
|
|
|
Duration duration = Duration(seconds: seconds);
|
2023-03-03 16:38:08 +01:00
|
|
|
String formattedTime = '';
|
|
|
|
String twoDigits(int n) => n.toString().padLeft(2, "0");
|
|
|
|
String days = duration.inDays.toString();
|
|
|
|
String hours = twoDigits(duration.inHours.remainder(24));
|
|
|
|
String minutes = twoDigits(duration.inMinutes.remainder(60));
|
|
|
|
String formattedSeconds = twoDigits(duration.inSeconds.remainder(60));
|
|
|
|
if (duration.inDays != 0) formattedTime += '$days:';
|
|
|
|
if (duration.inHours != 0) formattedTime += '$hours:';
|
|
|
|
formattedTime += '$minutes:';
|
|
|
|
formattedTime += formattedSeconds;
|
|
|
|
return formattedTime;
|
2023-02-26 19:52:45 +01:00
|
|
|
}
|
2023-03-06 00:04:59 +01:00
|
|
|
|
|
|
|
extension TimeOfDayExtension on TimeOfDay {
|
|
|
|
TimeOfDay durationBetween(TimeOfDay time) {
|
|
|
|
int hourOffset = time.minute - minute < 0 ? 1 : 0;
|
|
|
|
return TimeOfDay(
|
|
|
|
hour: (time.hour - hour - hourOffset) % 24,
|
|
|
|
minute: (time.minute - minute) % 60);
|
|
|
|
}
|
|
|
|
}
|