change behavior of some methods of CalendarUtil
This commit is contained in:
parent
d776dbf137
commit
b45495b007
|
@ -1,7 +1,6 @@
|
|||
package org.cutem.cutecalendar.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
|
@ -186,13 +185,14 @@ public class CalendarUtil {
|
|||
* Returns a calendar where each field is designated by the corresponding string.
|
||||
*
|
||||
* @param calendarString the string that matches <em>"yyyy-mm-dd/hh:mm"</em>
|
||||
* @return a {@code Calendar} instance if date is valid; {@code null} otherwise
|
||||
* @return a {@code Calendar} instance
|
||||
* @throws IllegalArgumentException if the only argument is bad formatted
|
||||
* @see #isValidDateString(String)
|
||||
*/
|
||||
@Nullable
|
||||
@NotNull
|
||||
public static Calendar constructCalendar(@NotNull String calendarString) {
|
||||
if (!isValidCalendarString(calendarString)) {
|
||||
return null;
|
||||
throw new IllegalArgumentException("bad formation");
|
||||
}
|
||||
String[] cal = calendarString.split("/");
|
||||
return constructCalendar(cal[0], cal[1]);
|
||||
|
@ -203,14 +203,15 @@ public class CalendarUtil {
|
|||
*
|
||||
* @param date the string that matches <em>"yyyy-mm-dd"</em>
|
||||
* @param time the string that matched <em>"hh:mm"</em>
|
||||
* @return a {@code Calendar} instance if both arguments are valid; {@code null} otherwise
|
||||
* @return a {@code Calendar} instance
|
||||
* @throws IllegalArgumentException if one of arguments is bad formatted
|
||||
* @see #isValidDateString(String)
|
||||
* @see #isValidTimeString(String)
|
||||
*/
|
||||
@Nullable
|
||||
@NotNull
|
||||
public static Calendar constructCalendar(@NotNull String date, @NotNull String time) {
|
||||
if (!isValidDateString(date) || !isValidTimeString(time)) {
|
||||
return null;
|
||||
throw new IllegalArgumentException("bad formation");
|
||||
}
|
||||
String[] slices = date.split("-");
|
||||
int y = Integer.parseInt(slices[0]);
|
||||
|
|
|
@ -125,8 +125,13 @@ public class CalendarUtilTest {
|
|||
exp = new int[]{2018, 5, 2, 11, 30, 0, 0};
|
||||
assertArrayEquals(exp, res);
|
||||
|
||||
cal = CalendarUtil.constructCalendar(s3 + '/' + s2);
|
||||
assertNull(cal);
|
||||
boolean ok = false;
|
||||
try {
|
||||
CalendarUtil.constructCalendar(s3 + '/' + s2);
|
||||
} catch (IllegalArgumentException e) {
|
||||
ok = true;
|
||||
}
|
||||
assertTrue(ok);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue