提交 952aaf18 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass Value directly to DateTimeUtils.getDatePart()

上级 5f196a7e
......@@ -837,28 +837,22 @@ public class Function extends Expression implements FunctionCall {
break;
}
case DAY_OF_MONTH:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.DAY_OF_MONTH));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.DAY_OF_MONTH));
break;
case DAY_OF_WEEK:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.DAY_OF_WEEK));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.DAY_OF_WEEK));
break;
case DAY_OF_YEAR:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.DAY_OF_YEAR));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.DAY_OF_YEAR));
break;
case HOUR:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getTimestamp(),
Calendar.HOUR_OF_DAY));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.HOUR_OF_DAY));
break;
case MINUTE:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getTimestamp(),
Calendar.MINUTE));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.MINUTE));
break;
case MONTH:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.MONTH));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.MONTH));
break;
case MONTH_NAME: {
SimpleDateFormat monthName = new SimpleDateFormat("MMMM",
......@@ -868,20 +862,16 @@ public class Function extends Expression implements FunctionCall {
break;
}
case QUARTER:
result = ValueInt.get((DateTimeUtils.getDatePart(v0.getDate(),
Calendar.MONTH) - 1) / 3 + 1);
result = ValueInt.get((DateTimeUtils.getDatePart(v0, Calendar.MONTH) - 1) / 3 + 1);
break;
case SECOND:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getTimestamp(),
Calendar.SECOND));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.SECOND));
break;
case WEEK:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.WEEK_OF_YEAR));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.WEEK_OF_YEAR));
break;
case YEAR:
result = ValueInt.get(DateTimeUtils.getDatePart(v0.getDate(),
Calendar.YEAR));
result = ValueInt.get(DateTimeUtils.getDatePart(v0, Calendar.YEAR));
break;
case ISO_YEAR:
result = ValueInt.get(DateTimeUtils.getIsoYear(v0));
......@@ -1523,8 +1513,7 @@ public class Function extends Expression implements FunctionCall {
break;
case EXTRACT: {
int field = getDatePart(v0.getString());
result = ValueInt.get(DateTimeUtils.getDatePart(
v1.getTimestamp(), field));
result = ValueInt.get(DateTimeUtils.getDatePart(v1, field));
break;
}
case FORMATDATETIME: {
......
......@@ -494,11 +494,12 @@ public class DateTimeUtils {
* Get the specified field of a date, however with years normalized to
* positive or negative, and month starting with 1.
*
* @param d the date
* @param date the date value
* @param field the field type
* @return the value
*/
public static int getDatePart(java.util.Date d, int field) {
public static int getDatePart(Value date, int field) {
java.util.Date d = date.getTimestamp();
Calendar c = getCalendar();
c.setTime(d);
if (field == Calendar.YEAR) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论