format method
Formats the date value according to the specified format string.
Returns an empty string if the date value is null. Otherwise, uses the
DateTime extension method to format the date according to the provided
format pattern.
Parameters:
dateFormat: The format pattern to use (defaults to DateTimeFormatsVN.dateOnly). See DateTimeFormatsVN for available format constants.
Returns:
A formatted date string, or an empty string if the date is null.
Example:
final field = JsonDate('createdAt');
field.value = DateTime(2024, 8, 7);
print(field.format()); // "07/08/2024" (using default format)
print(field.format(dateFormat: 'yyyy-MM-dd')); // "2024-08-07"
Implementation
String format({
String dateFormat = DateTimeFormatsVN.dateOnly,
}) {
if (rawValue == null) {
return "";
}
return value.format(dateFormat: dateFormat);
}