You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Tim Ellison (JIRA)" <ji...@apache.org> on 2006/08/17 20:31:15 UTC

[jira] Resolved: (HARMONY-923) Incorrect dates in java.util.Calendar() when year is very large

     [ http://issues.apache.org/jira/browse/HARMONY-923?page=all ]

Tim Ellison resolved HARMONY-923.
---------------------------------

    Resolution: Fixed

Thanks Anton.

Patch applied to LUNI modulke at repo revision r432324.

Please check it was applied as expected.


> Incorrect dates in java.util.Calendar() when year is very large
> ---------------------------------------------------------------
>
>                 Key: HARMONY-923
>                 URL: http://issues.apache.org/jira/browse/HARMONY-923
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: Windows XP professional
>            Reporter: Anton Luht
>         Assigned To: Tim Ellison
>            Priority: Minor
>         Attachments: patch.txt
>
>
> VM + classlib revision 423073
> Problem: with large values of year (aroung Integer.MIN_VALUE and Integer.MAX_VALUE) dates returned by Calendar diff from RI. The following test case shows it:
> import java.util.*;
> public class Test  { 
>     public static void main (String[] args) {   
>           Calendar cal = Calendar.getInstance();
>           int year = Integer.MIN_VALUE + 71;
>           cal.setTimeZone(TimeZone.getTimeZone("GMT"));
>           cal.set(Calendar.YEAR, year + 1900);
>           cal.set(Calendar.MONTH, Calendar.JANUARY);
>           cal.set(Calendar.DATE, 1);
>           cal.set(Calendar.HOUR_OF_DAY, 0);
>           cal.set(Calendar.MINUTE, 0);
>           cal.set(Calendar.SECOND, 0);
>           cal.set(Calendar.MILLISECOND, 0);
>           System.out.println(cal.getTimeInMillis());
>     }
> }
> Output in RI: 
> 6017546357372606464
> Output in Harmony:
> 61................................
> The problem is that though private method of GregorianCalendar daysFromBaseYear(int year) returns long, its argument is int and things like 'year - 1970' can cause int overflow. The solution is to cast argument to long and use it in further calculations.
> Please see the patch with JUnit test and fix for GregorianCalendar code attached

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira