diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java index ff728a73ac..eca9170157 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/types/coercion/DateLikeType.java @@ -27,31 +27,33 @@ import org.apache.doris.nereids.types.DateTimeV2Type; import org.apache.doris.nereids.types.DateType; import org.apache.doris.nereids.types.DateV2Type; +import java.time.LocalDate; import java.time.temporal.ChronoUnit; -import java.util.Calendar; /** * date like type. */ public abstract class DateLikeType extends PrimitiveType { - private Calendar toCalendar(double d) { - //d = (year * 10000 + month * 100 + day) * 1000000L; + private LocalDate toLocalDate(double d) { + // d = (year * 10000 + month * 100 + day) * 1000000L; int date = (int) (d / 1000000); int day = date % 100; int month = (date / 100) % 100; int year = date / 10000; - Calendar calendar = Calendar.getInstance(); - calendar.set(Calendar.YEAR, year); - calendar.set(Calendar.MONTH, month); - calendar.set(Calendar.DAY_OF_MONTH, day); - return calendar; + return LocalDate.of(year, month, day); } @Override public double rangeLength(double high, double low) { - Calendar to = toCalendar(high); - Calendar from = toCalendar(low); - return ChronoUnit.DAYS.between(from.toInstant(), to.toInstant()); + if (high == low) { + return 0; + } + if (Double.isInfinite(high) || Double.isInfinite(low)) { + return high - low; + } + LocalDate to = toLocalDate(high); + LocalDate from = toLocalDate(low); + return ChronoUnit.DAYS.between(from, to); } /**