@Test public void shouldShowUpToOneDay() throws Exception { given(resolver.get(eq(R.string.label_hours), anyString())).willAnswer(new StringAnswer(StringAnswer.HOURS)); assertThat(formatter.format((System.currentTimeMillis() - TimeUnit.DAYS.toMillis(1)) + 1)).isEqualTo("23h"); }
@Override public String format(Long millis) { long diff = System.currentTimeMillis() - millis; if (diff < TimeUnit.HOURS.toMillis(1)) { return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff))); } if (diff < TimeUnit.DAYS.toMillis(1)) { return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff))); } return format.format(new Date(millis)); }
TimeFormatter implements StringFormatter<Long> { @Override public String format(Long millis) { long diff = System.currentTimeMillis() - millis; if (diff < TimeUnit.HOURS.toMillis(1)) { return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff))); } if (diff < TimeUnit.DAYS.toMillis(1)) { return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff))); } return format.format(new Date(millis)); } }
TimeFormatter implements StringFormatter<Long> { @Override public String format(Long millis) { long diff = System.currentTimeMillis() - millis; if (diff < TimeUnit.HOURS.toMillis(1)) { return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff))); } if (diff < TimeUnit.DAYS.toMillis(1)) { return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff))); } return format.format(new Date(millis)); } @Inject  TimeFormatter(StringResolver resolver); private  TimeFormatter(StringResolver resolver, SimpleDateFormat format); }
TimeFormatter implements StringFormatter<Long> { @Override public String format(Long millis) { long diff = System.currentTimeMillis() - millis; if (diff < TimeUnit.HOURS.toMillis(1)) { return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff))); } if (diff < TimeUnit.DAYS.toMillis(1)) { return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff))); } return format.format(new Date(millis)); } @Inject  TimeFormatter(StringResolver resolver); private  TimeFormatter(StringResolver resolver, SimpleDateFormat format); @Override String format(Long millis); }
TimeFormatter implements StringFormatter<Long> { @Override public String format(Long millis) { long diff = System.currentTimeMillis() - millis; if (diff < TimeUnit.HOURS.toMillis(1)) { return resolver.get(R.string.label_minutes, Math.max(1, TimeUnit.MILLISECONDS.toMinutes(diff))); } if (diff < TimeUnit.DAYS.toMillis(1)) { return resolver.get(R.string.label_hours, Math.max(1, TimeUnit.MILLISECONDS.toHours(diff))); } return format.format(new Date(millis)); } @Inject  TimeFormatter(StringResolver resolver); private  TimeFormatter(StringResolver resolver, SimpleDateFormat format); @Override String format(Long millis);  }