avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ran...@apache.org
Subject cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util DateUtils.java
Date Thu, 10 Oct 2002 16:02:41 GMT
rana_b      2002/10/10 09:02:41

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver/util
                        DateUtils.java
  Log:
  resolved date format issue
  
  Revision  Changes    Path
  1.3       +19 -6     jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/DateUtils.java
  
  Index: DateUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/util/DateUtils.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- DateUtils.java	20 May 2002 10:20:18 -0000	1.2
  +++ DateUtils.java	10 Oct 2002 16:02:41 -0000	1.3
  @@ -1,3 +1,4 @@
  +//$Id$
   /*
    * Copyright (C) The Apache Software Foundation. All rights reserved.
    *
  @@ -33,11 +34,21 @@
           "Dec"
       };
   
  -    private static final DateFormat AFTER_SIX  = new SimpleDateFormat(" yyyy");
  -    private static final DateFormat BEFORE_SIX = new SimpleDateFormat("HH:mm");
  +    // as SimpleDateFormat is not thread-safe - we have to use ThreadLocal
  +    private final static ThreadLocal AFTER_SIX = new ThreadLocal() {
  +        protected Object initialValue() {
  +            return new SimpleDateFormat(" yyyy");
  +        }
  +    };
  +    private final static ThreadLocal BEFORE_SIX = new ThreadLocal() {
  +        protected Object initialValue() {
  +            return new SimpleDateFormat("HH:mm");
  +        }
  +    };
  +    
   
       /**
  -     * Get unix style date string
  +     * Get unix style date string.
        */
       public static String getUnixDate(Date date) {
           long dateTime = date.getTime();
  @@ -51,16 +62,18 @@
   
           String dateStr = String.valueOf(cal.get(Calendar.DATE));
           if (dateStr.length() == 1) {
  -            dateStr = " " + dateStr;
  +            dateStr = ' ' + dateStr;
           }
           firstPart += dateStr + ' ';
   
           long nowTime = System.currentTimeMillis();
           if ( Math.abs(nowTime - dateTime) > 183L * 24L * 60L * 60L * 1000L) {
  -            return firstPart + AFTER_SIX.format(date);
  +            DateFormat fmt = (DateFormat)AFTER_SIX.get();
  +            return firstPart + fmt.format(date);
           }
           else {
  -            return firstPart + BEFORE_SIX.format(date);
  +            DateFormat fmt = (DateFormat)BEFORE_SIX.get();
  +            return firstPart + fmt.format(date);
           }
       }
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message