mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
force US locale for tests
This commit is contained in:
@@ -34,6 +34,8 @@ public abstract class DateUtils
|
||||
|
||||
private static TimeZone fixedTimeZone = null;
|
||||
|
||||
private static Locale fixedLocale = null;
|
||||
|
||||
/**
|
||||
* Time of the day when the new day starts.
|
||||
*/
|
||||
@@ -58,7 +60,7 @@ public abstract class DateUtils
|
||||
|
||||
public static String formatHeaderDate(GregorianCalendar day)
|
||||
{
|
||||
Locale locale = Locale.getDefault();
|
||||
Locale locale = getLocale();
|
||||
String dayOfMonth = Integer.toString(day.get(DAY_OF_MONTH));
|
||||
String dayOfWeek = day.getDisplayName(DAY_OF_WEEK, SHORT, locale);
|
||||
return dayOfWeek + "\n" + dayOfMonth;
|
||||
@@ -82,7 +84,7 @@ public abstract class DateUtils
|
||||
for (int i = 0; i < wdays.length; i++)
|
||||
{
|
||||
wdays[i] =
|
||||
day.getDisplayName(DAY_OF_WEEK, format, Locale.getDefault());
|
||||
day.getDisplayName(DAY_OF_WEEK, format, getLocale());
|
||||
day.add(DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
@@ -100,7 +102,7 @@ public abstract class DateUtils
|
||||
|
||||
/**
|
||||
* @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)
|
||||
{
|
||||
@@ -111,7 +113,7 @@ public abstract class DateUtils
|
||||
for (int i = 0; i < days.length; i++)
|
||||
{
|
||||
days[i] = calendar.getDisplayName(DAY_OF_WEEK, format,
|
||||
Locale.getDefault());
|
||||
getLocale());
|
||||
calendar.add(DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
@@ -195,6 +197,17 @@ public abstract class DateUtils
|
||||
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)
|
||||
{
|
||||
GregorianCalendar cal = DateUtils.getCalendar(timestamp);
|
||||
|
||||
@@ -31,6 +31,14 @@ import static org.hamcrest.MatcherAssert.*;
|
||||
|
||||
public class DateUtilsTest extends BaseUnitTest
|
||||
{
|
||||
@Before
|
||||
@Override
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
super.setUp();
|
||||
DateUtils.setFixedLocale(Locale.US);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFormatHeaderDate()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user