Coverage Report - org.mule.util.DateUtils
 
Classes in this File Line Coverage Branch Coverage Complexity
DateUtils
0%
0/25
N/A
1
 
 1  
 /*
 2  
  * $Id: DateUtils.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.util;
 12  
 
 13  
 import org.mule.config.i18n.CoreMessages;
 14  
 
 15  
 import java.text.ParsePosition;
 16  
 import java.text.SimpleDateFormat;
 17  
 import java.util.Date;
 18  
 
 19  
 /**
 20  
  * <code>DateUtils</code> contains some useful methods dealing date/time
 21  
  * conversion, formatting etc.
 22  
  */
 23  
 // @ThreadSafe
 24  0
 public class DateUtils extends org.apache.commons.lang.time.DateUtils
 25  
 {
 26  
 
 27  
     public static String getTimeStamp(String format)
 28  
     {
 29  
         // Format the current time.
 30  0
         SimpleDateFormat formatter = new SimpleDateFormat(format);
 31  0
         Date currentTime = new Date();
 32  0
         return formatter.format(currentTime);
 33  
     }
 34  
 
 35  
     public static String formatTimeStamp(Date dateTime, String format)
 36  
     {
 37  
         // Format the current time.
 38  0
         SimpleDateFormat formatter = new SimpleDateFormat(format);
 39  0
         return formatter.format(dateTime);
 40  
     }
 41  
 
 42  
     public static String getStringFromDate(Date date, String format)
 43  
     {
 44  
         // converts from date to strin using the standard TIME_STAMP_FORMAT
 45  
         // pattern
 46  0
         SimpleDateFormat formatter = new SimpleDateFormat(format);
 47  0
         return formatter.format(date);
 48  
     }
 49  
 
 50  
     public static Date getDateFromString(String date, String format)
 51  
     {
 52  
         // The date must always be in the format of TIME_STAMP_FORMAT
 53  
         // i.e. JAN 29 2001 22:50:40 GMT
 54  0
         SimpleDateFormat formatter = new SimpleDateFormat(format);
 55  0
         ParsePosition pos = new ParsePosition(0);
 56  
 
 57  
         // Parse the string back into a Time Stamp.
 58  0
         return formatter.parse(date, pos);
 59  
     }
 60  
 
 61  
     public static String getFormattedDuration(long mills)
 62  
     {
 63  0
         long days = mills / 86400000;
 64  0
         mills = mills - (days * 86400000);
 65  0
         long hours = mills / 3600000;
 66  0
         mills = mills - (hours * 3600000);
 67  0
         long mins = mills / 60000;
 68  0
         mills = mills - (mins * 60000);
 69  0
         long secs = mills / 1000;
 70  0
         mills = mills - (secs * 1000);
 71  
 
 72  0
         StringBuffer bf = new StringBuffer(60);
 73  0
         bf.append(days).append(" ").append(CoreMessages.days().getMessage()).append(", ");
 74  0
         bf.append(hours).append(" ").append(CoreMessages.hours().getMessage()).append(", ");
 75  0
         bf.append(mins).append(" ").append(CoreMessages.minutes().getMessage()).append(", ");
 76  0
         bf.append(secs).append(".").append(mills).append(" ").append(CoreMessages.seconds().getMessage());
 77  0
         return bf.toString();
 78  
     }
 79  
 
 80  
 }