harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anton Luht (JIRA)" <j...@apache.org>
Subject [jira] Commented: (HARMONY-923) Incorrect dates in java.util.Calendar() when year is very large
Date Mon, 21 Aug 2006 11:18:16 GMT
    [ http://issues.apache.org/jira/browse/HARMONY-923?page=comments#action_12429391 ] 
            
Anton Luht commented on HARMONY-923:
------------------------------------

verified on 

java version "1.5.0"
pre-alpha : not complete or compatible
svn = r433212, (Aug 21 2006), Windows/ia32/msvc 1310, debug build
http://incubator.apache.org/harmony

> 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

        

Mime
View raw message