Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions docs/changelog/83099.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 83099
summary: Improve support for joda datetime to java datetime in Painless
area: Infra/Scripting
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,83 @@ public static Matcher matcher(Pattern receiver, int limitFactor, CharSequence in
/**
* Convert a {@link TemporalAccessor} into millis since epoch like {@link Instant#toEpochMilli()}.
*/
public static long toEpochMilli(TemporalAccessor v) {
return v.getLong(ChronoField.INSTANT_SECONDS) * 1_000 + v.get(ChronoField.NANO_OF_SECOND) / 1_000_000;
public static long toEpochMilli(TemporalAccessor receiver) {
return receiver.getLong(ChronoField.INSTANT_SECONDS) * 1_000 + receiver.get(ChronoField.NANO_OF_SECOND) / 1_000_000;
}

public static long getMillis(TemporalAccessor receiver) {
return toEpochMilli(receiver);
}

public static DayOfWeek getDayOfWeekEnum(ZonedDateTime receiver) {
return receiver.getDayOfWeek();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should have a separate file or section these Augmentations that's simply unsupported.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like a good idea. I would want to do that in as a follow up, though.

public static int getCenturyOfEra(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getCenturyOfEra] is no longer available; " + "use [get(ChronoField.YEAR_OF_ERA) / 100] instead"
);
}

public static int getEra(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getEra] is no longer available; use [get(ChronoField.ERA)] instead");
}

public static int getHourOfDay(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getHourOfDay] is no longer available; use [getHour()] instead");
}

public static int getMillisOfDay(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getMillisOfDay] is no longer available; use [get(ChronoField.MILLI_OF_DAY)] instead");
}

public static int getMillisOfSecond(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getMillisOfSecond] is no longer available; " + "use [get(ChronoField.MILLI_OF_SECOND)] instead"
);
}

public static int getMinuteOfDay(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getMinuteOfDay] is no longer available; " + "use [get(ChronoField.MINUTE_OF_DAY)] instead"
);
}

public static int getMinuteOfHour(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getMinuteOfHour] is no longer available; use [getMinute()] instead");
}

public static int getMonthOfYear(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getMonthOfYear] is no longer available; use [getMonthValue()] instead");
}

public static int getSecondOfDay(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getSecondOfDay] is no longer available; " + "use [get(ChronoField.SECOND_OF_DAY)] instead"
);
}

public static int getSecondOfMinute(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getSecondOfMinute] is no longer available; use [getSecond()] instead");
}

public static int getWeekOfWeekyear(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getWeekOfWeekyear] is no longer available; " + "use [get(IsoFields.WEEK_OF_WEEK_BASED_YEAR)] instead"
);
}

public static int getWeekyear(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getWeekyear] is no longer available; use [get(IsoFields.WEEK_BASED_YEAR)] instead");
}

public static int getYearOfCentury(ZonedDateTime receiver) {
throw new UnsupportedOperationException(
"[getYearOfCentury] is no longer available; " + "use [get(ChronoField.YEAR_OF_ERA) % 100] instead"
);
}

public static int getYearOfEra(ZonedDateTime receiver) {
throw new UnsupportedOperationException("[getYearOfEra] is no longer available; use [get(ChronoField.YEAR_OF_ERA)] instead");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class java.time.temporal.TemporalAccessor {
boolean isSupported(TemporalField)
def query(TemporalQuery)
ValueRange range(TemporalField)
# An easy method to convert temporalAccessors to millis since epoch similar to Instan#toEpochMilli.
# An easy method to convert temporalAccessors to millis since epoch similar to Instant#toEpochMilli.
long org.elasticsearch.painless.api.Augmentation toEpochMilli()
long org.elasticsearch.painless.api.Augmentation getMillis()
}

class java.time.temporal.TemporalAdjuster {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,20 @@ class java.time.ZonedDateTime {
int getDayOfMonth()
DayOfWeek getDayOfWeek()
DayOfWeek org.elasticsearch.painless.api.Augmentation getDayOfWeekEnum()
int org.elasticsearch.painless.api.Augmentation getCenturyOfEra()
int org.elasticsearch.painless.api.Augmentation getEra()
int org.elasticsearch.painless.api.Augmentation getHourOfDay()
int org.elasticsearch.painless.api.Augmentation getMillisOfDay()
int org.elasticsearch.painless.api.Augmentation getMillisOfSecond()
int org.elasticsearch.painless.api.Augmentation getMinuteOfDay()
int org.elasticsearch.painless.api.Augmentation getMinuteOfHour()
int org.elasticsearch.painless.api.Augmentation getMonthOfYear()
int org.elasticsearch.painless.api.Augmentation getSecondOfDay()
int org.elasticsearch.painless.api.Augmentation getSecondOfMinute()
int org.elasticsearch.painless.api.Augmentation getWeekOfWeekyear()
int org.elasticsearch.painless.api.Augmentation getWeekyear()
int org.elasticsearch.painless.api.Augmentation getYearOfCentury()
int org.elasticsearch.painless.api.Augmentation getYearOfEra()
int getDayOfYear()
int getHour()
LocalDate toLocalDate()
Expand Down
Loading