Message10192

Author zyasoft
Recipients kensingtoncat, zyasoft
Date 2015-09-01.16:48:41
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1441126122.0.0.191011469897.issue2387@psf.upfronthosting.co.za>
In-reply-to
Content
Let's try this out:

>>> import datetime, java
>>> datetime.date.today()
datetime.date(2015, 9, 1)
>>> datetime.date.today().__tojava__(java.sql.Date)
2015-08-31

So there's the reported problem. Let's dig in further. Per above, Jython does this automatic conversion via __tojava__ methods on datetime.{date, datetime, time} Python classes. Here's the relevant conversion for datetime.date:

https://github.com/jythontools/jython/blob/master/Lib/datetime.py#L1073

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

This code is problematic: java.sql.Date is in UTC; but datetime.date is naive.

>>> cal = datetime._make_java_utc_calendar()
>>> cal.clear()
>>> cal.set(2015, 8, 1)
>>> cal.getTimeInMillis()/1000.
1441065600.0
>>> time.time()
1441125551.691
>>> cal.getTimeInMillis()/1000. - time.time()
-59969.53800010681

Or a delta about 16.7 hours. More than enough to cause this issue.

I'm not certain what to do here. java.sql.Date models time differently than datetime.date. Providing this conversion might be worse than useless, but it's also something we have historically done so we cannot just remove.

Interestingly, datetime.datetime does not support conversion to java.sql.Date, which can be done correctly:

>>> datetime.datetime.now().__tojava__(java.sql.Date)
Error

So this specific conversion should be supported.
History
Date User Action Args
2015-09-01 16:48:42zyasoftsetmessageid: <1441126122.0.0.191011469897.issue2387@psf.upfronthosting.co.za>
2015-09-01 16:48:42zyasoftsetrecipients: + zyasoft, kensingtoncat
2015-09-01 16:48:41zyasoftlinkissue2387 messages
2015-09-01 16:48:41zyasoftcreate