harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r690853 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/util/Date.java test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Date Mon, 01 Sep 2008 05:48:07 GMT
Author: tonywu
Date: Sun Aug 31 22:48:06 2008
New Revision: 690853

URL: http://svn.apache.org/viewvc?rev=690853&view=rev
Log:
Apply patch for HARMONY-5468 [classlib][util] java.util.Date.toString outputs real time zone
name on RI, but prints GMT<+/-offset> on Harmony

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java?rev=690853&r1=690852&r2=690853&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/util/Date.java Sun Aug
31 22:48:06 2008
@@ -44,6 +44,13 @@
     private static int creationYear = new Date().getYear();
 
     private transient long milliseconds;
+    
+    private static String[] dayOfWeekNames = { "Sun", "Mon", "Tue", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+        "Wed", "Thu", "Fri", "Sat" }; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+    
+    private static String[] monthNames = { "Jan", "Feb", "Mar", //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
+        "Apr", "May", "Jun", "Jul", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+        "Aug", "Sep", "Oct", "Nov", "Dec"};  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
//$NON-NLS-5$
 
     /**
      * Initializes this Date instance to the current date and time.
@@ -698,11 +705,21 @@
      */
     @Override
     public String toString() {
-        return new SimpleDateFormat("E MMM dd HH:mm:ss z ", Locale.US) //$NON-NLS-1$
-                .format(this)
-                + new GregorianCalendar(milliseconds).get(Calendar.YEAR);
+        Calendar cal = new GregorianCalendar(milliseconds);
+        return dayOfWeekNames[cal.get(Calendar.DAY_OF_WEEK) - 1] + " " + monthNames[cal.get(Calendar.MONTH)]//$NON-NLS-1$
+                + " " + toTwoDigits(cal.get(Calendar.DAY_OF_MONTH)) + " " + toTwoDigits(cal.get(Calendar.HOUR_OF_DAY))//$NON-NLS-1$
//$NON-NLS-2$
+                + ":" + toTwoDigits(cal.get(Calendar.MINUTE)) + ":" + toTwoDigits(cal.get(Calendar.SECOND))//$NON-NLS-1$
//$NON-NLS-2$
+                + " " + cal.getTimeZone().getID() + " " + cal.get(Calendar.YEAR);//$NON-NLS-1$
//$NON-NLS-2$
     }
 
+    private String toTwoDigits(int digit) {
+        if(digit >= 10) {
+            return "" + digit;//$NON-NLS-1$
+        } else {
+            return "0" + digit;//$NON-NLS-1$
+        }
+    }
+    
     /**
      * Answers the millisecond value of the specified date and time in GMT.
      * 

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java?rev=690853&r1=690852&r2=690853&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Sun Aug 31 22:48:06 2008
@@ -449,6 +449,13 @@
 		} finally {
 			TimeZone.setDefault(tz);
 		}
+        
+        // Test for HARMONY-5468
+        TimeZone.setDefault(TimeZone.getTimeZone("MST"));
+        Date d2 = new Date(108, 7, 27);
+        assertTrue("Returned incorrect string: " + d2, d2.toString()
+                .startsWith("Wed Aug 27 00:00:00 MST")
+                && d2.toString().endsWith("2008"));
 	}
 
 	/**
@@ -461,6 +468,8 @@
 		assertTrue("Returned incorrect UTC value for epoch +1yr", Date.UTC(71,
 				0, 1, 0, 0, 0) == (long) 365 * 24 * 60 * 60 * 1000);
 	}
+	
+	static TimeZone defaultTimeZone = TimeZone.getDefault();
 
 	/**
 	 * Sets up the fixture, for example, open a network connection. This method
@@ -474,5 +483,6 @@
 	 * method is called after a test is executed.
 	 */
 	protected void tearDown() {
+		TimeZone.setDefault(defaultTimeZone);
 	}
 }



Mime
View raw message