countMonths function

String countMonths(
  1. int difference
)

Converts the time difference to a number of months. This function rounds to the nearest month. returns ("1 month" OR "X months" OR "1 year")

Implementation

String countMonths(int difference) {
  int count = (difference / 2628003000).round();
  count = count > 0 ? count : 1;
  if (count > 12) {
    return '1 year';
  }
  return count.toString() + (count > 1 ? ' months' : ' month');
}