toJson method

  1. @override
String? toJson()
override

Serializes the date value to an ISO 8601 UTC string for JSON.

Converts the date to UTC timezone before serialization to ensure consistent representation across different timezones. Returns null if the date value is null.

Returns: An ISO 8601 formatted string in UTC (e.g., "2024-08-07T12:34:56.789Z"), or null if the date is null.

Example:

final field = JsonDate('createdAt');
field.value = DateTime(2024, 8, 7, 12, 34, 56);
print(field.toJson()); // "2024-08-07T12:34:56.000Z" (converted to UTC)

Implementation

@override
String? toJson() {
  return rawValue?.toUtc().toIso8601String();
}