countYears function

String countYears(
  1. int difference
)

Converts the time difference to a number of years. This function truncates to the lowest year. returns ("1 year" OR "X years")

Implementation

String countYears(int difference) {
  int count = (difference / 31536000000).truncate();
  return count.toString() + (count > 1 ? ' years' : ' year');
}