convertMonthsToYearsAndMonths function

Map<String, int> convertMonthsToYearsAndMonths(
  1. int months
)

Implementation

Map<String, int> convertMonthsToYearsAndMonths(int months) {
  if (months < 0) return {'years': 0, 'months': 0};

  final int years = months ~/ 12; // Years
  final int remainingMonths = (months % 12).round(); // Remaining months

  return {'years': years, 'months': remainingMonths};
}