getTimeAgoConvertedDateTimeF function

DateTimeF getTimeAgoConvertedDateTimeF(
  1. DateTime dateTime
)

Implementation

DateTimeF getTimeAgoConvertedDateTimeF(DateTime dateTime) {
  final Duration difference = DateTime.now().difference(dateTime);

  /// --for day
  int days = difference.inDays;

  /// --for year
  int years = 0;
  if (days >= 365) {
    years = (days / 365).floor();
    days = days - (years * 365);
  }

  /// --for month
  int months = 0;
  if (days >= 30) {
    months = (days / 30).floor();
    days = days - (months * 30);
  }

  /// --for week
  int weeks = 0;
  if (days >= 7) {
    weeks = (days / 7).floor();
    days = days - (weeks * 7);
  }

  //#// TIME //#//

  /// --for second
  int seconds = 0;
  if (difference.inDays > 0) {
    var dateTimeInTimeOnly = dateTime.add(Duration(days: difference.inDays));
    final Duration tempDuration = DateTime.now().difference(dateTimeInTimeOnly);
    seconds = tempDuration.inSeconds;
  } else {
    seconds = difference.inSeconds;
  }

  /// --for hour
  int hours = 0;
  if (seconds >= 3600) {
    hours = (seconds ~/ 3600);
    seconds = seconds - (hours * 3600);
  }

  /// --for hour
  int minutes = 0;
  if (seconds >= 60) {
    minutes = seconds ~/ 60;
    seconds = seconds - (minutes * 60);
  }

  return DateTimeF(years, months, weeks, days, hours, minutes, seconds);
}