39 lines
913 B
Dart
39 lines
913 B
Dart
class AttendanceResponseDto {
|
|
final String id;
|
|
final String employeeId;
|
|
final DateTime? login;
|
|
final DateTime? logout;
|
|
|
|
AttendanceResponseDto({
|
|
required this.id,
|
|
required this.employeeId,
|
|
this.login,
|
|
this.logout,
|
|
});
|
|
|
|
factory AttendanceResponseDto.fromJson(Map<String, dynamic> json) {
|
|
final data = json['data'];
|
|
|
|
return AttendanceResponseDto(
|
|
id: data['id']?.toString() ?? '',
|
|
employeeId: data['employeeId']?.toString() ?? '',
|
|
login: _parseDateTime(data['login']),
|
|
logout: _parseDateTime(data['logout']),
|
|
);
|
|
}
|
|
|
|
static DateTime? _parseDateTime(dynamic value) {
|
|
if (value == null) return null;
|
|
if (value is DateTime) return value;
|
|
if (value is String) {
|
|
try {
|
|
return DateTime.parse(value);
|
|
} catch (e) {
|
|
print('Error parsing date: $value - $e');
|
|
return null;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
}
|