Add more date formatting tests

pull/996/head
Alex Baker 6 years ago
parent 3269d3588d
commit 5078cd2d15

@ -297,4 +297,144 @@ public class DateUtilitiesTest {
Locale.CHINESE, Locale.CHINESE,
FormatStyle.FULL))); FormatStyle.FULL)));
} }
@Test
public void frenchDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"dimanche 14 janvier 2018 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.FRENCH,
FormatStyle.FULL)));
}
@Test
public void indiaDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"रविवार, 14 जनवरी 2018 1:45 pm",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("hi-IN"),
FormatStyle.FULL)));
}
@Test
public void russiaDateTimeNoYear() {
freezeAt(new DateTime(2018, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"воскресенье, 14 января 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("ru"),
FormatStyle.FULL)));
}
@Test
public void russiaDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"воскресенье, 14 января 2018 г. 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("ru"),
FormatStyle.FULL)));
}
@Test
public void brazilDateTimeNoYear() {
freezeAt(new DateTime(2018, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"domingo, 14 de janeiro 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("pt-br"),
FormatStyle.FULL)));
}
@Test
public void brazilDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"domingo, 14 de janeiro de 2018 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("pt-br"),
FormatStyle.FULL)));
}
@Test
public void spainDateTimeNoYear() {
freezeAt(new DateTime(2018, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"domingo, 14 de enero 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("es"),
FormatStyle.FULL)));
}
@Test
public void spainDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"domingo, 14 de enero de 2018 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("es"),
FormatStyle.FULL)));
}
@Test
public void hebrewDateTimeNoYear() {
freezeAt(new DateTime(2018, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"יום ראשון, 14 בינואר 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("iw"),
FormatStyle.FULL)));
}
@Test
public void hebrewDateTimeWithYear() {
freezeAt(new DateTime(2017, 12, 12))
.thawAfter(
() ->
Assert.assertEquals(
"יום ראשון, 14 בינואר 2018 13:45",
DateUtilities.getRelativeDateTime(
getApplicationContext(),
new DateTime(2018, 1, 14, 13, 45, 1).getMillis(),
Locale.forLanguageTag("iw"),
FormatStyle.FULL)));
}
} }

@ -135,7 +135,7 @@ public class DateUtilities {
} }
private static String stripYear(String date, int year) { private static String stripYear(String date, int year) {
return date.replaceFirst("(,? )?" + year + "(年|년 )?", ""); return date.replaceAll("(?: de |, |/| )?" + year + "(?:年|년 | г\\.)?", "");
} }
private static @Nullable String getRelativeDay(Context context, long date, java.util.Locale locale, boolean abbreviated) { private static @Nullable String getRelativeDay(Context context, long date, java.util.Locale locale, boolean abbreviated) {

Loading…
Cancel
Save