提交 67f341e8 authored 作者: Stéphane Eintrazi's avatar Stéphane Eintrazi

Remove call to Calendar for truncate the date to 'WEEK'

上级 17ca1a1d
......@@ -445,14 +445,11 @@ public final class DateTimeFunctions {
case WEEK:
// Use Calendar to retrieve the first day of the week and convert
// the date to a dateValue
Date currentDate = DateTimeUtils.convertDateValueToDate(dateValue);
Calendar calendar = Calendar.getInstance();
calendar.setTime(currentDate);
calendar.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
ValueTimestamp valueTimestamp = ValueTimestamp.fromMillis(calendar.getTimeInMillis());
dateValue = valueTimestamp.getDateValue();
long absoluteDay = DateTimeUtils.absoluteDayFromDateValue(dateValue);
int dayOfWeek = DateTimeUtils.getDayOfWeekFromAbsolute(absoluteDay, 1);
if (dayOfWeek != 1) {
dateValue = DateTimeUtils.dateValueFromAbsoluteDay(absoluteDay - dayOfWeek + 1);
}
timeNanos = 0l;
break;
......
......@@ -728,7 +728,7 @@ public class DateTimeUtils {
return getDayOfWeekFromAbsolute(absoluteDayFromDateValue(dateValue), firstDayOfWeek);
}
private static int getDayOfWeekFromAbsolute(long absoluteValue, int firstDayOfWeek) {
public static int getDayOfWeekFromAbsolute(long absoluteValue, int firstDayOfWeek) {
return absoluteValue >= 0 ? (int) ((absoluteValue - firstDayOfWeek + 11) % 7) + 1
: (int) ((absoluteValue - firstDayOfWeek - 2) % 7) + 7;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论