# Error during conversion from ZonedDateTime to Joda DateTime

**URL:** <https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586>\
**Category:** Scripts & Rules\
**Tags:** jsr223, jython\
**Created:** [July 24, 2019, 8:48am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586 "2019-07-24T08:48:13Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhumbertgz](https://community.openhab.org/user_avatar/community.openhab.org/rhumbertgz/32/39965_2.png) [@rhumbertgz](https://community.openhab.org/u/rhumbertgz)\
**Post date:** [July 24, 2019, 8:48am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/1 "2019-07-24T08:48:14Z")

</div>

Hi guys!

I’m doing some Jython automations and I’m trying to do a conversion from _ZonedDateTime_ to DateTime (Joda), but I get this error:

```
File "/opt/openhab2/conf/automation/lib/python/core/date.py", line 217, in to_joda_datetime
    return DateTime(
IllegalArgumentException: java.lang.IllegalArgumentException: No instant converter found for type: java.time.Instant

```

It’s a little weird because of the conversion in the other way around works.

In summary

```
from core.date import toJodaDT
from org.joda.time import DateTime
from core.date import toJTime

toJTime(DateTime.now()) # Joda to Java works
toJodaDT(ZonedDateTime.now()) # Java to Joda doesn't work

```

Any suggestion?

Thanks in advance!  
Humberto

---

<div class="post-metadata">

**Author:** ![Bruce\_Osborne](https://community.openhab.org/user_avatar/community.openhab.org/bruce_osborne/32/38531_2.png) [@Bruce\_Osborne](https://community.openhab.org/u/Bruce_Osborne)\
**Post date:** [July 24, 2019, 10:20am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/2 "2019-07-24T10:20:20Z")

</div>

I believe @5iver is an expert here.

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [July 24, 2019, 11:36am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/3 "2019-07-24T11:36:19Z")

</div>

@rhumbertgz @5iver I’ll look into it, I wrote the module.

---

<div class="post-metadata">

**Author:** ![Bruce\_Osborne](https://community.openhab.org/user_avatar/community.openhab.org/bruce_osborne/32/38531_2.png) [@Bruce\_Osborne](https://community.openhab.org/u/Bruce_Osborne)\
**Post date:** [July 24, 2019, 11:47am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/4 "2019-07-24T11:47:15Z")

</div>

> [@CrazyIvan359](#):
>
> I’ll look into it, I wrote the module.

Sorry, I saw Scott commenting a lot in the Jython threads so I assumed he wrote it.

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [July 24, 2019, 11:58am UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/5 "2019-07-24T11:58:41Z")

</div>

@Bruce_Osborne He is looking after the Helper Libraries and most active on the forums, but I have been contributing to the project lately and wrote this particular module. Feel free to tag either of us for help with Jython rules, though Scott is far more knowledgeable.

---

<div class="post-metadata">

**Author:** ![Bruce\_Osborne](https://community.openhab.org/user_avatar/community.openhab.org/bruce_osborne/32/38531_2.png) [@Bruce\_Osborne](https://community.openhab.org/u/Bruce_Osborne)\
**Post date:** [July 24, 2019, 12:09pm UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/6 "2019-07-24T12:09:54Z")

</div>

Somewhere in my “plans” I may look at Jython since I have started using Python 3 at work.

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [July 24, 2019, 12:15pm UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/7 "2019-07-24T12:15:49Z")

</div>

I recommend bumping it up a few notches on your list! Python has a fairly shallow learning curve while still being a powerful language, and when comparing it to making rules in the DSL it might as well be another planet lol.

---

<div class="post-metadata">

**Author:** ![Bruce\_Osborne](https://community.openhab.org/user_avatar/community.openhab.org/bruce_osborne/32/38531_2.png) [@Bruce\_Osborne](https://community.openhab.org/u/Bruce_Osborne)\
**Post date:** [July 24, 2019, 12:32pm UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/8 "2019-07-24T12:32:09Z")

</div>

Well, busyness at work & home has restricted my hobby time.  
I have also started helping clean up the zwave device database, in appreciation for all the hard work there.

Is there any real plans for a Python 3 variant? Python 2 is officially dead early next year.

---

<div class="post-metadata">

**Author:** ![CrazyIvan359](https://community.openhab.org/user_avatar/community.openhab.org/crazyivan359/32/83351_2.png) [@CrazyIvan359](https://community.openhab.org/u/CrazyIvan359)\
**Post date:** [July 24, 2019, 2:33pm UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/9 "2019-07-24T14:33:18Z")

</div>

@rhumbertgz and I have tracked down the issue!

Anyone needing an instant fix for this, please update line 218 of `lib/python/core/date.py` to:

```python
        format_date(value_zoneddatetime),

```

---

<div class="post-metadata">

**Author:** ![rlkoshak](https://community.openhab.org/user_avatar/community.openhab.org/rlkoshak/32/75251_2.png) [@rlkoshak](https://community.openhab.org/u/rlkoshak)\
**Post date:** [July 24, 2019, 2:37pm UTC](https://community.openhab.org/t/error-during-conversion-from-zoneddatetime-to-joda-datetime/78586/10 "2019-07-24T14:37:54Z")

</div>

> [@Bruce\_Osborne](#):
>
> Is there any real plans for a Python 3 variant? Python 2 is officially dead early next year.

We can’t move to Python 3 until we can move OH itself off of Java 8 and gain access to Graal VM (or the Jython folks decide to actually put in some effort to build and release a Python 3 variant, OH is wholly dependent on up stream libraries to provide support for stuff like this).

As far as Rules are concerned, the difference between Python 2.7 and 3 are almost non-existent. So waiting for Python 3 support isn’t really doing anything for you. The Rules will look the same either way.

Just because the Python folks will stop supporting 2.7 next year doesn’t mean that all of a sudden all Python 2 programs in the world will stop working. It just means there will be no more changes to the language, either to add new feature or to fix bugs.

Even if OH takes a long time to get support for Python 3 you are not running any major risks by adopting Jython’s 2.7 now.

- You will have limited to no changes needed to your code to move to Python 3.
- In the Rules development context, there is little or nothing that Python 3 offers that you will miss having to build your Rules.
- Python 2.7 programs will continue to work for many years to come, they won’t automatically stop working when the foundation ends support.

Definitely make the move when you have the time but don’t let the fact that Jython only supports 2.7 keep you from making the move when you are ready.

When you are ready, see

- [Helper Libraries for openHAB Scripted Automation — openHAB Helper Libraries documentation](https://openhab-scripters.github.io/openhab-helper-libraries/index.html)
- [rhumbertgz](https://community.openhab.org/u/rhumbertgz)’s Automation # Postings. He is presenting Rules in both Rules DSL and JSR223 equivalents which will make for good examples
- [Journey to JSR223 Python 1 of 9](https://community.openhab.org/t/journey-to-jsr223-python-1-of/78556) which is showing my original production Rules DSL Rules and their conversion to Jython (work in progress)
- I’m going back to the Design Pattern postings and adding Jython equivalents for each so look there as well. This is also a work in progress.

These should give you the docs and enough examples to get started.
