commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject cvs commit: jakarta-commons/lang/src/test/org/apache/commons/lang/time FastDateFormatTest.java
Date Mon, 05 Jul 2004 22:37:40 GMT
scolebourne    2004/07/05 15:37:40

  Modified:    lang/src/java/org/apache/commons/lang/time
                        FastDateFormat.java
               lang/src/test/org/apache/commons/lang/time
                        FastDateFormatTest.java
  Log:
  Add format(long) and format(long, StringBuffer)
  bug 29794
  
  Revision  Changes    Path
  1.20      +27 -3     jakarta-commons/lang/src/java/org/apache/commons/lang/time/FastDateFormat.java
  
  Index: FastDateFormat.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/java/org/apache/commons/lang/time/FastDateFormat.java,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- FastDateFormat.java	18 Feb 2004 22:56:42 -0000	1.19
  +++ FastDateFormat.java	5 Jul 2004 22:37:40 -0000	1.20
  @@ -761,8 +761,8 @@
       // Format methods
       //-----------------------------------------------------------------------
       /**
  -     * <p>Format either a <code>Date</code> or a
  -     * <code>Calendar</code> object.</p>
  +     * <p>Formats a <code>Date</code>, <code>Calendar</code>
or
  +     * <code>Long</code> (milliseconds) object.</p>
        * 
        * @param obj  the object to format
        * @param toAppendTo  the buffer to append to
  @@ -774,6 +774,8 @@
               return format((Date) obj, toAppendTo);
           } else if (obj instanceof Calendar) {
               return format((Calendar) obj, toAppendTo);
  +        } else if (obj instanceof Long) {
  +            return format(((Long) obj).longValue(), toAppendTo);
           } else {
               throw new IllegalArgumentException("Unknown class: " +
                   (obj == null ? "<null>" : obj.getClass().getName()));
  @@ -781,6 +783,16 @@
       }
   
       /**
  +     * <p>Formats a millisecond <code>long</code> value.</p>
  +     * 
  +     * @param millis  the millisecond value to format
  +     * @return the formatted string
  +     */
  +    public String format(long millis) {
  +        return format(new Date(millis));
  +    }
  +
  +    /**
        * <p>Formats a <code>Date</code> object.</p>
        * 
        * @param date  the date to format
  @@ -800,6 +812,18 @@
        */
       public String format(Calendar calendar) {
           return format(calendar, new StringBuffer(mMaxLengthEstimate)).toString();
  +    }
  +
  +    /**
  +     * <p>Formats a milliseond <code>long</code> value into the
  +     * supplied <code>StringBuffer</code>.</p>
  +     * 
  +     * @param millis  the millisecond value to format
  +     * @param buf  the buffer to format into
  +     * @return the specified string buffer
  +     */
  +    public StringBuffer format(long millis, StringBuffer buf) {
  +        return format(new Date(millis), buf);
       }
   
       /**
  
  
  
  1.9       +9 -1      jakarta-commons/lang/src/test/org/apache/commons/lang/time/FastDateFormatTest.java
  
  Index: FastDateFormatTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/lang/src/test/org/apache/commons/lang/time/FastDateFormatTest.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- FastDateFormatTest.java	18 Feb 2004 23:03:03 -0000	1.8
  +++ FastDateFormatTest.java	5 Jul 2004 22:37:40 -0000	1.9
  @@ -172,30 +172,38 @@
               GregorianCalendar cal2 = new GregorianCalendar(2003, 6, 10, 9, 00, 00);
               Date date1 = cal1.getTime();
               Date date2 = cal2.getTime();
  +            long millis1 = date1.getTime();
  +            long millis2 = date2.getTime();
   
               fdf = FastDateFormat.getInstance("yyyy-MM-dd'T'HH:mm:ss");
               sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
               assertEquals(sdf.format(date1), fdf.format(date1));
               assertEquals("2003-01-10T15:33:20", fdf.format(date1));
               assertEquals("2003-01-10T15:33:20", fdf.format(cal1));
  +            assertEquals("2003-01-10T15:33:20", fdf.format(millis1));
               assertEquals("2003-07-10T09:00:00", fdf.format(date2));
               assertEquals("2003-07-10T09:00:00", fdf.format(cal2));
  +            assertEquals("2003-07-10T09:00:00", fdf.format(millis2));
   
               fdf = FastDateFormat.getInstance("Z");
               assertEquals("-0500", fdf.format(date1));
               assertEquals("-0500", fdf.format(cal1));
  +            assertEquals("-0500", fdf.format(millis1));
   
               fdf = FastDateFormat.getInstance("Z");
               assertEquals("-0400", fdf.format(date2));
               assertEquals("-0400", fdf.format(cal2));
  +            assertEquals("-0400", fdf.format(millis2));
   
               fdf = FastDateFormat.getInstance("ZZ");
               assertEquals("-05:00", fdf.format(date1));
               assertEquals("-05:00", fdf.format(cal1));
  +            assertEquals("-05:00", fdf.format(millis1));
   
               fdf = FastDateFormat.getInstance("ZZ");
               assertEquals("-04:00", fdf.format(date2));
               assertEquals("-04:00", fdf.format(cal2));
  +            assertEquals("-04:00", fdf.format(millis2));
   
               String pattern = "GGGG GGG GG G yyyy yyy yy y MMMM MMM MM M" +
                   " dddd ddd dd d DDDD DDD DD D EEEE EEE EE E aaaa aaa aa a zzzz zzz zz z";
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message