Issue2695

classification
Title: Add support for automatic coercion for python datetime into Java LocalDateTime
Type: Severity: normal
Components: Versions:
Milestone:
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jamesmudd, stefan.richthofer
Priority: Keywords:

Created on 2018-06-27.19:23:48 by jamesmudd, last changed 2018-06-27.20:05:49 by jamesmudd.

Messages
msg12024 (view) Author: James Mudd (jamesmudd) Date: 2018-06-27.19:23:47
This was inspired by a question on Github here https://github.com/jythontools/jython/issues/105

The existing Jython datetime supports automatic coercion into java.util.Calendar, java.sql.Timestamp, java.sql.Date and java.sql.Time. See __tojava__ in Lib/datetime.py

Since Java 8 there are new Date and Time classes introduced see http://www.oracle.com/technetwork/articles/java/jf14-date-time-2125367.html

Since these new java.time classes are becoming the standard for handling dates and times in Java it would be nice if Jython supported automatic coercion into these types where appropriate.

Hopefully not to difficult maybe a nice new feature for 2.7.2?
msg12025 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2018-06-27.19:34:34
Do you see a way to implement this while keeping Java 7 compatibility?
Maybe we can move on and drop Java 7 support, but that would be a much bigger decision; it would have to be discussed on jython-dev and everything.

It just occurred to me that it would be nice if one could register custom coercers via some (Java-?)API. Such that a user could setup this for classes of his/her own framework while starting up Jython scripting for thier users. Jython would then automatically take such registered corcers into account. Not sure if this would be feasible to implement. Maybe something for Jython 3...
msg12028 (view) Author: James Mudd (jamesmudd) Date: 2018-06-27.20:05:48
Good point keeping Java 7 support. I hadn't considered it but I think it might be possible with this one. I'm thinking something like:
	try:
	  from java.time import LocalDate LocalTime LocalDataTime
	  java8_support = True
	except ImportError:
	  java8_support = False

Then in the __tojava__ use the flag to switch on? Do you think that would work? Then there is the issue of writing tests without using the newer classes in Java still need to think about it.

Being able to register custom converters sounds like a nice idea, something that could be looked at.

I would be in favour of dropping Java 7 support but that's a much bigger question.
History
Date User Action Args
2018-06-27 20:05:49jamesmuddsetmessages: + msg12028
2018-06-27 19:34:35stefan.richthofersetnosy: + stefan.richthofer
messages: + msg12025
2018-06-27 19:23:48jamesmuddcreate