[opt](Nereids): use LocalDate to replace Calendar (#24361)
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user