formatFlexiDate function
String?
formatFlexiDate(
- dynamic input, {
- bool withYear = true,
- bool withMonth = true,
- bool withDay = true,
})
Implementation
String? formatFlexiDate(
input, {
bool withYear = true,
bool withMonth = true,
bool withDay = true,
}) {
final flexi =
input is FlexiDate ? input : FlexiDate.tryFrom(input?.toString());
if (flexi == null) {
return null;
}
String result = "";
final date = flexi.toDateTime();
if (flexi.month != null && withMonth != false) {
result += "${DateFormat.MMM().format(date)} ";
if (flexi.day != null && withDay != false) {
result += "${DateFormat.d().format(date)}";
}
}
result = result.trim();
if (flexi.month != null && withYear != false) {
if (flexi.month != null && flexi.day != null) result += ",";
if (result.isNotEmpty) result += " ";
result += "${DateFormat.y().format(date)}";
}
return result;
}