SimpleDateFormat.java (format): Zero pad unless field size is 2.
authorH. Väisänen <hvaisane@joyx.joensuu.fi>
Thu, 24 Jul 2003 15:43:04 +0000 (15:43 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Thu, 24 Jul 2003 15:43:04 +0000 (15:43 +0000)
2003-07-24  H. V�is�nen  <hvaisane@joyx.joensuu.fi>

* java/text/SimpleDateFormat.java (format) [YEAR_FIELD]: Zero pad
unless field size is 2.

From-SVN: r69744

libjava/ChangeLog
libjava/java/text/SimpleDateFormat.java

index 5372dfc9509ad9b08fb4f6d9e61ce283f5b6e1ec..844dfee78fa3f51918012b5aad55c814f83138af 100644 (file)
@@ -1,3 +1,8 @@
+2003-07-24  H. Väisänen  <hvaisane@joyx.joensuu.fi>
+
+       * java/text/SimpleDateFormat.java (format) [YEAR_FIELD]: Zero pad
+       unless field size is 2.
+
 2003-07-23  Thomas Fitzsimmons  <fitzsim@redhat.com>
 
        * gnu/java/awt/peer/gtk/GtkTextComponentPeer.java
index 67523e1628d660825130144a24479c32d5a43949..b43c6cd86d440de15821f68752c80792ba1f5988 100644 (file)
@@ -430,11 +430,15 @@ public class SimpleDateFormat extends DateFormat
          buffer.append(formatData.eras[calendar.get(Calendar.ERA)]);
          break;
        case YEAR_FIELD:
-         temp = String.valueOf(calendar.get(Calendar.YEAR));
-         if (p.size < 4)
-           buffer.append(temp.substring(temp.length()-2));
+         // If we have two digits, then we truncate.  Otherwise, we
+         // use the size of the pattern, and zero pad.
+         if (p.size == 2)
+           {
+             temp = String.valueOf(calendar.get(Calendar.YEAR));
+             buffer.append(temp.substring(temp.length() - 2));
+           }
          else
-           buffer.append(temp);
+           withLeadingZeros(calendar.get(Calendar.YEAR), p.size, buffer);
          break;
        case MONTH_FIELD:
          if (p.size < 3)