mirror of
				https://github.com/immich-app/immich.git
				synced 2025-10-30 18:22:37 -04:00 
			
		
		
		
	Co-authored-by: Fynn Petersen-Frey <zoodyy@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
		
			
				
	
	
		
			38 lines
		
	
	
		
			801 B
		
	
	
	
		
			Dart
		
	
	
	
	
	
			
		
		
	
	
			38 lines
		
	
	
		
			801 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);
 | |
|   }
 | |
| }
 | |
| 
 | |
| 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;
 | |
|   }
 | |
| }
 |