Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for getZone on ReadableDateTime objects in Painless #31438

Closed
alexandreblin opened this issue Jun 19, 2018 · 3 comments
Closed

Add support for getZone on ReadableDateTime objects in Painless #31438

alexandreblin opened this issue Jun 19, 2018 · 3 comments
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >feature

Comments

@alexandreblin
Copy link

Describe the feature:
A little context : I am trying to compute the difference in months between two dates in a scripted field.

I want to use the ChronoUnit.MONTHS.between() methods, which takes Java 8 date objects as parameters. But when getting dates from my document, I get JodaTime ReadableDateTime objects.

So I'm using the following to convert between JodaTime date object and Java 8 date objects :

var date = doc['subscribed_at'].value
Instant.ofEpochMilli(date.getMillis()).atZone(ZoneId.of(date.getZone().getID()))

However, according to the Painless API reference, getZone() is not whilelisted, which prevents me from converting the time properly by taking the timezone into account.

So, would it be possible to whitelist the getZone() method?
Or maybe I am missing something and there is a simpler way to do what I'm trying to do?

@ywelsch ywelsch added the :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache label Jun 20, 2018
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra

@rjernst
Copy link
Member

rjernst commented Jun 20, 2018

The timezone of the date will always be UTC (+0), as that is what it is set to when constructing the ReadableDateTime object. Additionally, we are moving away from joda time altogether, and replacing with java time (this should be available to use in the scripting api in 6.4.0, see #31441). Since we are trying to remove joda time, I don't think we should add any more whitelisted methods, and thus I am going to close this issue.

@rjernst rjernst closed this as completed Jun 20, 2018
@alexandreblin
Copy link
Author

Thank you! Looking forward for the 6.4.0 release 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache >feature
Projects
None yet
Development

No branches or pull requests

4 participants