getDateString static method

String getDateString(
  1. int microSeconds,
  2. String format
)

Converts a timestamp in microseconds to a formatted date string according to the specified format.

@param microSeconds The timestamp in microseconds. @param format The format of the date string to be returned. @return The formatted date string or an empty string if the date is not today, yesterday, or a valid date.

Implementation

static String getDateString(int microSeconds, String format) {
  // Convert the timestamp to a date string
  var date = convertTimeStampToDateString(microSeconds, format);

  // Check if the message date is today
  if (isToday(microSeconds)) {
    return getTranslated("today");
  }
  // Check if the message date is yesterday
  else if (isYesterday(microSeconds)) {
    return getTranslated("yesterday");
  }
  // Check if the message date is not a default value
  else if (!date.contains("1970")) {
    return date;
  }
  // Return an empty string if none of the conditions are met
  return "";
}