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