force US locale for tests

pull/334/merge
Luboš Luňák 8 years ago committed by Alinson Xavier
parent ba78e563cd
commit 46c61f9ea9

@ -34,6 +34,8 @@ public abstract class DateUtils
private static TimeZone fixedTimeZone = null; private static TimeZone fixedTimeZone = null;
private static Locale fixedLocale = null;
/** /**
* Time of the day when the new day starts. * Time of the day when the new day starts.
*/ */
@ -58,7 +60,7 @@ public abstract class DateUtils
public static String formatHeaderDate(GregorianCalendar day) public static String formatHeaderDate(GregorianCalendar day)
{ {
Locale locale = Locale.getDefault(); Locale locale = getLocale();
String dayOfMonth = Integer.toString(day.get(DAY_OF_MONTH)); String dayOfMonth = Integer.toString(day.get(DAY_OF_MONTH));
String dayOfWeek = day.getDisplayName(DAY_OF_WEEK, SHORT, locale); String dayOfWeek = day.getDisplayName(DAY_OF_WEEK, SHORT, locale);
return dayOfWeek + "\n" + dayOfMonth; return dayOfWeek + "\n" + dayOfMonth;
@ -82,7 +84,7 @@ public abstract class DateUtils
for (int i = 0; i < wdays.length; i++) for (int i = 0; i < wdays.length; i++)
{ {
wdays[i] = wdays[i] =
day.getDisplayName(DAY_OF_WEEK, format, Locale.getDefault()); day.getDisplayName(DAY_OF_WEEK, format, getLocale());
day.add(DAY_OF_MONTH, 1); day.add(DAY_OF_MONTH, 1);
} }
@ -100,7 +102,7 @@ public abstract class DateUtils
/** /**
* @return array with weekday names starting according to locale settings, * @return array with weekday names starting according to locale settings,
* e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Europe * e.g. [Mo,Di,Mi,Do,Fr,Sa,So] in Germany
*/ */
public static String[] getLocaleDayNames(int format) public static String[] getLocaleDayNames(int format)
{ {
@ -111,7 +113,7 @@ public abstract class DateUtils
for (int i = 0; i < days.length; i++) for (int i = 0; i < days.length; i++)
{ {
days[i] = calendar.getDisplayName(DAY_OF_WEEK, format, days[i] = calendar.getDisplayName(DAY_OF_WEEK, format,
Locale.getDefault()); getLocale());
calendar.add(DAY_OF_MONTH, 1); calendar.add(DAY_OF_MONTH, 1);
} }
@ -195,6 +197,17 @@ public abstract class DateUtils
fixedLocalTime = timestamp; fixedLocalTime = timestamp;
} }
public static void setFixedLocale(Locale locale)
{
fixedLocale = locale;
}
private static Locale getLocale()
{
if(fixedLocale != null) return fixedLocale;
return Locale.getDefault();
}
public static Long truncate(TruncateField field, long timestamp) public static Long truncate(TruncateField field, long timestamp)
{ {
GregorianCalendar cal = DateUtils.getCalendar(timestamp); GregorianCalendar cal = DateUtils.getCalendar(timestamp);

@ -31,6 +31,14 @@ import static org.hamcrest.MatcherAssert.*;
public class DateUtilsTest extends BaseUnitTest public class DateUtilsTest extends BaseUnitTest
{ {
@Before
@Override
public void setUp() throws Exception
{
super.setUp();
DateUtils.setFixedLocale(Locale.US);
}
@Test @Test
public void testFormatHeaderDate() public void testFormatHeaderDate()
{ {

Loading…
Cancel
Save