mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix chinese date bug
This commit is contained in:
parent
3c8236af95
commit
1b8e921ab2
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
# 5.4.2 (2020-09-08)
|
# 5.4.2 (2020-09-09)
|
||||||
|
|
||||||
### 新特性
|
### 新特性
|
||||||
* 【core 】 lock放在try外边(pr#1050@Github)
|
* 【core 】 lock放在try外边(pr#1050@Github)
|
||||||
@ -28,6 +28,7 @@
|
|||||||
* 【http 】 修复GET请求附带body导致变POST的问题
|
* 【http 】 修复GET请求附带body导致变POST的问题
|
||||||
* 【core 】 修复double相等判断问题(pr#175@Gitee)
|
* 【core 】 修复double相等判断问题(pr#175@Gitee)
|
||||||
* 【core 】 修复DateSizeUtil.format越界问题(issue#1069@Github)
|
* 【core 】 修复DateSizeUtil.format越界问题(issue#1069@Github)
|
||||||
|
* 【core 】 修复ChineseDate.getChineseMonth问题(issue#I1UG72@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -161,6 +161,16 @@ public class ChineseDate {
|
|||||||
return this.month;
|
return this.month;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前农历月份是否为闰月
|
||||||
|
*
|
||||||
|
* @return 是否为闰月
|
||||||
|
* @since 5.4.2
|
||||||
|
*/
|
||||||
|
public boolean isLeapMonth(){
|
||||||
|
return ChineseMonth.isLeapMonth(this.year, this.month);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得农历月份(中文,例如二月,十二月,或者润一月)
|
* 获得农历月份(中文,例如二月,十二月,或者润一月)
|
||||||
@ -168,7 +178,7 @@ public class ChineseDate {
|
|||||||
* @return 返回农历月份
|
* @return 返回农历月份
|
||||||
*/
|
*/
|
||||||
public String getChineseMonth() {
|
public String getChineseMonth() {
|
||||||
return ChineseMonth.getChineseMonthName(this.leap, this.month, false);
|
return ChineseMonth.getChineseMonthName(isLeapMonth(), this.month, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -177,7 +187,7 @@ public class ChineseDate {
|
|||||||
* @return 返回农历月份称呼
|
* @return 返回农历月份称呼
|
||||||
*/
|
*/
|
||||||
public String getChineseMonthName() {
|
public String getChineseMonthName() {
|
||||||
return ChineseMonth.getChineseMonthName(this.leap, this.month, true);
|
return ChineseMonth.getChineseMonthName(isLeapMonth(), this.month, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,17 +11,27 @@ public class ChineseMonth {
|
|||||||
private static final String[] MONTH_NAME = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
|
private static final String[] MONTH_NAME = {"一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二"};
|
||||||
private static final String[] MONTH_NAME_TRADITIONAL = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"};
|
private static final String[] MONTH_NAME_TRADITIONAL = {"正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "腊"};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前农历月份是否为闰月
|
||||||
|
*
|
||||||
|
* @return 是否为闰月
|
||||||
|
* @since 5.4.2
|
||||||
|
*/
|
||||||
|
public static boolean isLeapMonth(int year, int month){
|
||||||
|
return month == LunarInfo.leapMonth(year);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得农历月称呼<br>
|
* 获得农历月称呼<br>
|
||||||
* 当为传统表示时,表示为二月,腊月,或者润正月等
|
* 当为传统表示时,表示为二月,腊月,或者润正月等
|
||||||
* 当为非传统表示时,二月,十二月,或者润一月等
|
* 当为非传统表示时,二月,十二月,或者润一月等
|
||||||
*
|
*
|
||||||
* @param isLeep 是否闰月
|
* @param isLeapMonth 是否闰月
|
||||||
* @param month 月份,从1开始
|
* @param month 月份,从1开始
|
||||||
* @param isTraditional 是否传统表示,例如一月传统表示为正月
|
* @param isTraditional 是否传统表示,例如一月传统表示为正月
|
||||||
* @return 返回农历月份称呼
|
* @return 返回农历月份称呼
|
||||||
*/
|
*/
|
||||||
public static String getChineseMonthName(boolean isLeep, int month, boolean isTraditional) {
|
public static String getChineseMonthName(boolean isLeapMonth, int month, boolean isTraditional) {
|
||||||
return (isLeep ? "闰" : "") + (isTraditional ? MONTH_NAME_TRADITIONAL : MONTH_NAME)[month - 1] + "月";
|
return (isLeapMonth ? "闰" : "") + (isTraditional ? MONTH_NAME_TRADITIONAL : MONTH_NAME)[month - 1] + "月";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,4 +68,13 @@ public class ChineseDateTest {
|
|||||||
String cyclicalYMD = chineseDate.getCyclicalYMD();
|
String cyclicalYMD = chineseDate.getCyclicalYMD();
|
||||||
Assert.assertEquals("庚子年甲申月癸卯日",cyclicalYMD);
|
Assert.assertEquals("庚子年甲申月癸卯日",cyclicalYMD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getChineseMonthTest(){
|
||||||
|
ChineseDate chineseDate = new ChineseDate(2020,6,15);
|
||||||
|
Assert.assertEquals("六月", chineseDate.getChineseMonth());
|
||||||
|
|
||||||
|
chineseDate = new ChineseDate(2020,4,15);
|
||||||
|
Assert.assertEquals("闰四月", chineseDate.getChineseMonth());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user