Title: returns incorrect dates in non-UTC timezones with negative offset (Jython 2.7.0)
Type: behaviour Severity: normal
Components: Core Versions: Jython 2.7
Milestone: Jython 2.7.1
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: stefan.richthofer Nosy List: stefan.richthofer, ttakamiy, zyasoft
Priority: normal Keywords:

Created on 2016-06-16.18:56:28 by ttakamiy, last changed 2017-03-28.05:24:17 by zyasoft.

File name Uploaded Description Edit Remove ttakamiy, 2016-06-16.18:56:27 ttakamiy, 2016-06-30.17:13:29
msg10864 (view) Author: Tami Takamiya (ttakamiy) Date: 2016-06-16.18:56:27
JTable displays incorrect date with Jython 2.7.0.  Attached sample code ( is supposed to display two dates ("2015-12-31" and "2016-01-01"), but it displays "2015-12-30" and "2015-12-31" instead.  The problem is not observed with Jython 2.5.3.
msg10870 (view) Author: Tami Takamiya (ttakamiy) Date: 2016-06-30.17:13:29
I did some debugging and found the problem was in method.  

In that method, a java.util.GregorianCalendar object is create for the UTC timezone and a java.sql.Date object is created based on the time stamp of the GregorianCalendar object.  The problem is that when the Date object is created, the timezone is converted from UTC to the default timezone, which is US Eastern time in my case.

Therefore, the problem can be worked around by overriding datetime._utc_timezone by the default timezone (see attached  However, I think needs to be fixed for this issue.  Thanks, Tami
msg10871 (view) Author: Tami Takamiya (ttakamiy) Date: 2016-06-30.17:16:07
Title was corrected: datetime.__tojava__ ==>
msg11180 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-05.00:00:23
Tami, I just tried to reproduce this issue, but it works well for me, and I am also not in UTC, my default is:

>>> from java.util import TimeZone
>>> TimeZone.getDefault()

The dates in your example are displayed like they should out of the box. 

What specific fix would you suggest for Should it be the same fix as you propose in #2524?
What about datetime.datetime.__tojava__? Should it be fixed there too?
msg11181 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-05.00:02:32
>Should it be the same fix as you propose in #2524?

Sorry, I overlooked that it's a different author. Anyway, does that proposed change fix this for you as well?
msg11182 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-05.00:45:35
Okay, overlooked that #2524 is about datetime.time. So ignore what I wrote regarding that (you might still want to review that fix...?)

If we change to the following:

    if _is_jython:
        def __tojava__(self, java_class):
            if java_class not in (Calendar, Date, Object):
                return Py.NoConversion
            if java_class == Calendar:
                calendar = _make_java_utc_calendar()
                calendar.set(self.year, self.month - 1,
                return calendar
                calendar = _make_java_default_calendar()
                calendar.set(self.year, self.month - 1,
                return Date(calendar.getTimeInMillis())

	def _make_java_default_calendar():
		return GregorianCalendar(0, 0, 0, 0, 0, 0)

would that fix it for you? Could you please try that?
msg11185 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-05.17:25:46
It occurred to me that probably this does not affect all non-UTC timezones, but only UTC Offset: UTC -x ones. In +x timezones the time doesn't affect the date when time is set to zero (then it's just later, but still the same day). That's probably the explanation why I can't see the issue, being in UTC Offset: UTC +1.

I will try to reproduce it by setting my system to a -x timezone...

Anyway, the proposed solution (see above) should still fix it.
msg11188 (view) Author: Stefan Richthofer (stefan.richthofer) Date: 2017-03-06.16:21:33
Fixed as of

I could confirm this issue by changing my system's timezone setting and also confirmed the fix. It really turned out that this only affected timezones with negative offset.
msg11278 (view) Author: Tami Takamiya (ttakamiy) Date: 2017-03-27.18:21:53
Sorry for not having replied to the updates you made early this month.  I needed to leave work for weeks in order to deal with a personal situation.

Today I tested the fix by manually changing the 2.7.0 code and verified that it actually resolved the issue.  Thank you, Tami
Date User Action Args
2017-03-28 05:24:17zyasoftsetstatus: pending -> closed
2017-03-27 18:21:54ttakamiysetmessages: + msg11278
2017-03-06 16:21:34stefan.richthofersetstatus: open -> pending
title: returns incorrect dates in non-UTC timezones with Jython 2.7.0 -> returns incorrect dates in non-UTC timezones with negative offset (Jython 2.7.0)
messages: + msg11188
priority: normal
assignee: stefan.richthofer
milestone: Jython 2.7.2 -> Jython 2.7.1
resolution: fixed
2017-03-05 17:25:46stefan.richthofersetmessages: + msg11185
2017-03-05 00:45:36stefan.richthofersetmessages: + msg11182
2017-03-05 00:02:32stefan.richthofersetmessages: + msg11181
2017-03-05 00:00:24stefan.richthofersetnosy: + stefan.richthofer
messages: + msg11180
2016-09-30 16:20:40zyasoftsetassignee: zyasoft -> (no value)
milestone: Jython 2.7.2
2016-09-14 16:17:29zyasoftsetassignee: zyasoft
nosy: + zyasoft
2016-06-30 17:16:07ttakamiysetmessages: + msg10871
title: datetime.__tojava__ returns incorrect dates in non-UTC timezones with Jython 2.7.0 -> returns incorrect dates in non-UTC timezones with Jython 2.7.0
2016-06-30 17:13:30ttakamiysetfiles: +
messages: + msg10870
title: JTable displays incorrect dates with Jython 2.7.0 -> datetime.__tojava__ returns incorrect dates in non-UTC timezones with Jython 2.7.0
2016-06-16 18:56:28ttakamiycreate