formatDateTime method

String formatDateTime(
  1. DateTime date,
  2. bool diffToNow, {
  3. String? format,
})

Method to build a String representing a DateTime

Implementation

String formatDateTime(DateTime date, bool diffToNow, {String? format}) {
  if (!diffToNow) {
    format ??= Strings.get("_date_time_format_", fallbackValue: null);
  }
  if (format != null) {
    return DateFormat(format).format(date.toLocal());
  }

  if (formatDate(date.toLocal(), true) == formatDate(DateTime.now(), true)) {
    return formatTime(date.toLocal(), true);
  } else {
    return formatDate(date.toLocal(), true);
  }

  // var formattedDate = formatDate(date.toLocal(), diffToNow);
  // var formattedTime = formatTime(date.toLocal(), false);
  // if (formattedDate.isEmpty ||
  //     formattedDate == Strings.getCapitalized("today")) {
  //   return formattedTime;
  // } else if (formattedTime.isEmpty) {
  //   return formattedDate;
  // } else {
  //   return "$formattedDate, $formattedTime";
  // }
}