43 lines
1.2 KiB
Dart
43 lines
1.2 KiB
Dart
class ControlHistoryModel {
|
|
final String action;
|
|
final String source;
|
|
final String timestamp;
|
|
final int rawTimestamp;
|
|
|
|
ControlHistoryModel({
|
|
required this.action,
|
|
required this.source,
|
|
required this.timestamp,
|
|
required this.rawTimestamp,
|
|
});
|
|
|
|
factory ControlHistoryModel.fromMap(Map<dynamic, dynamic> json) {
|
|
final int ts = json['timestamp'] is int ? json['timestamp'] : 0;
|
|
return ControlHistoryModel(
|
|
action: json['action'] ?? '',
|
|
source: json['source'] ?? '',
|
|
timestamp: _parseTimestamp(json['timestamp']),
|
|
rawTimestamp: ts,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'action': action,
|
|
'source': source,
|
|
'timestamp': timestamp,
|
|
'rawTimestamp': rawTimestamp,
|
|
};
|
|
}
|
|
}
|
|
|
|
String _parseTimestamp(dynamic value) {
|
|
if (value == null) return '';
|
|
if (value is int) {
|
|
final dt = DateTime.fromMillisecondsSinceEpoch(value * 1000);
|
|
return "${dt.year}-${dt.month.toString().padLeft(2, '0')}-${dt.day.toString().padLeft(2, '0')} "
|
|
"${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}:${dt.second.toString().padLeft(2, '0')}";
|
|
}
|
|
return value.toString();
|
|
}
|