2023-02-04 22:42:42 +02:00
|
|
|
extension DurationExtension on String {
|
2023-03-06 17:27:01 +02:00
|
|
|
Duration? toDuration() {
|
|
|
|
try {
|
|
|
|
final parts = split(':')
|
|
|
|
.map((e) => double.parse(e).toInt())
|
|
|
|
.toList(growable: false);
|
|
|
|
return Duration(hours: parts[0], minutes: parts[1], seconds: parts[2]);
|
|
|
|
} catch (e) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-04 22:42:42 +02:00
|
|
|
}
|
|
|
|
|
2023-03-04 00:38:30 +02:00
|
|
|
double toDouble() {
|
|
|
|
return double.parse(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
int toInt() {
|
|
|
|
return int.parse(this);
|
2023-02-04 22:42:42 +02:00
|
|
|
}
|
|
|
|
}
|
2023-04-15 03:50:58 +02:00
|
|
|
|
|
|
|
extension ListExtension<E> on List<E> {
|
|
|
|
List<E> uniqueConsecutive<T>([T Function(E element)? key]) {
|
|
|
|
key ??= (E e) => e as T;
|
|
|
|
int i = 1, j = 1;
|
|
|
|
for (; i < length; i++) {
|
|
|
|
if (key(this[i]) != key(this[i - 1])) {
|
|
|
|
if (i != j) {
|
|
|
|
this[j] = this[i];
|
|
|
|
}
|
|
|
|
j++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
length = length == 0 ? 0 : j;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|