mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
package cn.hutool.core.date;
|
package cn.hutool.core.date;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -72,6 +74,10 @@ public class Zodiac {
|
|||||||
* @return 星座名
|
* @return 星座名
|
||||||
*/
|
*/
|
||||||
public static String getZodiac(final int month, final int day) {
|
public static String getZodiac(final int month, final int day) {
|
||||||
|
Assert.checkBetween(month,
|
||||||
|
Month.JANUARY.getValue(),
|
||||||
|
Month.DECEMBER.getValue(),
|
||||||
|
"Unsupported month value, must be [0,12]");
|
||||||
// 在分隔日前为前一个星座,否则为后一个星座
|
// 在分隔日前为前一个星座,否则为后一个星座
|
||||||
return day < DAY_ARR[month] ? ZODIACS[month] : ZODIACS[month + 1];
|
return day < DAY_ARR[month] ? ZODIACS[month] : ZODIACS[month + 1];
|
||||||
}
|
}
|
||||||
|
@@ -31,4 +31,12 @@ public class ZodiacTest {
|
|||||||
Assertions.assertNull(Zodiac.getChineseZodiac(1899));
|
Assertions.assertNull(Zodiac.getChineseZodiac(1899));
|
||||||
Assertions.assertNull(Zodiac.getChineseZodiac((Calendar) null));
|
Assertions.assertNull(Zodiac.getChineseZodiac((Calendar) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getZodiacOutOfRangeTest() {
|
||||||
|
// https://github.com/dromara/hutool/issues/3036
|
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, ()->{
|
||||||
|
DateUtil.getZodiac(Month.UNDECIMBER.getValue(), 10);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user