diff --git a/timesincetextview/src/androidTest/java/com/ddiehl/timesincetextview/TimeSinceTextViewAndroidTest.java b/timesincetextview/src/androidTest/java/com/ddiehl/timesincetextview/TimeSinceTextViewAndroidTest.java index 3ed4d2b..2d6d8f2 100644 --- a/timesincetextview/src/androidTest/java/com/ddiehl/timesincetextview/TimeSinceTextViewAndroidTest.java +++ b/timesincetextview/src/androidTest/java/com/ddiehl/timesincetextview/TimeSinceTextViewAndroidTest.java @@ -1,6 +1,7 @@ package com.ddiehl.timesincetextview; import android.content.Context; +import android.support.annotation.PluralsRes; import android.support.test.InstrumentationRegistry; import android.support.test.runner.AndroidJUnit4; @@ -17,29 +18,6 @@ @RunWith(AndroidJUnit4.class) public class TimeSinceTextViewAndroidTest { - private static final String TIMESPAN_NOW = "just now"; - private static final String TIMESPAN_YEARS = "%s years ago"; - private static final String TIMESPAN_MONTHS = "%s months ago"; - private static final String TIMESPAN_WEEKS = "%s weeks ago"; - private static final String TIMESPAN_DAYS = "%s days ago"; - private static final String TIMESPAN_HOURS = "%s hours ago"; - private static final String TIMESPAN_MINUTES = "%s minutes ago"; - private static final String TIMESPAN_SECONDS = "%s seconds ago"; - private static final String TIMESPAN_YEAR = "%s year ago"; - private static final String TIMESPAN_MONTH = "%s month ago"; - private static final String TIMESPAN_WEEK = "%s week ago"; - private static final String TIMESPAN_DAY = "%s day ago"; - private static final String TIMESPAN_HOUR = "%s hour ago"; - private static final String TIMESPAN_MINUTE = "%s minute ago"; - private static final String TIMESPAN_SECOND = "%s second ago"; - private static final String TIMESPAN_YEARS_ABBR = "%syr"; - private static final String TIMESPAN_MONTHS_ABBR = "%smo"; - private static final String TIMESPAN_WEEKS_ABBR = "%swk"; - private static final String TIMESPAN_DAYS_ABBR = "%sd"; - private static final String TIMESPAN_HOURS_ABBR = "%sh"; - private static final String TIMESPAN_MINUTES_ABBR = "%sm"; - private static final String TIMESPAN_SECONDS_ABBR = "%ss"; - private Context mContext; private final long mTime = new Date().getTime() / 1000; @@ -58,7 +36,7 @@ public void getFormattedDateString_now() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 10, mTime, false, mContext), - is(TIMESPAN_NOW)); + is(mContext.getString(R.string.timespan_now))); } @Test @@ -66,7 +44,7 @@ public void getFormattedDateString_11seconds() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 11, mTime, false, mContext), - is(TIMESPAN_SECONDS, String.valueOf(11))); + is(getQuantityString(R.plurals.timespan_seconds, 11))); } @Test @@ -74,7 +52,7 @@ public void getFormattedDateString_59seconds() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 59, mTime, false, mContext), - is(TIMESPAN_SECONDS, String.valueOf(59))); + is(getQuantityString(R.plurals.timespan_seconds, 59))); } @Test @@ -82,7 +60,7 @@ public void getFormattedDateString_1minute() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 60, mTime, false, mContext), - is(TIMESPAN_MINUTE, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_minutes, 1))); } @Test @@ -90,7 +68,7 @@ public void getFormattedDateString_59minutes() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_MINUTES, String.valueOf(59))); + is(getQuantityString(R.plurals.timespan_minutes, 59))); } @Test @@ -98,7 +76,7 @@ public void getFormattedDateString_1hour() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_HOUR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_hours, 1))); } @Test @@ -106,7 +84,7 @@ public void getFormattedDateString_23hours() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_HOURS, String.valueOf(23))); + is(getQuantityString(R.plurals.timespan_hours, 23))); } @Test @@ -114,7 +92,7 @@ public void getFormattedDateString_1day() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_DAY, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_days, 1))); } @Test @@ -122,7 +100,7 @@ public void getFormattedDateString_6days() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 7 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_DAYS, String.valueOf(6))); + is(getQuantityString(R.plurals.timespan_days, 6))); } @Test @@ -130,7 +108,7 @@ public void getFormattedDateString_1week() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 7 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_WEEK, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_weeks, 1))); } @Test @@ -138,7 +116,7 @@ public void getFormattedDateString_4weeks() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 30 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_WEEKS, String.valueOf(4))); + is(getQuantityString(R.plurals.timespan_weeks, 4))); } @Test @@ -146,7 +124,7 @@ public void getFormattedDateString_1month() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 30 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_MONTH, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_months, 1))); } @Test @@ -154,7 +132,7 @@ public void getFormattedDateString_12months() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 365 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_MONTHS, String.valueOf(12))); + is(getQuantityString(R.plurals.timespan_months, 12))); } @Test @@ -162,7 +140,7 @@ public void getFormattedDateString_1year() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 365 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_YEAR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_years, 1))); } @Test @@ -170,7 +148,7 @@ public void getFormattedDateString_30years() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 30 * 365 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_YEARS, String.valueOf(30))); + is(getQuantityString(R.plurals.timespan_years, 30))); } @Test @@ -178,31 +156,31 @@ public void getFormattedDateString_abbrev() { assertThat( TimeSinceTextView.getFormattedDateString( mTime - 59, mTime, true, mContext), - is(TIMESPAN_SECONDS_ABBR, String.valueOf(59))); + is(getQuantityString(R.plurals.timespan_seconds_abbr, 59))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 60, mTime, true, mContext), - is(TIMESPAN_MINUTES_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_minutes_abbr, 1))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_HOURS_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_hours_abbr, 1))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_DAYS_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_days_abbr, 1))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 7 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_WEEKS_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_weeks_abbr, 1))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 30 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_MONTHS_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_months_abbr, 1))); assertThat( TimeSinceTextView.getFormattedDateString( mTime - 1 * 365 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_YEARS_ABBR, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_years_abbr, 1))); } @Test @@ -211,7 +189,7 @@ public void setDate_long() { view.setDate(mTime - 1 * 24 * 60 * 60); // 1 day assertThat( view.getText().toString(), - is(TIMESPAN_DAY, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_days, 1))); } @Test @@ -220,11 +198,15 @@ public void setDate_java_util_date() { view.setDate(new Date((mTime - 1 * 24 * 60 * 60) * 1000)); // 1 day assertThat( view.getText().toString(), - is(TIMESPAN_DAY, String.valueOf(1))); + is(getQuantityString(R.plurals.timespan_days, 1))); } - private static Matcher is(String matcher, String... args) { + private static Matcher is(String matcher, Object... args) { return Is.is( String.format(matcher, args)); } + + private String getQuantityString(@PluralsRes int resId, int n) { + return mContext.getResources().getQuantityString(resId, n, n); + } } diff --git a/timesincetextview/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java b/timesincetextview/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java index 096cabd..780a025 100644 --- a/timesincetextview/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java +++ b/timesincetextview/src/main/java/com/ddiehl/timesincetextview/TimeSinceTextView.java @@ -8,36 +8,23 @@ public class TimeSinceTextView extends TextView { private static final int[] TIMESPAN_IDS = { - R.string.timespan_years, - R.string.timespan_months, - R.string.timespan_weeks, - R.string.timespan_days, - R.string.timespan_hours, - R.string.timespan_minutes, - R.string.timespan_seconds, - R.string.timespan_now - }; - - private static final int[] TIMESPAN_IDS_PLURAL = { - R.string.timespan_years_plural, - R.string.timespan_months_plural, - R.string.timespan_weeks_plural, - R.string.timespan_days_plural, - R.string.timespan_hours_plural, - R.string.timespan_minutes_plural, - R.string.timespan_seconds_plural, - R.string.timespan_now + R.plurals.timespan_years, + R.plurals.timespan_months, + R.plurals.timespan_weeks, + R.plurals.timespan_days, + R.plurals.timespan_hours, + R.plurals.timespan_minutes, + R.plurals.timespan_seconds }; private static final int[] TIMESPAN_IDS_ABBR = { - R.string.timespan_years_abbr, - R.string.timespan_months_abbr, - R.string.timespan_weeks_abbr, - R.string.timespan_days_abbr, - R.string.timespan_hours_abbr, - R.string.timespan_minutes_abbr, - R.string.timespan_seconds_abbr, - R.string.timespan_now + R.plurals.timespan_years_abbr, + R.plurals.timespan_months_abbr, + R.plurals.timespan_weeks_abbr, + R.plurals.timespan_days_abbr, + R.plurals.timespan_hours_abbr, + R.plurals.timespan_minutes_abbr, + R.plurals.timespan_seconds_abbr }; private static int NOW_THRESHOLD_SECONDS = 10; @@ -68,36 +55,32 @@ public static String getFormattedDateString(long utc, boolean abbreviated, Conte return getFormattedDateString(utc, currentTime, abbreviated, context); } - protected static String getFormattedDateString( + public static String getFormattedDateString( long start, long end, boolean abbreviated, Context context) { - long seconds = end - start; - long minutes = seconds / 60; - long hours = minutes / 60; - long days = hours / 24; - long weeks = days / 7; - long months = days / 30; - long years = days / 365; - - long[] units = new long[] { years, months, weeks, days, hours, minutes, seconds }; + int seconds = (int) (end - start); + int[] units = new int[] { + seconds / 31536000, // years + seconds / 2592000, // months + seconds / 604800, // weeks + seconds / 86400, // days + seconds / 3600, // hours + seconds / 60, // minutes + seconds }; String output = ""; - long unit = 0; + int unit = 0; for (int i = 0; i < units.length; i++) { unit = units[i]; if (unit > 0) { - if (abbreviated) { - output = context.getString(TIMESPAN_IDS_ABBR[i]); - } else if (unit == 1) { - output = context.getString(TIMESPAN_IDS[i]); - } else { - output = context.getString(TIMESPAN_IDS_PLURAL[i]); - } + output = context.getResources().getQuantityString( + abbreviated ? TIMESPAN_IDS_ABBR[i] : TIMESPAN_IDS[i], + unit, unit); break; } } if (unit == seconds && seconds <= NOW_THRESHOLD_SECONDS) { - output = context.getString(TIMESPAN_IDS[TIMESPAN_IDS.length - 1]); + output = context.getString(R.string.timespan_now); } return String.format(output, unit); diff --git a/timesincetextview/src/main/res/values-zh-rCN/strings.xml b/timesincetextview/src/main/res/values-zh-rCN/strings.xml index 7106380..55a7627 100644 --- a/timesincetextview/src/main/res/values-zh-rCN/strings.xml +++ b/timesincetextview/src/main/res/values-zh-rCN/strings.xml @@ -1,24 +1,45 @@ - %s年前 - %s个月前 - %s周前 - %s天前 - %s小时前 - %s分钟前 - %s秒前 - %s年前 - %s个月前 - %s周前 - %s天前 - %s小时前 - %s分钟前 - %s秒前 - %s年 - %s月 - %s周 - %s天 - %s小时 - %s分钟 - %s秒 刚刚 + + %d年前 + + + %d个月前 + + + %d周前 + + + %d天前 + + + %d小时前 + + + %d分钟前 + + + %d秒前 + + + %d年 + + + %d月 + + + %d周 + + + %d天 + + + %d小时 + + + %d分钟 + + + %d秒 + diff --git a/timesincetextview/src/main/res/values/strings.xml b/timesincetextview/src/main/res/values/strings.xml index d00af70..df496f2 100644 --- a/timesincetextview/src/main/res/values/strings.xml +++ b/timesincetextview/src/main/res/values/strings.xml @@ -1,24 +1,59 @@ - %s year ago - %s month ago - %s week ago - %s day ago - %s hour ago - %s minute ago - %s second ago - %s years ago - %s months ago - %s weeks ago - %s days ago - %s hours ago - %s minutes ago - %s seconds ago - %syr - %smo - %swk - %sd - %sh - %sm - %ss just now + + %d year ago + %d years ago + + + %d month ago + %d months ago + + + %d week ago + %d weeks ago + + + %d day ago + %d days ago + + + %d hour ago + %d hours ago + + + %d minute ago + %d minutes ago + + + %d second ago + %d seconds ago + + + %dyr + %dyr + + + %dmo + %dmo + + + %dwk + %dwk + + + %dd + %dd + + + %dh + %dh + + + %dm + %dm + + + %ds + %ds + diff --git a/timesincetextview/src/test/java/com/ddiehl/timesincetextview/TimeSinceTextViewTest.java b/timesincetextview/src/test/java/com/ddiehl/timesincetextview/TimeSinceTextViewTest.java deleted file mode 100644 index bb3acb8..0000000 --- a/timesincetextview/src/test/java/com/ddiehl/timesincetextview/TimeSinceTextViewTest.java +++ /dev/null @@ -1,256 +0,0 @@ -package com.ddiehl.timesincetextview; - -import android.content.Context; - -import org.hamcrest.Matcher; -import org.hamcrest.core.Is; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; - -import java.util.Date; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class TimeSinceTextViewTest { - private static final String TIMESPAN_NOW = "just now"; - private static final String TIMESPAN_YEARS = "%s years ago"; - private static final String TIMESPAN_MONTHS = "%s months ago"; - private static final String TIMESPAN_WEEKS = "%s weeks ago"; - private static final String TIMESPAN_DAYS = "%s days ago"; - private static final String TIMESPAN_HOURS = "%s hours ago"; - private static final String TIMESPAN_MINUTES = "%s minutes ago"; - private static final String TIMESPAN_SECONDS = "%s seconds ago"; - private static final String TIMESPAN_YEAR = "%s year ago"; - private static final String TIMESPAN_MONTH = "%s month ago"; - private static final String TIMESPAN_WEEK = "%s week ago"; - private static final String TIMESPAN_DAY = "%s day ago"; - private static final String TIMESPAN_HOUR = "%s hour ago"; - private static final String TIMESPAN_MINUTE = "%s minute ago"; - private static final String TIMESPAN_SECOND = "%s second ago"; - private static final String TIMESPAN_YEARS_ABBR = "%syr"; - private static final String TIMESPAN_MONTHS_ABBR = "%smo"; - private static final String TIMESPAN_WEEKS_ABBR = "%swk"; - private static final String TIMESPAN_DAYS_ABBR = "%sd"; - private static final String TIMESPAN_HOURS_ABBR = "%sh"; - private static final String TIMESPAN_MINUTES_ABBR = "%sm"; - private static final String TIMESPAN_SECONDS_ABBR = "%ss"; - - @Mock private Context mContext; - private final long mTime = new Date().getTime() / 1000; - - @Before - public void setUp() { - when(mContext.getString(R.string.timespan_now)) - .thenReturn(TIMESPAN_NOW); - when(mContext.getString(R.string.timespan_years)) - .thenReturn(TIMESPAN_YEAR); - when(mContext.getString(R.string.timespan_months)) - .thenReturn(TIMESPAN_MONTH); - when(mContext.getString(R.string.timespan_weeks)) - .thenReturn(TIMESPAN_WEEK); - when(mContext.getString(R.string.timespan_days)) - .thenReturn(TIMESPAN_DAY); - when(mContext.getString(R.string.timespan_hours)) - .thenReturn(TIMESPAN_HOUR); - when(mContext.getString(R.string.timespan_minutes)) - .thenReturn(TIMESPAN_MINUTE); - when(mContext.getString(R.string.timespan_seconds)) - .thenReturn(TIMESPAN_SECOND); - when(mContext.getString(R.string.timespan_years_plural)) - .thenReturn(TIMESPAN_YEARS); - when(mContext.getString(R.string.timespan_months_plural)) - .thenReturn(TIMESPAN_MONTHS); - when(mContext.getString(R.string.timespan_weeks_plural)) - .thenReturn(TIMESPAN_WEEKS); - when(mContext.getString(R.string.timespan_days_plural)) - .thenReturn(TIMESPAN_DAYS); - when(mContext.getString(R.string.timespan_hours_plural)) - .thenReturn(TIMESPAN_HOURS); - when(mContext.getString(R.string.timespan_minutes_plural)) - .thenReturn(TIMESPAN_MINUTES); - when(mContext.getString(R.string.timespan_seconds_plural)) - .thenReturn(TIMESPAN_SECONDS); - when(mContext.getString(R.string.timespan_years_abbr)) - .thenReturn(TIMESPAN_YEARS_ABBR); - when(mContext.getString(R.string.timespan_months_abbr)) - .thenReturn(TIMESPAN_MONTHS_ABBR); - when(mContext.getString(R.string.timespan_weeks_abbr)) - .thenReturn(TIMESPAN_WEEKS_ABBR); - when(mContext.getString(R.string.timespan_days_abbr)) - .thenReturn(TIMESPAN_DAYS_ABBR); - when(mContext.getString(R.string.timespan_hours_abbr)) - .thenReturn(TIMESPAN_HOURS_ABBR); - when(mContext.getString(R.string.timespan_minutes_abbr)) - .thenReturn(TIMESPAN_MINUTES_ABBR); - when(mContext.getString(R.string.timespan_seconds_abbr)) - .thenReturn(TIMESPAN_SECONDS_ABBR); - } - - @After - public void tearDown() { - - } - - @Test - public void getFormattedDateString_now() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 10, mTime, false, mContext), - is(TIMESPAN_NOW)); - } - - @Test - public void getFormattedDateString_10seconds() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 11, mTime, false, mContext), - is(TIMESPAN_SECONDS, String.valueOf(11))); - } - - @Test - public void getFormattedDateString_59seconds() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 59, mTime, false, mContext), - is(TIMESPAN_SECONDS, String.valueOf(59))); - } - - @Test - public void getFormattedDateString_1minute() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 60, mTime, false, mContext), - is(TIMESPAN_MINUTE, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_59minutes() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_MINUTES, String.valueOf(59))); - } - - @Test - public void getFormattedDateString_1hour() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_HOUR, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_23hours() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_HOURS, String.valueOf(23))); - } - - @Test - public void getFormattedDateString_1day() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_DAY, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_6days() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 7 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_DAYS, String.valueOf(6))); - } - - @Test - public void getFormattedDateString_1week() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 7 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_WEEK, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_4weeks() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 30 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_WEEKS, String.valueOf(4))); - } - - @Test - public void getFormattedDateString_1month() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 30 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_MONTH, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_12months() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 365 * 24 * 60 * 60 + 1, mTime, false, mContext), - is(TIMESPAN_MONTHS, String.valueOf(12))); - } - - @Test - public void getFormattedDateString_1year() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 365 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_YEAR, String.valueOf(1))); - } - - @Test - public void getFormattedDateString_30years() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 30 * 365 * 24 * 60 * 60, mTime, false, mContext), - is(TIMESPAN_YEARS, String.valueOf(30))); - } - - @Test - public void getFormattedDateString_abbrev() { - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 59, mTime, true, mContext), - is(TIMESPAN_SECONDS_ABBR, String.valueOf(59))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 60, mTime, true, mContext), - is(TIMESPAN_MINUTES_ABBR, String.valueOf(1))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_HOURS_ABBR, String.valueOf(1))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_DAYS_ABBR, String.valueOf(1))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 7 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_WEEKS_ABBR, String.valueOf(1))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 30 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_MONTHS_ABBR, String.valueOf(1))); - assertThat( - TimeSinceTextView.getFormattedDateString( - mTime - 1 * 365 * 24 * 60 * 60, mTime, true, mContext), - is(TIMESPAN_YEARS_ABBR, String.valueOf(1))); - } - - private static Matcher is(String matcher, String... args) { - return Is.is( - String.format(matcher, args)); - } -} \ No newline at end of file