From bb477ffa482e7d6b2db93be4557a62a5fb9d185f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=2E=20V=C3=A4is=C3=A4nen?= Date: Thu, 24 Jul 2003 15:43:04 +0000 Subject: SimpleDateFormat.java (format): Zero pad unless field size is 2. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2003-07-24 H. V�is�nen * java/text/SimpleDateFormat.java (format) [YEAR_FIELD]: Zero pad unless field size is 2. From-SVN: r69744 --- libjava/java/text/SimpleDateFormat.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'libjava/java/text') diff --git a/libjava/java/text/SimpleDateFormat.java b/libjava/java/text/SimpleDateFormat.java index 67523e1..b43c6cd 100644 --- a/libjava/java/text/SimpleDateFormat.java +++ b/libjava/java/text/SimpleDateFormat.java @@ -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) -- cgit v1.1