Author tmeagher
Recipients tmeagher
Date 2016-10-07.07:58:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Similar to issue 2504, but believe this is different enough to warrant a different bug report.

The module shipped with jython (present in the latest beta as well) appears to have a bug with python<->time conversion.

Specifically, at line 1489 in it defines the tojava conversion.

This sets the long time since epoch in ms on a java.util.Calendar 
which may have been initialized with a specific timezone.

However, the reconstruction of the epoch ms is based on the hour, 
minute, second, microsecond within the datetime.time object which are relative to the timezone in the datetime.time.tzinfo if one is present.

The calculation of epoch_ms will to return what the timeInMillis would be if the time was in UTC.

If it’s in another timezone, then this won’t be a correct ms time… 

Basically, the change I would be recommending would be something like that below :

        def __tojava__(self, java_class):
            if java_class not in (Calendar, Time, Object):
                return Py.NoConversion
            calendar = _make_java_calendar(self)
            if calendar == Py.NoConversion:
                return Py.NoConversion
            #Remove epoch ms calculation....
            #epoch_ms = (self.hour * 3600 + self.minute * 60 + self.second) * 1000 + self.microsecond // 1000
            #initialize to epoch time - effectively clear out the current date from the calendar.
            #if a time is really just signalling to ignore the date component, maybe not strictly necessary?

            #now setup the calendar to have the details populated from this time.
            calendar.set(Calendar.HOUR_OF_DAY, self.hour)
            calendar.set(Calendar.MINUTE, self.minute)
            calendar.set(Calendar.SECOND, self.second)
            calendar.set(Calendar.MILLISECOND, self.microsecond // 1000)

            if java_class == Calendar:
                return calendar
                return Time(calendar.getTimeInMillis())
Date User Action Args
2016-10-07 07:58:52tmeaghersetrecipients: + tmeagher
2016-10-07 07:58:52tmeaghersetmessageid: <>
2016-10-07 07:58:52tmeagherlinkissue2524 messages
2016-10-07 07:58:50tmeaghercreate