fromJson method

  1. @override
DateTime fromJson(
  1. dynamic json
)

Implementation

@override
DateTime fromJson(dynamic json) {
  if (json is int) {
    // Assume the integer is a Unix timestamp in seconds, convert to UTC DateTime
    return DateTime.fromMillisecondsSinceEpoch(json * 1000, isUtc: true);
  } else if (json is String) {
    // Assume the string is in ISO 8601 format
    return DateTime.parse(json).toUtc();
  }
  // Handle unexpected type
  throw FormatException(
      'Invalid date format: expected int (Unix timestamp) or String (ISO 8601), got ${json.runtimeType}');
}