getDateCategory method

String getDateCategory(
  1. MediaFile media, {
  2. Locale? locale,
})

Implementation

String getDateCategory(MediaFile media, {Locale? locale}) {
  Config config = GetInstance().isRegistered<PhoneGalleryController>()
      ? Get.find<PhoneGalleryController>().config
      : Config();
  DateTime? lastDate = media.lastModified;
  lastDate = lastDate ?? DateTime.now();
  initializeDateFormatting();
  String languageCode = locale != null
      ? (locale).languageCode
      : Platform.localeName.split('_')[0];
  if (daysBetween(lastDate) <= 3) {
    return config.recent;
  } else if (daysBetween(lastDate) > 3 && daysBetween(lastDate) <= 7) {
    return config.lastWeek;
  } else if (DateTime.now().month == lastDate.month) {
    return config.lastMonth;
  } else if (DateTime.now().year == lastDate.year) {
    String month = DateFormat.MMMM(languageCode).format(lastDate).toString();
    return "$month ${lastDate.day}";
  } else {
    String month = DateFormat.MMMM(languageCode).format(lastDate).toString();
    return "$month ${lastDate.day}, ${lastDate.year}";
  }
}