fix issue IDFVKG

This commit is contained in:
shad0wm00n
2025-12-25 18:58:56 +08:00
parent de93fa7670
commit 611361a5bd
2 changed files with 21 additions and 4 deletions

View File

@@ -74,13 +74,17 @@ public class DateBetween implements Serializable {
Assert.notNull(begin, "Begin date is null !");
Assert.notNull(end, "End date is null !");
// defensive copy
Date b = new Date(begin.getTime());
Date e = new Date(end.getTime());
if (isAbs && begin.after(end)) {
// 间隔只为正数的情况下,如果开始日期晚于结束日期,置换之
this.begin = end;
this.end = begin;
this.begin = e;
this.end = b;
} else {
this.begin = begin;
this.end = end;
this.begin = b;
this.end = e;
}
}

View File

@@ -96,4 +96,17 @@ public class DateBetweenTest {
long result = DateUtil.betweenYear(sdate, edate, false);
assertEquals(0, result);
}
@Test
public void issueIDFVKGTest() {
Date b = new Date(1609459200000L); // 2021-01-01 00:00:00
Date e = new Date(1609545600000L); // 2021-01-02 00:00:00
DateBetween db = new DateBetween(b, e);
// 修改原始 date
b.setTime(0L); // 1970-01-01
// 期望 DateBetween 不受影响,间隔仍为 1 天
assertEquals(1, db.between(DateUnit.DAY));
}
}