harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r964786 - in /harmony/enhanced/java/trunk/classlib/modules/luni/src: main/java/java/util/Date.java test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Date Fri, 16 Jul 2010 12:38:46 GMT
Author: tellison
Date: Fri Jul 16 12:38:46 2010
New Revision: 964786

URL: http://svn.apache.org/viewvc?rev=964786&view=rev
Log:
Fix to date toString to use the short display name in the correct daylight zone, and fix a
test that makes assumptions about the name.
Use a string builder to collect the string.
Tidy-up some of the compiler directives.

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

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/Date.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/Date.java?rev=964786&r1=964785&r2=964786&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/Date.java (original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/util/Date.java Fri
Jul 16 12:38:46 2010
@@ -45,12 +45,13 @@ public class Date implements Serializabl
 
     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$
+    @SuppressWarnings("nls")
+    private static String[] dayOfWeekNames = { "Sun", "Mon", "Tue", "Wed",
+            "Thu", "Fri", "Sat" };
+
+    @SuppressWarnings("nls")
+    private static String[] monthNames = { "Jan", "Feb", "Mar", "Apr", "May",
+            "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
 
     /**
      * Initializes this {@code Date} instance to the current date and time.
@@ -708,10 +709,28 @@ public class Date implements Serializabl
     @Override
     public String toString() {
         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$
+        TimeZone zone = cal.getTimeZone();
+        String zoneName = zone.getDisplayName(zone.inDaylightTime(this),
+                TimeZone.SHORT, Locale.getDefault());
+
+        StringBuilder sb = new StringBuilder(34);
+        sb.append(dayOfWeekNames[cal.get(Calendar.DAY_OF_WEEK) - 1]);
+        sb.append(' ');
+        sb.append(monthNames[cal.get(Calendar.MONTH)]);
+        sb.append(' ');
+        sb.append(toTwoDigits(cal.get(Calendar.DAY_OF_MONTH)));
+        sb.append(' ');
+        sb.append(toTwoDigits(cal.get(Calendar.HOUR_OF_DAY)));
+        sb.append(':');
+        sb.append(toTwoDigits(cal.get(Calendar.MINUTE)));
+        sb.append(':');
+        sb.append(toTwoDigits(cal.get(Calendar.SECOND)));
+        sb.append(' ');
+        sb.append(zoneName);
+        sb.append(' ');
+        sb.append(cal.get(Calendar.YEAR));
+
+        return sb.toString();
     }
 
     private String toTwoDigits(int digit) {

Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java?rev=964786&r1=964785&r2=964786&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/util/DateTest.java
Fri Jul 16 12:38:46 2010
@@ -471,7 +471,7 @@ public class DateTest extends junit.fram
         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")
+                .startsWith("Wed Aug 27 00:00:00")
                 && d2.toString().endsWith("2008"));
 	}
 



Mime
View raw message