convertToAgo function

String convertToAgo(
  1. String dateTime
)

Implementation

String convertToAgo(String dateTime) {
  DateTime input =
  DateFormat('MMM dd, yyyy').parse(dateTime, false);
  Duration diff = DateTime.now().difference(input);

  /*if (diff.inDays >= 1) {
    return universalDateConverter("MMM dd, yyyy", "dd MMM,yyyy", dateTime);
  } else if (diff.inHours >= 1) {
    return '${diff.inHours},hour${diff.inHours == 1 ? '' : 's'},ago';
  } else if (diff.inMinutes >= 1) {
    return '${diff.inMinutes},minute${diff.inMinutes == 1 ? '' : 's'},ago';
  } else if (diff.inSeconds >= 1) {
    return '${diff.inSeconds},second${diff.inSeconds == 1 ? '' : 's'},ago';
  } else {
    return 'just now';
  }*/

  if (diff.inDays > 1) {
    return '${diff.inDays} days,ago';
  }
  else if(diff.inDays == 1){
    return 'Yesterday';
  }
  else {
    return 'Today';
  }
}