Merge branch 'LANG-1255'

This commit is contained in:
Benedikt Ritter 2016-10-02 12:28:09 +02:00
commit 33bb9fe25b
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
3 changed files with 41 additions and 0 deletions

View File

@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
<body>
<release version="3.5" date="tba" description="New features including Java 9 detection">
<action issue="LANG-1255" type="add" dev="britter" due-to="Kaiyuan Wang">Add DateUtils.toCalendar(Date, TimeZone)</action>
<action issue="LANG-1023" type="add" dev="britter" due-to="Marko Bekhta">Add WordUtils.wrap overload with customizable breakable character</action>
<action issue="LANG-787" type="add" dev="pschumacher" due-to="Gokul Nanthakumar C">Add method removeIgnoreCase(String, String) to StringUtils</action>
<action issue="LANG-1261" type="fix" dev="pschumacher" >ArrayUtils.contains returns false for instances of subtypes</action>

View File

@ -666,6 +666,20 @@ public static Calendar toCalendar(final Date date) {
return c;
}
//-----------------------------------------------------------------------
/**
* Converts a {@code Date} of a given {@code TimeZone} into a {@code Calendar}
* @param date the date to convert to a Calendar
* @param tz the time zone of the @{code date}
* @return the created Calendar
* @throws NullPointerException if {@code date} or {@code tz} is null
*/
public static Calendar toCalendar(final Date date, final TimeZone tz) {
final Calendar c = Calendar.getInstance(tz);
c.setTime(date);
return c;
}
//-----------------------------------------------------------------------
/**
* <p>Rounds a date, leaving the field specified as the most

View File

@ -694,6 +694,32 @@ public void testToCalendar() {
}
}
//-----------------------------------------------------------------------
@Test(expected=NullPointerException.class)
public void testToCalendarWithDateNull() {
DateUtils.toCalendar(null, zone);
}
//-----------------------------------------------------------------------
@Test(expected=NullPointerException.class)
public void testToCalendarWithTimeZoneNull() {
DateUtils.toCalendar(date1, null);
}
//-----------------------------------------------------------------------
@Test
public void testToCalendarWithDateAndTimeZoneNotNull() {
Calendar c = DateUtils.toCalendar(date2, defaultZone);
assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the Date back", date2, c.getTime());
assertEquals("Convert Date and TimeZone to a Calendar, but failed to get the TimeZone back", defaultZone, c.getTimeZone());
}
//-----------------------------------------------------------------------
@Test(expected=NullPointerException.class)
public void testToCalendarWithDateAndTimeZoneNull() {
DateUtils.toCalendar(null, null);
}
//-----------------------------------------------------------------------
/**
* Tests various values with the round method