stevencaswell 2003/08/05 17:42:56 Modified: lang/src/test/org/apache/commons/lang/time DateUtilsTest.java Log: corrected the test of parseCVS with "h:mm z" format by replacing the current date/time with a series of calls using hard-coded time values Revision Changes Path 1.7 +38 -7 jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java Index: DateUtilsTest.java =================================================================== RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/DateUtilsTest.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- DateUtilsTest.java 4 Aug 2003 00:21:19 -0000 1.6 +++ DateUtilsTest.java 6 Aug 2003 00:42:56 -0000 1.7 @@ -413,14 +413,45 @@ assertEquals("parseCVS format MMM d, yyyy h:mm a", now, DateUtils.parseCVS(new SimpleDateFormat("MMM d, yyyy h:mm a").format(now.getTime())), 50); // h:mm z + /* + * This format is difficult to test using the current time because the + * parseCVS method applies the default date of January 1, 1970 to the + * parsed time. The most straightforward way to test the parse is to + * pass in a known value, and test the output against this know value. + */ now = Calendar.getInstance(); - now.set(Calendar.MILLISECOND, 0); - now.set(Calendar.SECOND, 0); - now.set(Calendar.DAY_OF_MONTH, 1); - now.set(Calendar.MONTH, Calendar.JANUARY); - now.set(Calendar.YEAR, 1970); - assertEquals("parseCVS format h:mm z", - now, DateUtils.parseCVS(new SimpleDateFormat("H:mm z").format(now.getTime())), 50); + now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT")); + assertEquals("parseCVS format h:mm z 16:30 GMT", + now, DateUtils.parseCVS("16:30 GMT"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 EST")); + assertEquals("parseCVS format h:mm z 16:30 EST", + now, DateUtils.parseCVS("16:30 EST"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT-05:00")); + assertEquals("parseCVS format h:mm z 16:30 GMT-05:00", + now, DateUtils.parseCVS("16:30 GMT-05:00"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("16:30 GMT+01:00")); + assertEquals("parseCVS format h:mm z 16:30 GMT+01:00", + now, DateUtils.parseCVS("16:30 GMT+01:00"), 50); + + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT")); + assertEquals("parseCVS format h:mm z 06:30 GMT", + now, DateUtils.parseCVS("06:30 GMT"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 EST")); + assertEquals("parseCVS format h:mm z 06:30 EST", + now, DateUtils.parseCVS("06:30 EST"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT-05:00")); + assertEquals("parseCVS format h:mm z 06:30 GMT-05:00", + now, DateUtils.parseCVS("06:30 GMT-05:00"), 50); + now = Calendar.getInstance(); + now.setTime(new SimpleDateFormat("h:mm z").parse("06:30 GMT+01:00")); + assertEquals("parseCVS format h:mm z 06:30 GMT+01:00", + now, DateUtils.parseCVS("06:30 GMT+01:00"), 50); now = Calendar.getInstance(); now.add(Calendar.WEEK_OF_MONTH, -1);
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]