2023-11-09 18:19:53 +02:00
|
|
|
extension StringExtension on String {
|
|
|
|
String capitalize() {
|
|
|
|
return split(" ")
|
|
|
|
.map(
|
|
|
|
(str) => str.isEmpty ? str : str[0].toUpperCase() + str.substring(1),
|
|
|
|
)
|
|
|
|
.join(" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension DurationExtension on String {
|
2024-01-05 07:20:55 +02:00
|
|
|
/// Parses and returns the string of format HH:MM:SS as a duration object else null
|
2023-11-09 18:19:53 +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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
double toDouble() {
|
|
|
|
return double.parse(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
int toInt() {
|
|
|
|
return int.parse(this);
|
|
|
|
}
|
|
|
|
}
|