This commit is contained in:
Looly
2020-01-29 10:58:45 +08:00
parent 1c13d73010
commit 63a8c5766d
10 changed files with 129 additions and 49 deletions

View File

@@ -268,6 +268,10 @@ public class DateTime extends Date {
* @return 如果此对象为可变对象,返回自身,否则返回新对象
*/
public DateTime offset(DateField datePart, int offset) {
if(DateField.ERA == datePart){
throw new IllegalArgumentException("ERA is not support offset!");
}
final Calendar cal = toCalendar();
//noinspection MagicConstant
cal.add(datePart.getValue(), offset);

View File

@@ -645,6 +645,7 @@ public class DateUtilTest {
DateTime startDate = DateUtil.parse("2019-12-01 17:02:30");
DateTime endDate = DateUtil.parse("2019-12-02 17:02:30");
int length = 3;
//noinspection deprecation
boolean expired = DateUtil.isExpired(startDate, DateField.DAY_OF_YEAR, length, endDate);
Assert.assertTrue(expired);
}