formatTime static method

String formatTime(
  1. int seconds
)

Método para formatear el tiempo en años, meses, dias y horas.

Implementation

static String formatTime(int seconds) {
  int years = seconds ~/ (365 * 24 * 3600); // CALCULA LOS AÑOS
  int remainingSeconds = seconds % (365 * 24 * 3600);

  int months = remainingSeconds ~/ (30 * 24 * 3600); // CALCULA LOS MESES
  remainingSeconds %= (30 * 24 * 3600);

  int days = remainingSeconds ~/ (24 * 3600); // CALCULA LOS DIAS
  remainingSeconds %= (24 * 3600);

  int hours = remainingSeconds ~/ 3600; // CALCULA LAS HORAS

  // DEVUELVE EL TIEMPO FORMATEADO EN UNA CADENA
  if (years > 0) {
    return "${years}a ${months}m ${days}d";
  } else if (months > 0) {
    return "${months}m ${days}d";
  } else if (days > 0) {
    return "${days}d ${hours}h";
  } else {
    return hours == 1 ? "$hours hora" : "$hours horas";
  }
}