readableFormatRefined property

String get readableFormatRefined

show Month in full text, show day and time, if date is today, tomorrow or yesterday, it returns the string respectively

Implementation

String get readableFormatRefined {
  var now = DateTime.now();
  var midNightToday = DateTime(now.year, now.month, now.day);
  var midNightYesterday = midNightToday.subtract(const Duration(days: 1));
  var midNightTomorrow = midNightToday.add(const Duration(days: 1));
  var afterTomorrow = midNightToday.add(const Duration(days: 2));
  var date = this;
  if (date.year != now.year) return date.readableFormat;
  if (date.isAfter(afterTomorrow)) return date.readableFormat;
  if (date.isAfter(midNightTomorrow)) return 'Tomorrow';
  if ((date.isBefore(midNightTomorrow) && (date.isAfter(midNightToday)))) {
    return 'Today';
  }
  if ((date.isAfter(midNightYesterday) && (date.isBefore(midNightToday)))) {
    return 'Yesterday';
  }
  return date.readableFormat;
}