提交 5f196a7e authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass Value directly to DateTimeUtils.getIso*()

上级 07e507f3
......@@ -884,13 +884,13 @@ public class Function extends Expression implements FunctionCall {
Calendar.YEAR));
break;
case ISO_YEAR:
result = ValueInt.get(DateTimeUtils.getIsoYear(v0.getDate()));
result = ValueInt.get(DateTimeUtils.getIsoYear(v0));
break;
case ISO_WEEK:
result = ValueInt.get(DateTimeUtils.getIsoWeek(v0.getDate()));
result = ValueInt.get(DateTimeUtils.getIsoWeek(v0));
break;
case ISO_DAY_OF_WEEK:
result = ValueInt.get(DateTimeUtils.getIsoDayOfWeek(v0.getDate()));
result = ValueInt.get(DateTimeUtils.getIsoDayOfWeek(v0));
break;
case CURDATE:
case CURRENT_DATE: {
......
......@@ -552,10 +552,11 @@ public class DateTimeUtils {
* starts at Monday. See also http://en.wikipedia.org/wiki/ISO_8601
*
* @author Robert Rathsack
* @param date the date object which day of week should be calculated
* @param value the date object which day of week should be calculated
* @return the day of the week, Monday as 1 to Sunday as 7
*/
public static int getIsoDayOfWeek(java.util.Date date) {
public static int getIsoDayOfWeek(Value value) {
java.util.Date date = value.getDate();
Calendar cal = DateTimeUtils.createGregorianCalendar();
cal.setTimeInMillis(date.getTime());
int val = cal.get(Calendar.DAY_OF_WEEK) - 1;
......@@ -573,10 +574,11 @@ public class DateTimeUtils {
* the December 28th always belongs to the last week.
*
* @author Robert Rathsack
* @param date the date object which week of year should be calculated
* @param value the date object which week of year should be calculated
* @return the week of the year
*/
public static int getIsoWeek(java.util.Date date) {
public static int getIsoWeek(Value value) {
java.util.Date date = value.getDate();
Calendar c = DateTimeUtils.createGregorianCalendar();
c.setTimeInMillis(date.getTime());
c.setFirstDayOfWeek(Calendar.MONDAY);
......@@ -588,10 +590,11 @@ public class DateTimeUtils {
* Returns the year according to the ISO week definition.
*
* @author Robert Rathsack
* @param date the date object which year should be calculated
* @param value the date object which year should be calculated
* @return the year
*/
public static int getIsoYear(java.util.Date date) {
public static int getIsoYear(Value value) {
java.util.Date date = value.getDate();
Calendar cal = DateTimeUtils.createGregorianCalendar();
cal.setTimeInMillis(date.getTime());
cal.setFirstDayOfWeek(Calendar.MONDAY);
......
......@@ -5,22 +5,18 @@
*/
package org.h2.test.unit;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import static org.h2.util.DateTimeUtils.getIsoDayOfWeek;
import static org.h2.util.DateTimeUtils.getIsoWeek;
import static org.h2.util.DateTimeUtils.getIsoYear;
import static org.h2.value.ValueDate.parse;
import org.h2.test.TestBase;
import org.h2.util.DateTimeUtils;
/**
* Test cases for DateTimeIso8601Utils.
*/
public class TestDateIso8601 extends TestBase {
private final SimpleDateFormat dateFormatter =
new SimpleDateFormat("yyyy-MM-dd");
/**
* Run just this test.
*
......@@ -49,14 +45,6 @@ public class TestDateIso8601 extends TestBase {
testIsoYearJanuary1thSunday();
}
private Date parse(String s) throws ParseException {
return dateFormatter.parse(s);
}
private static int getIsoDayOfWeek(Date date) {
return DateTimeUtils.getIsoDayOfWeek(date);
}
/**
* Test if day of week is returned as Monday = 1 to Sunday = 7.
*/
......@@ -70,11 +58,6 @@ public class TestDateIso8601 extends TestBase {
assertEquals(7, getIsoDayOfWeek(parse("2008-10-05")));
}
private static int getIsoWeek(Date date) {
Timestamp ts = new Timestamp(date.getTime());
return DateTimeUtils.getIsoWeek(ts);
}
/**
* January 1st is a Monday therefore the week belongs to the next year.
*/
......@@ -154,11 +137,6 @@ public class TestDateIso8601 extends TestBase {
assertEquals(2, getIsoWeek(parse("2012-01-09")));
}
private static int getIsoYear(Date date) {
Timestamp ts = new Timestamp(date.getTime());
return DateTimeUtils.getIsoYear(ts);
}
/**
* January 1st is a Monday therefore year is equal to isoYear.
*/
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论