Message10964

Author tmeagher
Recipients tmeagher
Date 2016-10-07.07:58:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1475827132.24.0.945617974927.issue2524@psf.upfronthosting.co.za>
In-reply-to
Content
Similar to issue 2504, but believe this is different enough to warrant a different bug report.

The datetime.py 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 datetime.py 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
            #calendar.setTimeInMillis(epoch_ms)
                
            #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?
            cal.setTimeInMillis(0);

            #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
            else:
                return Time(calendar.getTimeInMillis())
History
Date User Action Args
2016-10-07 07:58:52tmeaghersetrecipients: + tmeagher
2016-10-07 07:58:52tmeaghersetmessageid: <1475827132.24.0.945617974927.issue2524@psf.upfronthosting.co.za>
2016-10-07 07:58:52tmeagherlinkissue2524 messages
2016-10-07 07:58:50tmeaghercreate