Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.LocalTime;
import java.time.Period;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAccessor;
Expand Down Expand Up @@ -401,10 +402,108 @@ public static Integer extract(List<Object> args) {
return ((LocalDateTime) datetime).getNano() / 1000_000;
}
break;
case "MICROSECONDS":
if (datetime instanceof LocalTime) {
return ((LocalTime) datetime).getNano() / 1000;
}
if (datetime instanceof LocalDateTime) {
return ((LocalDateTime) datetime).getNano() / 1000;
}
break;
case "EPOCH":
if (datetime instanceof LocalDateTime) {
ZoneOffset offset = ZoneOffset.UTC;
return (int) ((LocalDateTime) datetime).toEpochSecond(offset);
}
if (datetime instanceof LocalDate) {
LocalDateTime ldt = LocalDateTime.of((LocalDate) datetime, LocalTime.MIDNIGHT);
ZoneOffset offset = ZoneOffset.UTC;
return (int) ldt.toEpochSecond(offset);
}
break;
case "QUARTER":
if (datetime instanceof LocalDate) {
int month = ((LocalDate) datetime).getMonthValue();
return (month - 1) / 3 + 1;
}
if (datetime instanceof LocalDateTime) {
int month = ((LocalDateTime) datetime).getMonthValue();
return (month - 1) / 3 + 1;
}
break;
case "WEEK":
if (datetime instanceof LocalDate) {
return datetime.get(WeekFields.ISO.weekOfYear());
}
if (datetime instanceof LocalDateTime) {
return datetime.get(WeekFields.ISO.weekOfYear());
}
break;
case "CENTURY":
if (datetime instanceof LocalDate) {
int year = ((LocalDate) datetime).getYear();
return (year > 0) ? (year - 1) / 100 + 1 : year / 100;
}
if (datetime instanceof LocalDateTime) {
int year = ((LocalDateTime) datetime).getYear();
return (year > 0) ? (year - 1) / 100 + 1 : year / 100;
}
break;
case "DECADE":
if (datetime instanceof LocalDate) {
return ((LocalDate) datetime).getYear() / 10;
}
if (datetime instanceof LocalDateTime) {
return ((LocalDateTime) datetime).getYear() / 10;
}
break;
case "DOW":
if (datetime instanceof LocalDate) {
return ((LocalDate) datetime).getDayOfWeek().getValue() % 7;
}
if (datetime instanceof LocalDateTime) {
return ((LocalDateTime) datetime).getDayOfWeek().getValue() % 7;
}
break;
case "ISODOW":
if (datetime instanceof LocalDate) {
return ((LocalDate) datetime).getDayOfWeek().getValue();
}
if (datetime instanceof LocalDateTime) {
return ((LocalDateTime) datetime).getDayOfWeek().getValue();
}
break;
case "DOY":
case "DAYOFYEAR":
if (datetime instanceof LocalDate) {
return ((LocalDate) datetime).getDayOfYear();
}
if (datetime instanceof LocalDateTime) {
return ((LocalDateTime) datetime).getDayOfYear();
}
break;
case "ISOYEAR":
if (datetime instanceof LocalDate) {
LocalDate date = (LocalDate) datetime;
return date.get(WeekFields.ISO.weekBasedYear());
}
if (datetime instanceof LocalDateTime) {
LocalDate date = ((LocalDateTime) datetime).toLocalDate();
return date.get(WeekFields.ISO.weekBasedYear());
}
break;
case "MILLENNIUM":
Copy link

Copilot AI May 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OffsetDateTime is not handled in the MILLENNIUM case. Add an instanceof OffsetDateTime branch similar to other units so timestamptz values can return the correct millennium.

Copilot uses AI. Check for mistakes.
if (datetime instanceof LocalDate) {
int year = ((LocalDate) datetime).getYear();
return (year > 0) ? (year - 1) / 1000 + 1 : year / 1000;
}
if (datetime instanceof LocalDateTime) {
int year = ((LocalDateTime) datetime).getYear();
return (year > 0) ? (year - 1) / 1000 + 1 : year / 1000;
}
break;
case "DAYOFWEEK":
return dayOfWeek(args);
case "DAYOFYEAR":
return dayOfYear(args);
default:
throw new TransformException(
CommonErrorCodeDeprecated.UNSUPPORTED_OPERATION,
Expand Down
Loading