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