Fix for zero-padding of years.
A commented out set of failing tests are added to the Unit Test and need to be addressed. Submitted by: Jerson Chua git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@137932 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f010588d53
commit
3aab5ae026
|
@ -61,7 +61,7 @@ import java.util.TimeZone;
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
* @author Nikolay Metchev
|
* @author Nikolay Metchev
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @version $Id: FastDateFormat.java,v 1.20 2004/07/05 22:37:40 scolebourne Exp $
|
* @version $Id: FastDateFormat.java,v 1.21 2004/09/12 05:03:26 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class FastDateFormat extends Format {
|
public class FastDateFormat extends Format {
|
||||||
// A lot of the speed in this class comes from caching, but some comes
|
// A lot of the speed in this class comes from caching, but some comes
|
||||||
|
@ -591,7 +591,7 @@ public class FastDateFormat extends Format {
|
||||||
break;
|
break;
|
||||||
case 'y': // year (number)
|
case 'y': // year (number)
|
||||||
if (tokenLen >= 4) {
|
if (tokenLen >= 4) {
|
||||||
rule = UnpaddedNumberField.INSTANCE_YEAR;
|
rule = selectNumberRule(Calendar.YEAR, tokenLen);
|
||||||
} else {
|
} else {
|
||||||
rule = TwoDigitYearField.INSTANCE;
|
rule = TwoDigitYearField.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ import junit.textui.TestRunner;
|
||||||
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
* @author <a href="mailto:ggregory@seagullsw.com">Gary Gregory</a>
|
||||||
* @author Fredrik Westermarck
|
* @author Fredrik Westermarck
|
||||||
* @since 2.0
|
* @since 2.0
|
||||||
* @version $Id: FastDateFormatTest.java,v 1.9 2004/07/05 22:37:40 scolebourne Exp $
|
* @version $Id: FastDateFormatTest.java,v 1.10 2004/09/12 05:03:26 bayard Exp $
|
||||||
*/
|
*/
|
||||||
public class FastDateFormatTest extends TestCase {
|
public class FastDateFormatTest extends TestCase {
|
||||||
|
|
||||||
|
@ -233,4 +233,37 @@ public class FastDateFormatTest extends TestCase {
|
||||||
assertEquals("2004-02-03", fdf.format(cal));
|
assertEquals("2004-02-03", fdf.format(cal));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that pre-1000AD years get padded with yyyy
|
||||||
|
*/
|
||||||
|
public void testLowYearPadding() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
FastDateFormat format = FastDateFormat.getInstance("yyyy/MM/DD");
|
||||||
|
|
||||||
|
cal.set(1,0,1);
|
||||||
|
assertEquals("0001/01/01", format.format(cal));
|
||||||
|
cal.set(10,0,1);
|
||||||
|
assertEquals("0010/01/01", format.format(cal));
|
||||||
|
cal.set(100,0,1);
|
||||||
|
assertEquals("0100/01/01", format.format(cal));
|
||||||
|
cal.set(999,0,1);
|
||||||
|
assertEquals("0999/01/01", format.format(cal));
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* testLowYearPadding showed that the date was buggy
|
||||||
|
* This test confirms it, getting 366 back as a date
|
||||||
|
// TODO: Fix this problem
|
||||||
|
public void testSimpleDate() {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
FastDateFormat format = FastDateFormat.getInstance("yyyy/MM/DD");
|
||||||
|
|
||||||
|
cal.set(2004,11,31);
|
||||||
|
assertEquals("2004/12/31", format.format(cal));
|
||||||
|
cal.set(999,11,31);
|
||||||
|
assertEquals("0999/12/31", format.format(cal));
|
||||||
|
cal.set(1,2,2);
|
||||||
|
assertEquals("0001/03/02", format.format(cal));
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue