@Test public void shouldFormatAsBreakdown_whenLargerThanMinute() { assertEquals("1 minute 1 second", ExpirationUtil.getExpirationDisplayValue(context, SECONDS_IN_MINUTE + 1)); }
public static String getExpirationDisplayValue(Context context, int expirationTime) { if (expirationTime <= 0) { return context.getString(R.string.expiration_off); } String displayValue = ""; int secondsRemaining = expirationTime; int weeks = secondsRemaining / SECONDS_IN_WEEK; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_weeks, weeks); secondsRemaining = secondsRemaining - weeks * SECONDS_IN_WEEK; int days = secondsRemaining / SECONDS_IN_DAY; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_days, days); secondsRemaining = secondsRemaining - days * SECONDS_IN_DAY; int hours = secondsRemaining / SECONDS_IN_HOUR; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_hours, hours); secondsRemaining = secondsRemaining - hours * SECONDS_IN_HOUR; int minutes = secondsRemaining / SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_minutes, minutes); secondsRemaining = secondsRemaining - minutes * SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_seconds, secondsRemaining); return displayValue; }
ExpirationUtil { public static String getExpirationDisplayValue(Context context, int expirationTime) { if (expirationTime <= 0) { return context.getString(R.string.expiration_off); } String displayValue = ""; int secondsRemaining = expirationTime; int weeks = secondsRemaining / SECONDS_IN_WEEK; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_weeks, weeks); secondsRemaining = secondsRemaining - weeks * SECONDS_IN_WEEK; int days = secondsRemaining / SECONDS_IN_DAY; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_days, days); secondsRemaining = secondsRemaining - days * SECONDS_IN_DAY; int hours = secondsRemaining / SECONDS_IN_HOUR; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_hours, hours); secondsRemaining = secondsRemaining - hours * SECONDS_IN_HOUR; int minutes = secondsRemaining / SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_minutes, minutes); secondsRemaining = secondsRemaining - minutes * SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_seconds, secondsRemaining); return displayValue; } }
ExpirationUtil { public static String getExpirationDisplayValue(Context context, int expirationTime) { if (expirationTime <= 0) { return context.getString(R.string.expiration_off); } String displayValue = ""; int secondsRemaining = expirationTime; int weeks = secondsRemaining / SECONDS_IN_WEEK; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_weeks, weeks); secondsRemaining = secondsRemaining - weeks * SECONDS_IN_WEEK; int days = secondsRemaining / SECONDS_IN_DAY; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_days, days); secondsRemaining = secondsRemaining - days * SECONDS_IN_DAY; int hours = secondsRemaining / SECONDS_IN_HOUR; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_hours, hours); secondsRemaining = secondsRemaining - hours * SECONDS_IN_HOUR; int minutes = secondsRemaining / SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_minutes, minutes); secondsRemaining = secondsRemaining - minutes * SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_seconds, secondsRemaining); return displayValue; }  }
ExpirationUtil { public static String getExpirationDisplayValue(Context context, int expirationTime) { if (expirationTime <= 0) { return context.getString(R.string.expiration_off); } String displayValue = ""; int secondsRemaining = expirationTime; int weeks = secondsRemaining / SECONDS_IN_WEEK; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_weeks, weeks); secondsRemaining = secondsRemaining - weeks * SECONDS_IN_WEEK; int days = secondsRemaining / SECONDS_IN_DAY; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_days, days); secondsRemaining = secondsRemaining - days * SECONDS_IN_DAY; int hours = secondsRemaining / SECONDS_IN_HOUR; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_hours, hours); secondsRemaining = secondsRemaining - hours * SECONDS_IN_HOUR; int minutes = secondsRemaining / SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_minutes, minutes); secondsRemaining = secondsRemaining - minutes * SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_seconds, secondsRemaining); return displayValue; }  static String getExpirationDisplayValue(Context context, int expirationTime); static String getExpirationAbbreviatedDisplayValue(Context context, int expirationTime); }
ExpirationUtil { public static String getExpirationDisplayValue(Context context, int expirationTime) { if (expirationTime <= 0) { return context.getString(R.string.expiration_off); } String displayValue = ""; int secondsRemaining = expirationTime; int weeks = secondsRemaining / SECONDS_IN_WEEK; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_weeks, weeks); secondsRemaining = secondsRemaining - weeks * SECONDS_IN_WEEK; int days = secondsRemaining / SECONDS_IN_DAY; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_days, days); secondsRemaining = secondsRemaining - days * SECONDS_IN_DAY; int hours = secondsRemaining / SECONDS_IN_HOUR; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_hours, hours); secondsRemaining = secondsRemaining - hours * SECONDS_IN_HOUR; int minutes = secondsRemaining / SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_minutes, minutes); secondsRemaining = secondsRemaining - minutes * SECONDS_IN_MINUTE; displayValue = getDisplayValue(context, displayValue, R.plurals.expiration_seconds, secondsRemaining); return displayValue; }  static String getExpirationDisplayValue(Context context, int expirationTime); static String getExpirationAbbreviatedDisplayValue(Context context, int expirationTime);  }