formatDateWeekEnd function
Implementation
String formatDateWeekEnd({required String date}) {
if (date.contains(",")) {
String startDate = date.split(',')[0];
String endDate = date.split(',')[1];
DateTime startDateTime = DateTime.parse(startDate);
DateTime endDateTime = DateTime.parse(endDate);
if (startDateTime.month == endDateTime.month) {
// Format the dates with day number only
final startDay = DateFormat('d').format(startDateTime);
final endDay = DateFormat('d').format(endDateTime);
return "$startDay-$endDay ${DateFormat('MMM').format(startDateTime)}";
} else {
// Format dates with full month names if months differ
final startDay = DateFormat('d').format(startDateTime);
final endDay = DateFormat('d').format(endDateTime);
return "$startDay ${DateFormat('MMM').format(startDateTime)} - $endDay ${DateFormat('MMM').format(startDateTime)}";
}
} else {
return "${DateFormat('E, d MMM').format(DateTime.parse(date))}";
}
}