Date/Calendar related fixes (?)

Mike Leddy
Tue May 11 19:17:00 GMT 1999

In order to get my app to work right I had to make a couple of patches. I'm not
if they'll turn out to be correct.

First in, java::util::GregorianCalendar::computeTime,
line 60

> time = t * 1000LL + elements(fields)[MILLISECOND];

On my platform, i586-pc-linux-gnu/Debian an 32 bit overflow results. I basically
1000 a long long constant. There must be a better way eg. using a cast in a
independant way, but I don't know my way around the code yet.

Second in, setTimeInMillis, line 249

> computeFields();

I replaced clear() with computeFields(). My app extensively uses
Date.setMinute() etc.
Reading the code its a 'chicken before the egg' situation regarding fields and
computed time. As the primary function of the calendar is to convert fields to a

millisecond time it would seem that the potential penalty of a computeFields
call in
setTimeInMillis is worth the extra logic that would be needed to detect a
time before computed fields state.

A simple program that shows uninitialized fields causing a rogue date:

import java.util.Date;
public class Test {
  static public void main(String[] args)  {
    Date d=new Date();

Hope that these two pointers result in official fixes. My app is running now :-)


Mike Leddy.

More information about the Java mailing list