34 lines
927 B
Dart
34 lines
927 B
Dart
import "../models/trip.dart";
|
|
|
|
class TripValidator {
|
|
static List<String> validate(Trip trip) {
|
|
final errors = <String>[];
|
|
|
|
// Validate time format
|
|
if (!RegExp(r"^\d{2}:\d{2}$").hasMatch(trip.scheduledTime)) {
|
|
errors.add("Invalid time format: ${trip.scheduledTime}");
|
|
}
|
|
|
|
// Validate trip number
|
|
if (trip.tripNumber.isEmpty) {
|
|
errors.add("Missing trip number");
|
|
}
|
|
|
|
// Validate duty/running numbers
|
|
if (trip.dutyNumber.isEmpty || trip.runningNumber.isEmpty) {
|
|
errors.add("Missing duty or running number");
|
|
}
|
|
|
|
// Validate actual departure time if provided
|
|
if (trip.actualDepartureTime != null &&
|
|
!RegExp(r"^\d{2}:\d{2}$").hasMatch(trip.actualDepartureTime!)) {
|
|
errors.add("Invalid actual departure time format: ${trip.actualDepartureTime}");
|
|
}
|
|
|
|
return errors;
|
|
}
|
|
|
|
static bool isValid(Trip trip) {
|
|
return validate(trip).isEmpty;
|
|
}
|
|
}
|