add methods

This commit is contained in:
Looly 2021-03-18 22:22:19 +08:00
parent 8e8518c8d1
commit 81694dadfe
4 changed files with 72 additions and 1 deletions

View File

@ -13,6 +13,7 @@
* 【db 】 增加Ignite数据库驱动识别
* 【core 】 DateUtil.parse支持带毫秒的UTC时间
* 【core 】 IdcardUtil.Idcard增加toStringpr#1487@Github
* 【core 】 ChineseDate增加getGregorianXXX方法issue#1481@Github
### Bug修复
* 【core 】 修复IoUtil.readBytes的FileInputStream中isClose参数失效问题issue#I3B7UD@Gitee

View File

@ -7,6 +7,7 @@ import cn.hutool.core.date.chinese.LunarFestival;
import cn.hutool.core.date.chinese.LunarInfo;
import cn.hutool.core.util.StrUtil;
import java.util.Calendar;
import java.util.Date;
@ -151,6 +152,16 @@ public class ChineseDate {
return this.year;
}
/**
* 获取公历的年
*
* @return 公历年
* @since 5.6.1
*/
public int getGregorianYear(){
return this.gyear;
}
/**
* 获取农历的月从1开始计数
*
@ -161,6 +172,26 @@ public class ChineseDate {
return this.month;
}
/**
* 获取公历的月从1开始计数
*
* @return 公历月
* @since 5.6.1
*/
public int getGregorianMonthBase1(){
return this.gmonth;
}
/**
* 获取公历的月从0开始计数
*
* @return 公历月
* @since 5.6.1
*/
public int getGregorianMonth(){
return this.gmonth -1;
}
/**
* 当前农历月份是否为闰月
*
@ -200,6 +231,16 @@ public class ChineseDate {
return this.day;
}
/**
* 获取公历的日
*
* @return 公历日
* @since 5.6.1
*/
public int getGregorianDay(){
return this.gday;
}
/**
* 获得农历日
*
@ -223,6 +264,28 @@ public class ChineseDate {
}
}
/**
* 获取公历的Date
*
* @return 公历Date
* @since 5.6.1
*/
public Date getGregorianDate(){
return DateUtil.date(getGregorianCalendar());
}
/**
* 获取公历的Calendar
*
* @return 公历Calendar
* @since 5.6.1
*/
public Calendar getGregorianCalendar(){
final Calendar calendar = CalendarUtil.calendar();
//noinspection MagicConstant
calendar.set(this.gyear, getGregorianMonth(), this.gday, 0, 0, 0);
return calendar;
}
/**
* 获得节日
@ -347,4 +410,4 @@ public class ChineseDate {
// ------------------------------------------------------- private method end
}
}

View File

@ -9,6 +9,7 @@ public class ChineseDateTest {
@Test
public void chineseDateTest() {
ChineseDate date = new ChineseDate(DateUtil.parseDate("2020-01-25"));
Assert.assertEquals("2020-01-25 00:00:00", date.getGregorianDate().toString());
Assert.assertEquals(2020, date.getChineseYear());
Assert.assertEquals(1, date.getMonth());
@ -50,6 +51,7 @@ public class ChineseDateTest {
@Test
public void getChineseMonthTest(){
ChineseDate chineseDate = new ChineseDate(2020,6,15);
Assert.assertEquals("2020-08-04 00:00:00", chineseDate.getGregorianDate().toString());
Assert.assertEquals("六月", chineseDate.getChineseMonth());
chineseDate = new ChineseDate(2020,4,15);

View File

@ -54,6 +54,8 @@ public class DialectFactory {
public static final String DRIVER_KINGBASE8 = "com.kingbase8.Driver";
/** JDBC 驱动 Ignite thin */
public static final String DRIVER_IGNITE_THIN = "org.apache.ignite.IgniteJdbcThinDriver";
/** JDBC 驱动 ClickHouse */
public static final String DRIVER_CLICK_HOUSE = "ru.yandex.clickhouse.ClickHouseDriver";
private static final Map<DataSource, Dialect> DIALECT_POOL = new ConcurrentHashMap<>();
@ -143,6 +145,9 @@ public class DialectFactory {
} else if (nameContainsProductInfo.contains("ignite")) {
// Ignite thin
driver = DRIVER_IGNITE_THIN;
} else if (nameContainsProductInfo.contains("clickhouse")) {
// ClickHouse
driver = DRIVER_CLICK_HOUSE;
}
return driver;