mirror of
https://github.com/immich-app/immich.git
synced 2024-12-25 10:43:13 +02:00
9ac087c59c
* fix(mobile): do not crash on malformed asset duration * add unit test
21 lines
425 B
Dart
21 lines
425 B
Dart
extension DurationExtension on String {
|
|
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;
|
|
}
|
|
}
|
|
|
|
double toDouble() {
|
|
return double.parse(this);
|
|
}
|
|
|
|
int toInt() {
|
|
return int.parse(this);
|
|
}
|
|
}
|