diff --git a/src/test/org/apache/commons/lang/time/DateFormatUtilsTest.java b/src/test/org/apache/commons/lang/time/DateFormatUtilsTest.java index 3f8068364..3af300a96 100644 --- a/src/test/org/apache/commons/lang/time/DateFormatUtilsTest.java +++ b/src/test/org/apache/commons/lang/time/DateFormatUtilsTest.java @@ -18,6 +18,7 @@ package org.apache.commons.lang.time; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; import java.util.Calendar; +import java.util.Locale; import java.util.TimeZone; import junit.framework.Test; @@ -61,6 +62,40 @@ public class DateFormatUtilsTest extends TestCase { } //----------------------------------------------------------------------- + public void testFormat() { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + c.set(2005,0,1,12,0,0); + c.setTimeZone(TimeZone.getDefault()); + StringBuffer buffer = new StringBuffer (); + int year = c.get(Calendar.YEAR); + int month = c.get(Calendar.MONTH) + 1; + int day = c.get(Calendar.DAY_OF_MONTH); + int hour = c.get(Calendar.HOUR_OF_DAY); + buffer.append (year); + buffer.append(month); + buffer.append(day); + buffer.append(hour); + assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH")); + + assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH")); + + assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime(), "yyyyMdH", Locale.US)); + + assertEquals(buffer.toString(), DateFormatUtils.format(c.getTime().getTime(), "yyyyMdH", Locale.US)); + } + + public void testFormatUTC() { + Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + c.set(2005,0,1,12,0,0); + assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern())); + + assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern())); + + assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US)); + + assertEquals ("2005-01-01T12:00:00", DateFormatUtils.formatUTC(c.getTime().getTime(), DateFormatUtils.ISO_DATETIME_FORMAT.getPattern(), Locale.US)); + } + public void testDateTimeISO(){ TimeZone timeZone = TimeZone.getTimeZone("GMT-3"); Calendar cal = Calendar.getInstance(timeZone); diff --git a/src/test/org/apache/commons/lang/time/DateUtilsTest.java b/src/test/org/apache/commons/lang/time/DateUtilsTest.java index 7fd9c194d..b2203301f 100644 --- a/src/test/org/apache/commons/lang/time/DateUtilsTest.java +++ b/src/test/org/apache/commons/lang/time/DateUtilsTest.java @@ -303,6 +303,8 @@ public class DateUtilsTest extends TestCase { assertEquals("round semimonth-2 failed", dateParser.parse("November 16, 2001"), DateUtils.round(date2, DateUtils.SEMI_MONTH)); + + assertEquals("round date-1 failed", dateParser.parse("February 13, 2002"), DateUtils.round(date1, Calendar.DATE));