@Test public void test_getInstance_String() { final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy"); final FastDateFormat format2 = FastDateFormat.getInstance("MM-DD-yyyy"); final FastDateFormat format3 = FastDateFormat.getInstance("MM-DD-yyyy"); assertTrue(format1 != format2); // -- junit 3.8 version -- assertFalse(format1 == format2); assertSame(format2, format3); assertEquals("MM/DD/yyyy", format1.getPattern()); assertEquals(TimeZone.getDefault(), format1.getTimeZone()); assertEquals(TimeZone.getDefault(), format2.getTimeZone()); }
@SystemDefaults(locale="en_US", timezone="America/New_York") @Test public void test_getInstance_String_TimeZone_Locale() { final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getTimeZone("Atlantic/Reykjavik"), Locale.GERMANY); final FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy", Locale.GERMANY); final FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault(), Locale.GERMANY); assertNotSame(format1, format2); assertEquals(TimeZone.getTimeZone("Atlantic/Reykjavik"), format1.getTimeZone()); assertEquals(TimeZone.getDefault(), format2.getTimeZone()); assertEquals(TimeZone.getDefault(), format3.getTimeZone()); assertEquals(Locale.GERMANY, format1.getLocale()); assertEquals(Locale.GERMANY, format2.getLocale()); assertEquals(Locale.GERMANY, format3.getLocale()); }
@Test public void testCheckDefaults() { final FastDateFormat format = FastDateFormat.getInstance(); final FastDateFormat medium = FastDateFormat.getDateTimeInstance(FastDateFormat.SHORT, FastDateFormat.SHORT); assertEquals(medium, format); final SimpleDateFormat sdf = new SimpleDateFormat(); assertEquals(sdf.toPattern(), format.getPattern()); assertEquals(Locale.getDefault(), format.getLocale()); assertEquals(TimeZone.getDefault(), format.getTimeZone()); }
@SystemDefaults(timezone="America/New_York", locale="en_US") @Test public void test_getInstance_String_TimeZone() { final FastDateFormat format1 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getTimeZone("Atlantic/Reykjavik")); final FastDateFormat format2 = FastDateFormat.getInstance("MM/DD/yyyy"); final FastDateFormat format3 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); final FastDateFormat format4 = FastDateFormat.getInstance("MM/DD/yyyy", TimeZone.getDefault()); final FastDateFormat format5 = FastDateFormat.getInstance("MM-DD-yyyy", TimeZone.getDefault()); final FastDateFormat format6 = FastDateFormat.getInstance("MM-DD-yyyy"); assertNotSame(format1, format2); assertEquals(TimeZone.getTimeZone("Atlantic/Reykjavik"), format1.getTimeZone()); assertEquals(TimeZone.getDefault(), format2.getTimeZone()); assertSame(format3, format4); assertNotSame(format3, format5); assertNotSame(format4, format6); }
private void verifyTimeZoneIDWithFormatter(Format formatter, String timeZoneId) { assertTrue(formatter instanceof FastDateFormat); assertEquals(((FastDateFormat)formatter).getTimeZone().getID(), timeZoneId); } }
protected synchronized void initRollingPeriod() { final String lcRollingPeriod = conf.get( YarnConfiguration.TIMELINE_SERVICE_ROLLING_PERIOD, YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ROLLING_PERIOD); this.rollingPeriod = RollingPeriod.valueOf(lcRollingPeriod .toUpperCase(Locale.ENGLISH)); fdf = FastDateFormat.getInstance(rollingPeriod.dateFormat(), TimeZone.getTimeZone("GMT")); sdf = new SimpleDateFormat(rollingPeriod.dateFormat()); sdf.setTimeZone(fdf.getTimeZone()); }