LANG-1104 - FastDateParserTest.testParses fails in TimeZone America/Sao_Paulo

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@1670560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chas Honton 2015-04-01 04:07:43 +00:00
parent 56462a1e18
commit 06d724599d
2 changed files with 27 additions and 2 deletions

View File

@ -22,6 +22,7 @@
<body>
<release version="3.4" date="tba" description="tba">
<action issue="LANG-1104" type="fix" dev="chas">Parse test fails for TimeZone America/Sao_Paulo</action>
<action issue="LANG-1103" type="add" dev="britter">Add SystemUtils.IS_JAVA_1_9</action>
<action issue="LANG-1102" type="update" dev="britter">Make logic for comparing OS versions in SystemUtils smarter</action>
<action issue="LANG-1091" type="update" dev="britter" due-to="Fabian Lange">Shutdown thread pools in test cases</action>

View File

@ -42,8 +42,8 @@ import org.junit.Test;
* @since 3.2
*/
public class FastDateParserTest {
private static final String SHORT_FORMAT_NOERA = "y/M/d/h/a/m/s/E/Z";
private static final String LONG_FORMAT_NOERA = "yyyy/MMMM/dddd/hhhh/mmmm/ss/aaaa/EEEE/ZZZZ";
private static final String SHORT_FORMAT_NOERA = "y/M/d/h/a/m/s/E";
private static final String LONG_FORMAT_NOERA = "yyyy/MMMM/dddd/hhhh/mmmm/ss/aaaa/EEEE";
private static final String SHORT_FORMAT = "G/" + SHORT_FORMAT_NOERA;
private static final String LONG_FORMAT = "GGGG/" + LONG_FORMAT_NOERA;
@ -218,6 +218,7 @@ public class FastDateParserTest {
private void validateSdfFormatFdpParseEquality(final String format, final Locale locale, final TimeZone tz, final DateParser fdp, final Date in, final int year, final Date cs) throws ParseException {
final SimpleDateFormat sdf = new SimpleDateFormat(format, locale);
sdf.setTimeZone(tz);
if (format.equals(SHORT_FORMAT)) {
sdf.set2DigitYearStart( cs );
}
@ -254,6 +255,29 @@ public class FastDateParserTest {
}
}
// we cannot use historic dates to test timezone parsing, some timezones have second offsets
// as well as hours and minutes which makes the z formats a low fidelity round trip
@Test
public void testTzParses() throws Exception {
// Check that all Locales can parse the time formats we use
for(final Locale locale : Locale.getAvailableLocales()) {
final FastDateParser fdp= new FastDateParser("yyyy/MM/dd z", TimeZone.getDefault(), locale);
for(final TimeZone tz : new TimeZone[]{NEW_YORK, REYKJAVIK, GMT}) {
final Calendar cal= Calendar.getInstance(tz, locale);
cal.clear();
cal.set(Calendar.YEAR, 2000);
cal.set(Calendar.MONTH, 1);
cal.set(Calendar.DAY_OF_MONTH, 10);
final Date expected= cal.getTime();
final Date actual = fdp.parse("2000/02/10 "+tz.getDisplayName(locale));
Assert.assertEquals("tz:"+tz.getID()+" locale:"+locale.getDisplayName(), expected, actual);
}
}
}
@Test
public void testLocales_Long_AD() throws Exception {
testLocales(LONG_FORMAT, false);