This commit is contained in:
Looly 2023-12-23 23:39:10 +08:00
parent 1463172c2d
commit 3a1eb66f14
2 changed files with 19 additions and 20 deletions

View File

@ -18,11 +18,13 @@ import org.dromara.hutool.core.date.DateTime;
import org.dromara.hutool.core.date.DateUtil;
import org.dromara.hutool.core.date.TimeUtil;
import org.dromara.hutool.core.date.Zodiac;
import org.dromara.hutool.core.lang.Console;
import org.dromara.hutool.core.text.StrUtil;
import java.time.LocalDate;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
/**
@ -404,24 +406,20 @@ public class ChineseDate {
}
@Override
public int hashCode() {
return getChineseDay().hashCode() ^ getChineseMonth().hashCode()
^ Integer.valueOf(getChineseYear()).hashCode();
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
final ChineseDate that = (ChineseDate) o;
return year == that.year && month == that.month && day == that.day;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ChineseDate) {
ChineseDate other = (ChineseDate) obj;
return day == other.day
&& month == other.month
&& year == other.year
&& isLeapMonth == other.isLeapMonth;
}
return false;
public int hashCode() {
return Objects.hash(year, month, day);
}
// ------------------------------------------------------- private method start

View File

@ -17,6 +17,7 @@ import org.dromara.hutool.core.text.StrUtil;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.util.Date;
import java.util.Objects;
@ -178,13 +179,13 @@ public class ChineseDateTest {
@Test
public void equalsTest(){
// 二月初一
Date date1 = new Date(2023 - 1900, 1, 20);
final Date date1 = DateUtil.date(LocalDate.of(2023, 2, 20));
// 润二月初一
Date date2 = new Date(2023 - 1900, 2, 22);
final Date date2 = DateUtil.date(LocalDate.of(2023, 3, 22));
ChineseDate chineseDate1 = new ChineseDate(date1);
ChineseDate chineseDate2 = new ChineseDate(date2);
ChineseDate chineseDate3 = new ChineseDate(date2);
final ChineseDate chineseDate1 = new ChineseDate(date1);
final ChineseDate chineseDate2 = new ChineseDate(date2);
final ChineseDate chineseDate3 = new ChineseDate(date2);
Assertions.assertEquals("2023-02-01", chineseDate1.toStringNormal());
Assertions.assertEquals("2023-02-01", chineseDate2.toStringNormal());