commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1406122 - /commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
Date Tue, 06 Nov 2012 13:12:13 GMT
Author: ggregory
Date: Tue Nov  6 13:12:12 2012
New Revision: 1406122

URL: http://svn.apache.org/viewvc?rev=1406122&view=rev
Log:
Refactor some duplicate code.

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java?rev=1406122&r1=1406121&r2=1406122&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/time/FastDatePrinter.java
Tue Nov  6 13:12:12 2012
@@ -394,19 +394,28 @@ public class FastDatePrinter implements 
      */
     @Override
     public String format(long millis) {
-        Calendar c = new GregorianCalendar(mTimeZone, mLocale);  // hard code GregorianCalendar
+        Calendar c = newCalendar();  // hard code GregorianCalendar
         c.setTimeInMillis(millis);
+        return applyRulesToString(c);
+    }
+
+    private String applyRulesToString(Calendar c) {
         return applyRules(c, new StringBuffer(mMaxLengthEstimate)).toString();
     }
 
+    private GregorianCalendar newCalendar() {
+        // hard code GregorianCalendar
+        return new GregorianCalendar(mTimeZone, mLocale);
+    }
+
     /* (non-Javadoc)
      * @see org.apache.commons.lang3.time.DatePrinter#format(java.util.Date)
      */
     @Override
     public String format(Date date) {
-        Calendar c = new GregorianCalendar(mTimeZone, mLocale);  // hard code GregorianCalendar
+        Calendar c = newCalendar();  // hard code GregorianCalendar
         c.setTime(date);
-        return applyRules(c, new StringBuffer(mMaxLengthEstimate)).toString();
+        return applyRulesToString(c);
     }
 
     /* (non-Javadoc)
@@ -430,7 +439,7 @@ public class FastDatePrinter implements 
      */
     @Override
     public StringBuffer format(Date date, StringBuffer buf) {
-        Calendar c = new GregorianCalendar(mTimeZone, mLocale);  // hard code GregorianCalendar
+        Calendar c = newCalendar();  // hard code GregorianCalendar
         c.setTime(date);
         return applyRules(c, buf);
     }



Mime
View raw message