Untitled
Anonymous
dart
10/15/2024 11:51 AM
796 B
19
Indexable
class Utilidades{
/// Comprueba fechas inválidas antes de parsear
/// Si no hay fecha a devolver y se ha introducido un datetime como parámetro, devuelve ese datetime
static DateTime? parseFecha(String? dateString, {DateTime? segundaOpcion}) {
if (dateString == null ||
dateString.isEmpty ||
dateString == '0000-00-00 00:00:00' ||
dateString == '0000-00-00') {
if (segundaOpcion != null) {
return segundaOpcion;
}
return null;
}
try {
return DateTime.parse(dateString);
} catch (e) {
rethrow;
}
}
}Editor is loading...
Leave a Comment